FrontPage

This is a Ruby 1.8/1.9 binding of Tx, a library for a compact trie data structure.

For details of Tx, see: Tx: Succinct Trie Data structure

How to install

$ sudo gem install tx

Or

$ wget http://gimite.net/archive/tx-ruby-0.0.5.tar.gz
$ tar xvzf tx-ruby-*.tar.gz
$ cd tx-ruby
$ sudo ruby setup.rb
  • If your Ruby is 1.8.x mswin32, you don't need compilers (binary is bundled).
  • Tx library is bundled, so you don't need to install it separately.

Document

 require "rubygems"
 require "tx"
 
 # Builds an index and saves it to a file.
 builder = Tx::Builder.new
 builder.add_all(["foo", "ho", "hog", "hoga", "hoge", "hogeshi"])
 builder.build("test.index")
 
 # Loads an index.
 index = Tx::Index.open("test.index")
 
 # Simple lookup.
 index.include?("hoge")           #=> true
 index.include?("bar")            #=> false
 
 # Searches prefixes of the word.
 index.longest_prefix("hogeeee") #=> 4 (which means "hoge" is in the index)
 index.search_prefixes("hoge")   #=> ["ho", "hog", "hoge"]
 
 # Searches words which begin with the string.
 index.search_expansions("hog")  #=> ["hog", "hoga", "hoge", "hogeshi"]
 
 # Finds all occurences of words in the index.
 index.scan("hogefugafoo")       #=> [["hoge", 0], ["foo", 8]]
 
 # Replaces words in the index.
 index.gsub("hogefugafoo"){ |s, i| s.upcase }
                                 #=> "HOGEfugaFOO"
  • Usage example of Hash-like index:
 require "tx"
 
 # Builds an index and saves it to a file.
 builder = Tx::MapBuilder.new
 builder.add("ho", "foo")
 builder.add("hoge", "bar")
 builder.build("test")
 
 # Loads an index.
 map = Tx::Map.open("test")
 
 # Simple lookup.
 map.has_key?("hoge")                     #=> true
 map["hoge"]                             #=> "bar"
 map["fuga"]                             #=> nil
 
 # Searches prefixes/expansion of the word in keys.
 map.key_index.longest_prefix("hogeeee") #=> 4 (which means the index has a key "hoge")
 map.key_index.search_prefixes("hoge")   #=> ["ho", "hoge"]
 map.key_index.search_expansions("ho")   #=> ["ho", "hoge"]
 
 # Finds all occurences of keys in the index.
 index.scan("hogehoga")                  #=> [["hoge", 0, "bar"], ["ho", 4, "foo"]]

License

New BSD License.

History

  • 0.0.5
    • Based on Tx 0.13.
    • Fixed compilation error in recent Ubuntu (thanks to ROBA).
    • Supported Ruby 1.9.x.
    • Added Set/Hash-like methods to Tx::Index and Tx::Map.
  • 0.0.4
    • Based on Tx 0.09.
    • Added Hash-like interface: Tx::Map and Tx::MapBuilder.
  • 0.0.3
    • Added Tx::Index#scan and Tx::Index#gsub.
    • Fixed a bug that Ruby crashes when opening non-existing index file.
  • 0.0.2
    • (Incompatible with 0.0.1) Result of Tx::Index#search_expansions now includes str itself if it's in the index.
    • Fixed performance problem.
  • 0.0.1
    • First version. Based on Tx 0.0.4.

How to hack

Source code is on Github.

Some hints:

  • This library is implemented with SWIG (So I guess it's easy to generate binding for other script languages). You need to install SWIG to regenerate ext/tx_swig_wrap.cxx if you edit ext/tx_swig.{h,i}.
  • To generate ext/tx_swig_wrap.cxx which works on Ruby 1.9, you need to apply ext/swig.patch to SWIG.
  • To build lib/i386-msvcrt/tx_core.so, follow instruction here (Japanese).

Comments

  • 1 -- 1? 2014-04-03 (Thu) 13:08:42
  • 1 -- 1? 2014-04-03 (Thu) 13:08:46
  • 1 -- -1'? 2014-04-03 (Thu) 13:08:47
    • 1' -- 1? 2014-04-03 (Thu) 13:08:49
  • 1 -- 1? 2014-04-03 (Thu) 13:08:51
  • 1 -- 1? 2014-04-29 (Tue) 00:02:38
  • 1 -- 1? 2014-04-29 (Tue) 00:02:40
  • 1 -- -1'? 2014-04-29 (Tue) 00:02:41
    • 1' -- 1? 2014-04-29 (Tue) 00:02:42
  • 1 -- 1? 2014-04-29 (Tue) 00:02:43
  • 1 -- 1? 2014-06-30 (Mon) 13:38:18
  • 1 -- 1? 2014-06-30 (Mon) 13:38:45
  • 1 -- -1'? 2014-06-30 (Mon) 13:38:50
    • 1' -- 1? 2014-06-30 (Mon) 13:39:13
  • 1 -- 1? 2014-06-30 (Mon) 13:39:15
  • 1 -- 1? 2014-07-04 (Fri) 08:26:22
  • 1 -- -1'? 2014-07-04 (Fri) 08:26:24
    • 1' -- 1? 2014-07-04 (Fri) 08:26:28
  • 1 -- 1? 2014-07-04 (Fri) 08:26:32
  • 1 -- 1? 2014-08-07 (Thu) 15:10:33
  • 1 -- 1? 2014-08-07 (Thu) 15:10:37
  • 1 -- -1'? 2014-08-07 (Thu) 15:10:38
    • 1' -- 1? 2014-08-07 (Thu) 15:10:39
  • 1 -- 1? 2014-08-07 (Thu) 15:10:40
  • 1 -- 1? 2014-08-11 (Mon) 19:28:24
  • 1 -- 1? 2014-08-11 (Mon) 19:28:26
  • 1 -- -1'? 2014-08-11 (Mon) 19:28:27
    • 1' -- 1? 2014-08-11 (Mon) 19:28:28
  • 1 -- 1? 2014-08-11 (Mon) 19:28:29
  • 1 -- 1? 2014-10-06 (Mon) 15:53:52
  • 1 -- -1'? 2014-10-06 (Mon) 15:53:53
    • 1' -- 1? 2014-10-06 (Mon) 15:53:54
  • 1 -- 1? 2014-10-06 (Mon) 15:53:56
  • 1 -- 1? 2014-10-15 (Wed) 10:29:51
  • 1 -- 1? 2014-10-15 (Wed) 10:29:56
  • 1 -- -1'? 2014-10-15 (Wed) 10:29:59
    • 1' -- 1? 2014-10-15 (Wed) 10:29:59
  • 1 -- 1? 2014-10-15 (Wed) 10:30:01

  • 1 -- 1? 2014-10-15 (Wed) 10:29:53
  • 1 -- 1? 2014-08-11 (Mon) 19:28:26
  • 1 -- 1? 2014-08-07 (Thu) 15:10:34
  • 1 -- 1? 2014-07-04 (Fri) 08:26:05
  • 1 -- 1? 2014-06-30 (Mon) 13:38:44
  • 1 -- 1? 2014-04-29 (Tue) 00:02:39
  • 1 -- 1? 2014-04-03 (Thu) 13:08:45

Front page   Edit Unfreeze Diff Backup Upload Copy Rename Reload   New List of pages Search Recent changes   Help   RSS of recent changes
Last-modified: 2014-10-15 (Wed) 10:30:01 (16d)