class OrderedHash
Constants
- ONE
Attributes
hash[R]
times_queried[R]
Public Class Methods
new()
click to toggle source
# File lib/logstash/filters/ip2location.rb, line 70 def initialize @times_queried = Hash.new(0) # ip -> times queried @hash = {} # number of hits -> array of ips end
Public Instance Methods
add(key)
click to toggle source
# File lib/logstash/filters/ip2location.rb, line 75 def add(key) hash[ONE] ||= [] hash[ONE] << key times_queried[key] = ONE end
delete_least_used()
click to toggle source
# File lib/logstash/filters/ip2location.rb, line 97 def delete_least_used first_pile_with_someting.shift.tap { |key| times_queried.delete(key) } end
first_pile_with_someting()
click to toggle source
# File lib/logstash/filters/ip2location.rb, line 101 def first_pile_with_someting hash[hash.keys.min] end
increment(key)
click to toggle source
# File lib/logstash/filters/ip2location.rb, line 91 def increment(key) add(key) unless times_queried.has_key?(key) reorder(key) times_queried[key] += 1 end
reorder(key)
click to toggle source
# File lib/logstash/filters/ip2location.rb, line 81 def reorder(key) number_of_queries = times_queried[key] hash[number_of_queries].delete(key) hash.delete(number_of_queries) if hash[number_of_queries].empty? hash[number_of_queries + 1] ||= [] hash[number_of_queries + 1] << key end