Class: OklahomaMixer::Cursor

Inherits:
Object
  • Object
show all
Defined in:
lib/oklahoma_mixer/cursor.rb,
lib/oklahoma_mixer/cursor/c.rb

Overview

:nodoc:

Defined Under Namespace

Modules: C

Instance Method Summary collapse

Constructor Details

#initialize(b_tree_pointer, start = nil, reverse = false) ⇒ Cursor


6
7
8
9
10
11
12
13
14
# File 'lib/oklahoma_mixer/cursor.rb', line 6

def initialize(b_tree_pointer, start = nil, reverse = false)
  @pointer = C.new(b_tree_pointer)
  @reverse = reverse
  if start
    C.jump(@pointer, *start)
  else
    C.send(@reverse ? :last : :first, @pointer)
  end
end

Instance Method Details

#deleteObject


38
39
40
# File 'lib/oklahoma_mixer/cursor.rb', line 38

def delete
  C.out(@pointer)
end

#freeObject


42
43
44
# File 'lib/oklahoma_mixer/cursor.rb', line 42

def free
  C.del(@pointer)
end

#keyObject


16
17
18
# File 'lib/oklahoma_mixer/cursor.rb', line 16

def key
  C.read_from_func(:key, @pointer)
end

#key_and_valueObject


24
25
26
27
28
29
30
31
32
# File 'lib/oklahoma_mixer/cursor.rb', line 24

def key_and_value
  Utilities.temp_xstr do |key|
    Utilities.temp_xstr do |value|
      if C.rec(@pointer, key.pointer, value.pointer)
        [key.to_s, value.to_s]
      end
    end
  end
end

#nextObject


34
35
36
# File 'lib/oklahoma_mixer/cursor.rb', line 34

def next
  C.send(@reverse ? :prev : :next, @pointer)
end

#valueObject


20
21
22
# File 'lib/oklahoma_mixer/cursor.rb', line 20

def value
  C.read_from_func(:val, @pointer)
end