Class: StrokeDB::Skiplist::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/strokedb/data_structures/skiplist.rb

Direct Known Subclasses

HeadNode, TailNode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level, key, value, timestamp = nil) ⇒ Node

Returns a new instance of Node.



244
245
246
247
# File 'lib/strokedb/data_structures/skiplist.rb', line 244

def initialize(level, key, value,timestamp=nil)
	@key, @value, @timestamp = key, value, timestamp
	@forward = Array.new(level)
end

Instance Attribute Details

#_serialized_indexObject

Returns the value of attribute _serialized_index.



243
244
245
# File 'lib/strokedb/data_structures/skiplist.rb', line 243

def _serialized_index
  @_serialized_index
end

#forwardObject

Returns the value of attribute forward.



242
243
244
# File 'lib/strokedb/data_structures/skiplist.rb', line 242

def forward
  @forward
end

#keyObject

Returns the value of attribute key.



242
243
244
# File 'lib/strokedb/data_structures/skiplist.rb', line 242

def key
  @key
end

#timestampObject

Returns the value of attribute timestamp.



242
243
244
# File 'lib/strokedb/data_structures/skiplist.rb', line 242

def timestamp
  @timestamp
end

#valueObject

Returns the value of attribute value.



242
243
244
# File 'lib/strokedb/data_structures/skiplist.rb', line 242

def value
  @value
end

Instance Method Details

#<(key) ⇒ Object



256
257
258
# File 'lib/strokedb/data_structures/skiplist.rb', line 256

def <(key)
 @key < key
end

#<=(key) ⇒ Object



259
260
261
# File 'lib/strokedb/data_structures/skiplist.rb', line 259

def <=(key)
 @key <= key
end

#free(list) ⇒ Object

this is called when node is thrown out of the list note, that node.value is called immediately after node.free



250
251
252
# File 'lib/strokedb/data_structures/skiplist.rb', line 250

def free(list)
  # do nothing
end

#levelObject

do nothing



253
254
255
# File 'lib/strokedb/data_structures/skiplist.rb', line 253

def level
  @forward.size
end

#nextObject



262
263
264
# File 'lib/strokedb/data_structures/skiplist.rb', line 262

def next
  forward[0]
end

#to_sObject



265
266
267
# File 'lib/strokedb/data_structures/skiplist.rb', line 265

def to_s
  "[#{level}]#{@key}: #{@value}"
end