Class: Rod::Index::HashIndex
Overview
This implementation of index is based on the Berkeley DB Hash access method.
Defined Under Namespace
Classes: Handle
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
The class given index is associated with.
Attributes inherited from Base
Instance Method Summary collapse
-
#copy(index) ⇒ Object
Copies the index from the given
index
. -
#delete(key, value = nil) ⇒ Object
Delets given
value
for the givenkey
. -
#destroy ⇒ Object
Clears the contents of the index.
-
#each ⇒ Object
Iterates over the keys and corresponding values present in the index.
-
#each_for(key) ⇒ Object
Iterates over all values for a given
key
. -
#get_first(key) ⇒ Object
Returns the first value for a given
key
or raises keyMissing exception if it is not present. -
#initialize(path, klass, options = {}) ⇒ HashIndex
constructor
Initializes the index with
path
andclass
. -
#put(key, rod_id) ⇒ Object
Registers given
rod_id
for the givenkey
. -
#save ⇒ Object
Stores the index on disk.
Methods inherited from Base
#[], create, #key_persisted, #to_s
Methods included from Utils
#remove_file, #remove_files, #remove_files_but, #report_progress
Constructor Details
#initialize(path, klass, options = {}) ⇒ HashIndex
Initializes the index with path
and class
. Options are not (yet) used.
18 19 20 21 22 |
# File 'lib/rod/index/hash_index.rb', line 18 def initialize(path,klass,={}) @path = path + ".db" @klass = klass @options = end |
Instance Attribute Details
#klass ⇒ Object (readonly)
The class given index is associated with.
14 15 16 |
# File 'lib/rod/index/hash_index.rb', line 14 def klass @klass end |
Instance Method Details
#copy(index) ⇒ Object
Copies the index from the given index
. The index have to cleared before being copied.
52 53 54 55 |
# File 'lib/rod/index/hash_index.rb', line 52 def copy(index) self.destroy super(index) end |
#delete(key, value = nil) ⇒ Object
Delets given value
for the given key
. If the value
is nil, then the key is removed with all the values.
60 61 62 |
# File 'lib/rod/index/hash_index.rb', line 60 def delete(key,value=nil) _delete(key,value) end |
#destroy ⇒ Object
Clears the contents of the index.
30 31 32 33 |
# File 'lib/rod/index/hash_index.rb', line 30 def destroy close if opened? remove_file(@path) end |
#each ⇒ Object
Iterates over the keys and corresponding values present in the index.
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rod/index/hash_index.rb', line 37 def each if block_given? open(@path, :create => true) unless opened? _each_key do |key| next if key.empty? key = Marshal.load(key) yield key,self[key] end else enum_for(:each) end end |
#each_for(key) ⇒ Object
Iterates over all values for a given key
. Raises KeyMissing if the key is not present.
71 72 73 74 75 |
# File 'lib/rod/index/hash_index.rb', line 71 def each_for(key) _get(key) do |value| yield value end end |
#get_first(key) ⇒ Object
Returns the first value for a given key
or raises keyMissing exception if it is not present.
79 80 81 |
# File 'lib/rod/index/hash_index.rb', line 79 def get_first(key) _get_first(key) end |
#put(key, rod_id) ⇒ Object
Registers given rod_id
for the given key
.
65 66 67 |
# File 'lib/rod/index/hash_index.rb', line 65 def put(key,rod_id) _put(key,rod_id) end |
#save ⇒ Object
Stores the index on disk.
25 26 27 |
# File 'lib/rod/index/hash_index.rb', line 25 def save close end |