Class: Akane::Recorder::RoundrobinFlags

Inherits:
Object
  • Object
show all
Defined in:
lib/akane/recorder.rb

Instance Method Summary collapse

Constructor Details

#initialize(size) ⇒ RoundrobinFlags

Returns a new instance of RoundrobinFlags.



115
116
117
118
# File 'lib/akane/recorder.rb', line 115

def initialize(size)
  @hash = {}
  @limit_size = size
end

Instance Method Details

#[](k) ⇒ Object



120
121
122
# File 'lib/akane/recorder.rb', line 120

def [](k)
  @hash[k]
end

#flag!(k) ⇒ Object



124
125
126
127
128
129
130
131
132
# File 'lib/akane/recorder.rb', line 124

def flag!(k)
  @hash[k] = true
  if @limit_size < @hash.size
    @hash.keys.first(@hash.size-@limit_size).each do |overflowed_key|
      @hash.delete overflowed_key
    end
  end
  nil
end

#flagsObject



138
139
140
# File 'lib/akane/recorder.rb', line 138

def flags
  @hash.keys
end

#unflag!(k) ⇒ Object



134
135
136
# File 'lib/akane/recorder.rb', line 134

def unflag!(k)
  @hash.delete k
end