Class: Sparkey::HashReader

Inherits:
Object
  • Object
show all
Includes:
Errors
Defined in:
lib/sparkey/hash_reader.rb

Instance Method Summary collapse

Methods included from Errors

#handle_status

Instance Method Details

#closeObject


14
15
16
17
18
# File 'lib/sparkey/hash_reader.rb', line 14

def close
  ptr = FFI::MemoryPointer.new(:pointer).write_pointer(@hash_reader_ptr)

  Sparkey::Native.hash_close(ptr)
end

#collision_countObject


35
36
37
# File 'lib/sparkey/hash_reader.rb', line 35

def collision_count
  Sparkey::Native.hash_numcollisions(@hash_reader_ptr)
end

#entry_countObject


31
32
33
# File 'lib/sparkey/hash_reader.rb', line 31

def entry_count
  Sparkey::Native.hash_numentries(@hash_reader_ptr)
end

#log_readerObject


39
40
41
42
43
44
45
46
# File 'lib/sparkey/hash_reader.rb', line 39

def log_reader
  reader_ptr = Sparkey::Native.hash_getreader(@hash_reader_ptr)

  log_reader = Sparkey::LogReader.new
  log_reader.ptr = reader_ptr

  log_reader
end

#open(filename) ⇒ Object


4
5
6
7
8
9
10
11
12
# File 'lib/sparkey/hash_reader.rb', line 4

def open(filename)
  hash_filename = "#{filename}.spi"
  log_filename = "#{filename}.spl"
  ptr = FFI::MemoryPointer.new(:pointer)

  handle_status Sparkey::Native.hash_open(ptr, hash_filename, log_filename)

  @hash_reader_ptr = ptr.read_pointer
end

#ptrObject


48
49
50
# File 'lib/sparkey/hash_reader.rb', line 48

def ptr
  @hash_reader_ptr
end

#seek(key) ⇒ Object


20
21
22
23
24
25
26
27
28
29
# File 'lib/sparkey/hash_reader.rb', line 20

def seek(key)
  iterator = Sparkey::HashIterator.new(self)

  key_length = key.bytesize
  key_ptr = FFI::MemoryPointer.new(:uint8, key_length).write_bytes(key)

  handle_status Sparkey::Native.hash_get(@hash_reader_ptr, key_ptr, key_length, iterator.ptr)

  iterator
end