Class Tx::Map
In: tx.rb
Parent: Object

A class to access an index with key/value pairs.

Methods

[]   each   each_key   each_pair   each_value   has_key   keys   new   open   scan   size   values  

Included Modules

Enumerable

External Aliases

has_key -> has_key?

Attributes

encoding  [R]  Encoding object specified in new. nil in Ruby 1.8.
key_index  [R]  Tx::Index which contains keys.
value_index  [R]  Tx::Index which contains values.

Public Class methods

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.

Public Instance methods

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.)

Same as Hash#each.

Same as Hash#each_key.

Same as Hash#each_pair.

Same as Hash#each_value.

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.)

Returns all keys as an Array.

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"]

Returns number of keys.

Returns all values as an Array.

[Validate]