class APNS::InfiniteArray
Public Class Methods
new(buffer_size:)
click to toggle source
# File lib/apns/infinite_array.rb, line 13 def initialize(buffer_size:) @buffer_size = buffer_size @buf = [] end
Public Instance Methods
buffer_index_from(index:)
click to toggle source
# File lib/apns/infinite_array.rb, line 55 def buffer_index_from(index:) return if index > @buf.last.index buf_index = index - @buf[0].index return if buf_index < 0 buf_index end
clear()
click to toggle source
# File lib/apns/infinite_array.rb, line 50 def clear @buf = [] @hash = {} end
delete_where_index_less_than(index)
click to toggle source
# File lib/apns/infinite_array.rb, line 44 def delete_where_index_less_than index while @buf[0].index < index pop_front end end
item_at(index)
click to toggle source
# File lib/apns/infinite_array.rb, line 28 def item_at index buf_index = buffer_index_from(index: index) return unless buf_index @buf[buf_index].item end
items_from(index)
click to toggle source
# File lib/apns/infinite_array.rb, line 34 def items_from index buf_index = buffer_index_from(index: index) return [] unless buf_index @buf[buf_index..-1].map(&:item) end
pop_front()
click to toggle source
# File lib/apns/infinite_array.rb, line 40 def pop_front @buf = @buf[1..-1] end
push(item)
click to toggle source
# File lib/apns/infinite_array.rb, line 18 def push item @buf << Element.new(index: size, item: item) pop_front if @buf.size > @buffer_size end
size()
click to toggle source
# File lib/apns/infinite_array.rb, line 23 def size return 0 if @buf[0].nil? @buf.last.index + 1 end