Class | Tx::Map |
In: |
tx.rb
|
Parent: | Object |
A class to access an index with key/value pairs.
has_key | -> | has_key? |
Loads an index from a file named file_prefix.key, file_prefix.val and file_prefix.map. The index file can be generated with Tx::MapBuilder.
e.g. map = Tx::Map.new("test")
Ruby 1.9 only: You can specify Encoding object as second parameter. It is used as encoding of result of lookup, etc. Default is Encoding.default_internal (if it‘s nil, Encoding::UTF_8). Note that offsets (pos, len) returned by and given to Tx::Map is in byte unit, not character unit, even if encoding is specified.
Returns the value which corresponds to key. Returns nil if key is not in the index.
e.g. map["hoge"] #=> "bar"
If pos and len are specified, searches key[pos, len] instead of whole key. (Negative pos is not supported.)
Returns true if key is in the index.
e.g. map.has_key("hoge") #=> true if the index has a key "hoge"
If pos and len are specified, searches key[pos, len] instead of whole key. (Negative pos is not supported.)
Finds all occurences of keys in the index from str, and returns Array of [matched key, its position, value which corresponds to the key].
e.g. index.scan("hogefugabar") #=> [["hoge", 0, "foo"], ["bar", 8, "foooo"]]
If block is given, call it for each key, position and value.
e.g.
index.scan("hogefugabar"){ |k, i, v| p [k, i, v] } #=> ["hoge", 0, "foo"] ["bar", 8, "foooo"]