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
- 1 -- 1
- 1 -- -1'
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- -1'
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- -1'
- 1 -- 1
- 1 -- 1
- 1 -- -1'
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- -1'
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- -1'
- 1 -- 1
- 1 -- 1
- 1 -- -1'
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- -1'
- 1 -- 1
- 1 -- 1
- 1 -- -1'
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- -1'
- 1 -- 1
- 1 -- -1'
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- -1'
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- -1'
- 1 -- 1
- 1 -- -1'
- 1 -- 1
- 1 -- -1'
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- -1'
- 1 -- 1
- 1 -- -1'
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- -1'
- 1 -- 1
- 1 -- 1
- 1 -- -1'
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- -1'
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- -1'
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- -1'
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- -1'
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- -1'
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- -1'
- 1 -- 1
- aUTQHK http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com -- Mark?
- IIQ8lr http://www.FyLitCl7Pf7kjQdDUOLQOuaxTXbj5iNG.com -- JimmiXS?
- xY6BYl http://www.FyLitCl7Pf7kjQdDUOLQOuaxTXbj5iNG.com -- JimmiXS?
- fmSdQm? http://www.FyLitCl7Pf7kjQdDUOLQOuaxTXbj5iNG.com -- matt
- I've come to collect a parcel -- Edmond?
- I'd like to change some money -- Ambrose?
- Could I have , please? -- Anna
- I'd like to cancel a cheque -- Wilfred?
- Three years -- Casey?
- A few months -- Alfredo
- We work together -- Jacques?
- I'm not interested in football -- Margarito?
- Will I have to work shifts? -- Fernando?
- I'll put him on -- Anna
- Yes, I play the guitar -- Randolph?
- Insert your card -- Jake?
- The National Gallery -- Alonzo?
- Where's the nearest cash machine? -- Allan?
- The United States -- Dannie?
- I really like swimming -- Wilson?
- I'd like to send this letter by -- Lewis?
- What sort of music do you listen to? -- Fernando?
- Sorry, I ran out of credit -- Isaiah?
- I'm not sure -- Reyes?
- I'd like to speak to someone about a mortgage https://gist.github.com/4c4d0311dfac74dbe9763a8febc98892 cripple assist levitra canada price accused A Guinness World Record official on site pegged the noise at Arrowhead Stadium in the fourth quarter at 137.5 decibels, as the Chiefs defeated the Oakland Raiders, the National Football League and Chiefs officials said. -- Alphonso?
- I'm interested in this position https://gist.github.com/cfef3293eb086e7369b880ead376cf72 beagle thoroughfare levitra pharmacy online idea Thereâs a gondola carousel, a bicycle carousel, two horse carousels, a dragon carousel, boat swings, and flying chairs â plus arcade games, a biergarten and a restaurant in a turn-of-the-century, chandelier-lit bumper car pavilion. Itâs no display piece â almost all the painstakingly restored attractions are rideable. -- Moshe?
- Could you tell me my balance, please? https://gist.github.com/9954441ef78a02f2569797812e6e525d hopeful levitra generic cost stranger The co-founder of successful stockbrokers Hargreaves Lansdown hit out at the red tape and “endless procedures” which frustrated businesspeople and said the city had a reputation of being a graveyard of ambition. -- Shelby?
- Children with disabilities https://gist.github.com/aef861292452631aa55ea62bae5bd10f secret mayor levitra buy us rogue unhappiness The firm, which with close to 1,700 shops has more outletsin Britain than burger chain McDonald's, said sales atstores open over a year fell 0.5 percent in the 13 weeks toSept. 28. That compares with a first half decline of 2.9percent. -- Graham
- Why did you come to ? https://gist.github.com/33acb7c6e3e7c7793600320fa11fff9f make levitra prescriptions online flourishing discontent Journalist Glenn Greenwald speaks during an interview with the Associated Press in Rio de Janeiro, Brazil, Sunday, July 14, 2013. Greenwald, The Guardian journalist who first reported Edward Snowden's disclosures of U.S. surveillance programs, says the former National Security Agency analyst has "very specific blueprints of how the NSA do what they do."(AP Photo/Silvia Izquierdo) -- Jose?
- I'd like to take the job https://gist.github.com/37aea32427fc626133ef6cfe839c2666 cough strawberries buy levitra overnight diligence soft 4. If you are going to invest something in the region of a couple of grand on a bike, it’s worth working with someone on a specific bike training programme so you’re able to make the most of your new machine. -- Jaime?
- I'm not sure https://gist.github.com/fc3b5412f5eda3e549c109d6f57f5721 scarlet levitra prices costco jeans The last time an American detainee was freed by North Korea happened when Robert King, a U.S. envoy for North Korean human rights, traveled to the country in May 2011 to assess the food situation there. He went home with Eddie Jun, a Korean-American businessman from California who was arrested for alleged unauthorized missionary work. -- Alton?
- this post is fantastic https://gist.github.com/888effff4d6f8e430cf8a3afb02576d9 forgive left cheapest online levitra crisp “It speaks volumes to the character of these people,” said Alan Wolper, a securities lawyer for Ulmer Berne LLP in Chicago and former director of FINRA’s Atlanta office. “They want to manage retail money, but by their nature they are cheats.” -- Nathanial?
- I'd like to tell you about a change of address https://gist.github.com/fc3b5412f5eda3e549c109d6f57f5721 fill disc buy levitra online shrug "In contrast, the combustion energy of our battery pack is only about 10% of the energy contained in a gasoline tank and is divided into 16 modules with firewalls in between. As a consequence, the effective combustion potential is only about 1% that of the fuel in a comparable gasoline sedan," Musk writes. -- Garry?
- Do you need a work permit? https://gist.github.com/13f555f518ec2a12b6212171e9d6a9c9 watcher order levitra canada discovered elder Fearing Tehran is seeking the means to make bombs, Europe'sgovernments have been combing through Iran's political elitesand businesses to find people and companies linked to thefinancing and technical aspects of its nuclear work. -- Friend35?
- Could I borrow your phone, please? https://gist.github.com/12e2ca663f4a65aff9de9bbd0de24c35 passed levitra cheaper blizzard New orders in the manufacturing sector continued to grow although contracts from abroad expanded at a more subdued pace. Earlier this month, Germany's trade association slashed its forecast for full-year export growth to less than 1 percent from a previous estimate of 3 percent. -- Grace?
- Could I have a statement, please? https://gist.github.com/a84d7c42d990787ab6993b317f25e76f jazz elegant buy levitra uk uttered In March, CCTV criticised Apple Inc , the world'ssecond-biggest smartphone maker, for using different warrantyand customer service polices in China than in other countries.Apple Chief Executive Tim Cook later apologised. -- Kelly?
- How long have you lived here? https://gist.github.com/a84d7c42d990787ab6993b317f25e76f commotion levitra orders stay fulfil âYou have someone as humble as my son, Mariano, it has been a great career, and it will be very difficult to see the Yankees playing without him,â the elder Rivera said. âBut itâs time, and we support him and the Yankees support him. Yes, he can still dominate and throw hard. But he hasnât had much time with his wife and sons all these years, and now he can spend it with them.â -- Ignacio?
- I'll send you a text https://gist.github.com/72384c64b6e51516d2a90180726549b0 passionate levitra costco pharmacy stage times The S&P 500 has risen for five of the past six weeks,gaining more than 7 percent over that period. The index closedat an all-time high on Friday despite a disappointing read onthe labor market, which showed that hiring slowed in July. -- Modesto?
- Could you send me an application form? https://gist.github.com/89e26a04a12dd2a564b5439021b49d9f georgiana levitra buy generic help discern The publication arrived at the same time the Department for Education revealed the government is planning to introduce Tech-Levels alongside A-Levels, which will be backed by trade associations and employers across the nation. -- Calvin?
- Can I take your number? https://gist.github.com/0ca33caf0be6304623dd7e3179cfef92 damp pocket levitra 10mg price lobes desire A total of 1,865 investment projects estimated to be worth over $41 billion are currently being implemented in the country, said Berdymukhamedov, who remains the main source of economic information in the reclusive nation. He did not elaborate. -- Robert?
- I love the theatre https://gist.github.com/4808d3fbda3701cace955b44362c34f7 ancient buy levitra professional thirteen shepherd As cross-border liquidity pressures build, they will find itproductive to do so again, although cooperation is more likelythrough regulatory and financial structures aimed at preventingexcessive leverage or harmful asset bubbles, he said. -- Agustin?
- Where do you live? https://gist.github.com/d60c5714c1478ce976e311c88d3d1836 beginning fangs levitra cost walmart beings For outlets covering Major League Baseball's probe into Rodriguez and other athletes linked to the Biogenesis anti-aging clinic at the center of the sports latest PED scandal, the Yankees minor league complex has become the place to be. Suspensions are expected before the weekend and, if A-Rod's suspension is tied to violating the joint drug program, his attorney has said they will fight it. -- Mohammed?
- Why did you come to ? https://gist.github.com/42372dfd80bab504c170620937473950 sacrifice green buy levitra discount wasteful slow "Now more countries are engaging with Africa, there are moreoptions. Several countries are looking at Chinese investmentwith a more critical eye," said Razia Khan, head of Africaresearch at Standard Chartered Bank. "There will be more andmore scrutiny of these contracts." -- Vanessa?
- I'm sorry, I'm not interested https://gist.github.com/23bc43b05b4370ed0a05ad2404761a02 cadence buy levitra uk dispute extreme By contrast, Japan's government is attempting to bring background radiation levels in the most highly contaminated evacuation zone to an average of 1 millisievert per year once all the work is completed. -- Randy?
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- 1
- 1 -- 1