text_ux 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +25 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +51 -0
  7. data/Rakefile +18 -0
  8. data/ext/text_ux/extconf.rb +5 -0
  9. data/ext/text_ux/text_ux.cpp +252 -0
  10. data/lib/text_ux.rb +5 -0
  11. data/lib/text_ux/version.rb +3 -0
  12. data/spec/fixtures/test.ux +0 -0
  13. data/spec/spec_helper.rb +19 -0
  14. data/spec/text_ux_spec.rb +137 -0
  15. data/text_ux.gemspec +26 -0
  16. data/vendor/ux-trie/ux-0.1.9/.lock-waf_darwin_build +8 -0
  17. data/vendor/ux-trie/ux-0.1.9/.unittest-gtest/gtest-1.6.0/fused-src/gtest/gtest-all.cc +9118 -0
  18. data/vendor/ux-trie/ux-0.1.9/.unittest-gtest/gtest-1.6.0/fused-src/gtest/gtest.h +19537 -0
  19. data/vendor/ux-trie/ux-0.1.9/.unittest-gtest/gtest-1.6.0/fused-src/gtest/gtest_main.cc +39 -0
  20. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Build.py +733 -0
  21. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Build.pyc +0 -0
  22. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/ConfigSet.py +147 -0
  23. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/ConfigSet.pyc +0 -0
  24. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Configure.py +314 -0
  25. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Configure.pyc +0 -0
  26. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Context.py +298 -0
  27. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Context.pyc +0 -0
  28. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Errors.py +37 -0
  29. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Errors.pyc +0 -0
  30. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Logs.py +149 -0
  31. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Logs.pyc +0 -0
  32. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Node.py +500 -0
  33. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Node.pyc +0 -0
  34. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Options.py +130 -0
  35. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Options.pyc +0 -0
  36. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Runner.py +191 -0
  37. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Runner.pyc +0 -0
  38. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Scripting.py +358 -0
  39. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Scripting.pyc +0 -0
  40. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Task.py +669 -0
  41. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Task.pyc +0 -0
  42. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/TaskGen.py +341 -0
  43. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/TaskGen.pyc +0 -0
  44. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/__init__.py +4 -0
  45. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/__init__.pyc +0 -0
  46. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/ar.py +12 -0
  47. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/ar.pyc +0 -0
  48. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/asm.py +25 -0
  49. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/bison.py +29 -0
  50. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/c.py +27 -0
  51. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/c_aliases.py +56 -0
  52. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/c_aliases.pyc +0 -0
  53. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/c_config.py +708 -0
  54. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/c_config.pyc +0 -0
  55. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/c_osx.py +121 -0
  56. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/c_osx.pyc +0 -0
  57. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/c_preproc.py +606 -0
  58. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/c_preproc.pyc +0 -0
  59. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/c_tests.py +110 -0
  60. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/c_tests.pyc +0 -0
  61. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/ccroot.py +372 -0
  62. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/ccroot.pyc +0 -0
  63. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/compiler_c.py +39 -0
  64. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/compiler_cxx.py +39 -0
  65. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/compiler_cxx.pyc +0 -0
  66. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/compiler_d.py +30 -0
  67. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/compiler_fc.py +45 -0
  68. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/cs.py +98 -0
  69. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/cxx.py +27 -0
  70. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/cxx.pyc +0 -0
  71. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/d.py +51 -0
  72. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/d_config.py +47 -0
  73. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/d_scan.py +133 -0
  74. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/dbus.py +30 -0
  75. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/dmd.py +43 -0
  76. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/errcheck.py +153 -0
  77. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/fc.py +123 -0
  78. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/fc_config.py +271 -0
  79. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/fc_scan.py +68 -0
  80. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/flex.py +27 -0
  81. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/g95.py +55 -0
  82. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/gas.py +10 -0
  83. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/gcc.py +98 -0
  84. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/gdc.py +34 -0
  85. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/gfortran.py +69 -0
  86. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/glib2.py +174 -0
  87. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/gnu_dirs.py +65 -0
  88. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/gxx.py +98 -0
  89. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/gxx.pyc +0 -0
  90. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/icc.py +31 -0
  91. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/icpc.py +30 -0
  92. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/ifort.py +42 -0
  93. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/intltool.py +78 -0
  94. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/irixcc.py +49 -0
  95. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/javaw.py +272 -0
  96. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/kde4.py +49 -0
  97. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/lua.py +19 -0
  98. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/msvc.py +650 -0
  99. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/nasm.py +13 -0
  100. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/perl.py +78 -0
  101. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/python.py +303 -0
  102. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/qt4.py +424 -0
  103. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/ruby.py +104 -0
  104. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/suncc.py +54 -0
  105. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/suncxx.py +55 -0
  106. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/tex.py +222 -0
  107. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/vala.py +215 -0
  108. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/waf_unit_test.py +79 -0
  109. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/winres.py +34 -0
  110. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/xlc.py +46 -0
  111. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Tools/xlcxx.py +46 -0
  112. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Utils.py +334 -0
  113. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/Utils.pyc +0 -0
  114. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/__init__.py +4 -0
  115. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/__init__.pyc +0 -0
  116. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/ansiterm.py +173 -0
  117. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/ansiterm.pyc +0 -0
  118. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/extras/__init__.py +4 -0
  119. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/extras/__init__.pyc +0 -0
  120. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/extras/compat15.py +223 -0
  121. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/extras/compat15.pyc +0 -0
  122. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/fixpy2.py +50 -0
  123. data/vendor/ux-trie/ux-0.1.9/.waf-1.6.8-3e3391c5f23fbabad81e6d17c63a1b1e/waflib/fixpy2.pyc +0 -0
  124. data/vendor/ux-trie/ux-0.1.9/src/bitVec.cpp +119 -0
  125. data/vendor/ux-trie/ux-0.1.9/src/bitVec.hpp +64 -0
  126. data/vendor/ux-trie/ux-0.1.9/src/bitVecTest.cpp +143 -0
  127. data/vendor/ux-trie/ux-0.1.9/src/cmdline.h +809 -0
  128. data/vendor/ux-trie/ux-0.1.9/src/rsDic.cpp +121 -0
  129. data/vendor/ux-trie/ux-0.1.9/src/rsDic.hpp +57 -0
  130. data/vendor/ux-trie/ux-0.1.9/src/ux.hpp +26 -0
  131. data/vendor/ux-trie/ux-0.1.9/src/uxMain.cpp +206 -0
  132. data/vendor/ux-trie/ux-0.1.9/src/uxMap.cpp +0 -0
  133. data/vendor/ux-trie/ux-0.1.9/src/uxMap.hpp +248 -0
  134. data/vendor/ux-trie/ux-0.1.9/src/uxMapTest.cpp +139 -0
  135. data/vendor/ux-trie/ux-0.1.9/src/uxTest.cpp +229 -0
  136. data/vendor/ux-trie/ux-0.1.9/src/uxTrie.cpp +529 -0
  137. data/vendor/ux-trie/ux-0.1.9/src/uxTrie.hpp +220 -0
  138. data/vendor/ux-trie/ux-0.1.9/src/uxUtil.cpp +92 -0
  139. data/vendor/ux-trie/ux-0.1.9/src/uxUtil.hpp +35 -0
  140. data/vendor/ux-trie/ux-0.1.9/src/wscript +43 -0
  141. data/vendor/ux-trie/ux-0.1.9/unittest_gtest.py +0 -0
  142. data/vendor/ux-trie/ux-0.1.9/unittest_gtest.pyc +0 -0
  143. data/vendor/ux-trie/ux-0.1.9/unittestt.py +166 -0
  144. data/vendor/ux-trie/ux-0.1.9/ux.pc.in +10 -0
  145. data/vendor/ux-trie/ux-0.1.9/waf +0 -0
  146. data/vendor/ux-trie/ux-0.1.9/wscript +32 -0
  147. metadata +249 -0
@@ -0,0 +1,220 @@
1
+ /*
2
+ * Copyright (c) 2010 Daisuke Okanohara
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions
6
+ * are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above Copyright
9
+ * notice, this list of conditions and the following disclaimer.
10
+ *
11
+ * 2. Redistributions in binary form must reproduce the above Copyright
12
+ * notice, this list of conditions and the following disclaimer in the
13
+ * documentation and/or other materials provided with the distribution.
14
+ *
15
+ * 3. Neither the name of the authors nor the names of its contributors
16
+ * may be used to endorse or promote products derived from this
17
+ * software without specific prior written permission.
18
+ */
19
+
20
+ #ifndef UX_TRIE_HPP__
21
+ #define UX_TRIE_HPP__
22
+
23
+ #include <string>
24
+ #include <vector>
25
+ #include <stdint.h>
26
+ #include "bitVec.hpp"
27
+ #include "rsDic.hpp"
28
+
29
+ namespace ux{
30
+
31
+ typedef uint64_t id_t;
32
+
33
+ enum {
34
+ NOTFOUND = 0xFFFFFFFFU,
35
+ LIMIT_DEFAULT = 0xFFFFFFFFU
36
+ };
37
+
38
+
39
+ /**
40
+ * Succinct Trie Data structure
41
+ */
42
+ class Trie {
43
+ public:
44
+ /**
45
+ * Constructor
46
+ */
47
+ Trie();
48
+
49
+ /**
50
+ * Constructor
51
+ * @param keyList input key list
52
+ * @param isTailUX use tail compression.
53
+ */
54
+ Trie(std::vector<std::string>& keyList, bool isTailUX = true);
55
+
56
+ /**
57
+ * Destructor
58
+ */
59
+ ~Trie();
60
+
61
+ /**
62
+ * Build a dictionary from keyList
63
+ * @param keyList input key list
64
+ * @param isTailUX use tail compression.
65
+ */
66
+ void build(std::vector<std::string>& keyList, bool isTailUX = true);
67
+
68
+ /**
69
+ * Save the dictionary in a file
70
+ * @param indexName The file name
71
+ * @return 0 on success, -1 on failure
72
+ */
73
+ int save(const char* indexName) const;
74
+
75
+ /**
76
+ * Load the dicitonary from a file
77
+ * @param indexName The filename
78
+ * @return 0 on success, -1 on failure
79
+ */
80
+ int load(const char* indexName);
81
+
82
+ /**
83
+ * Save the dictionary in ostream
84
+ * @param os The ostream as an output
85
+ * @return 0 on success, -1 on failure
86
+ */
87
+ int save(std::ostream& os) const;
88
+
89
+ /**
90
+ * Load the dictionary from istream
91
+ * @param is The istream as an input
92
+ * @return 0 on success, -1 on failure
93
+ */
94
+ int load(std::istream& is);
95
+
96
+ /**
97
+ * Return the longest key that matches the prefix of the query in the dictionary
98
+ * @param str the query
99
+ * @param len the length of the query
100
+ * @param retLen The length of the matched key in the dictionary
101
+ * @return The ID of the matched key or NOTFOUND if no key is matched
102
+ */
103
+ id_t prefixSearch(const char* str, size_t len, size_t& retLen) const;
104
+
105
+ /**
106
+ * Return the all keys that match the prefix of the query in the dictionary
107
+ * @param str the query
108
+ * @param len the length of the query
109
+ * @param retIDs The IDs of the matched keys
110
+ * @param limit The maximum number of matched keys
111
+ * @return The number of matched keys
112
+ */
113
+ size_t commonPrefixSearch(const char* str, size_t len, std::vector<id_t>& retIDs,
114
+ size_t limit = LIMIT_DEFAULT) const;
115
+
116
+ /**
117
+ * Return the all keys whose their prefixes match the query
118
+ * @param str the query
119
+ * @param len the length of the query
120
+ * @param The IDs of the matched keys
121
+ * @param limit The maximum number of matched keys
122
+ * @return The number of matched keys
123
+ */
124
+ size_t predictiveSearch(const char* str, size_t len, std::vector<id_t>& retIDs,
125
+ size_t limit = LIMIT_DEFAULT) const;
126
+
127
+ /**
128
+ * Return the key for the given ID
129
+ * @param id The ID of the key
130
+ * @param ret The key for the given ID or empty if such ID does not exist
131
+ */
132
+ void decodeKey(id_t id, std::string& ret) const;
133
+
134
+ /**
135
+ * Return the key for the given ID
136
+ * @param id The ID of the key
137
+ * @return The key for the given ID or empty if such ID does not exist
138
+ */
139
+ std::string decodeKey(id_t id) const;
140
+
141
+ /**
142
+ * Return the number of keys in the dictionary
143
+ * @return the number of keys in the dictionary
144
+ */
145
+ size_t size() const;
146
+
147
+ /**
148
+ * Clear the internal state
149
+ */
150
+ void clear();
151
+
152
+ /*
153
+ * Get the allocated memory size
154
+ * @return The size of the allocated memory
155
+ */
156
+ size_t getAllocSize() const;
157
+
158
+ /*
159
+ * Report the statistics of the memory allocation
160
+ * @param allocSize The initial overhead size
161
+ * @param os The output distination
162
+ */
163
+ void allocStat(size_t allocSize, std::ostream& os) const;
164
+
165
+ /*
166
+ * Report the internal statistics
167
+ * @param os The output distination
168
+ */
169
+ void stat(std::ostream& os) const;
170
+
171
+ /**
172
+ * Report the error message for the error ID
173
+ * @param error The error ID
174
+ * @return The error message
175
+ */
176
+ static std::string what(int error);
177
+
178
+ private:
179
+ void buildTailUX();
180
+ bool isLeaf(uint64_t pos) const;
181
+ void getChild(uint8_t c, uint64_t& pos, uint64_t& zeros) const;
182
+ void getParent(uint8_t& c, uint64_t& pos, uint64_t& zeros) const;
183
+ void traverse(const char* str, size_t len, size_t& retLen, std::vector<id_t>& retIDs,
184
+ size_t limit) const;
185
+
186
+ void enumerateAll(uint64_t pos, uint64_t zeros, std::vector<id_t>& retIDs, size_t limit) const;
187
+ bool tailMatch(const char* str, size_t len, size_t depth,
188
+ uint64_t tailID, size_t& retLen) const;
189
+ std::string getTail(uint64_t i) const;
190
+
191
+ RSDic loud_;
192
+ RSDic terminal_;
193
+ RSDic tail_;
194
+
195
+ std::vector<std::string> vtails_;
196
+ Trie* vtailux_;
197
+ std::vector<uint8_t> edges_;
198
+ BitVec tailIDs_;
199
+ size_t tailIDLen_;
200
+ size_t keyNum_;
201
+ bool isReady_;
202
+
203
+ public:
204
+ /**
205
+ * Error code.
206
+ */
207
+ enum {
208
+ SUCCESS = 0,
209
+ FILE_OPEN_ERROR = 1,
210
+ FILE_WRITE_ERROR = 2,
211
+ FILE_READ_ERROR = 3,
212
+ SAVE_ERROR = 4,
213
+ LOAD_ERROR = 5
214
+ };
215
+ };
216
+
217
+
218
+ }
219
+
220
+ #endif // UX_TRIE_HPP__
@@ -0,0 +1,92 @@
1
+ /*
2
+ * Copyright (c) 2010 Daisuke Okanohara
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions
6
+ * are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above Copyright
9
+ * notice, this list of conditions and the following disclaimer.
10
+ *
11
+ * 2. Redistributions in binary form must reproduce the above Copyright
12
+ * notice, this list of conditions and the following disclaimer in the
13
+ * documentation and/or other materials provided with the distribution.
14
+ *
15
+ * 3. Neither the name of the authors nor the names of its contributors
16
+ * may be used to endorse or promote products derived from this
17
+ * software without specific prior written permission.
18
+ */
19
+
20
+ #include "uxUtil.hpp"
21
+
22
+ namespace ux{
23
+
24
+ uint64_t lg2(const uint64_t x){
25
+ uint64_t ret = 0;
26
+ while (x >> ret){
27
+ ++ret;
28
+ }
29
+ return ret;
30
+ }
31
+
32
+ uint64_t mask(uint64_t x, uint64_t pos){
33
+ return x & ((1LLU << pos) - 1);
34
+ }
35
+
36
+ uint64_t popCount(uint64_t r) {
37
+ r = (r & 0x5555555555555555ULL) +
38
+ ((r >> 1) & 0x5555555555555555ULL);
39
+ r = (r & 0x3333333333333333ULL) +
40
+ ((r >> 2) & 0x3333333333333333ULL);
41
+ r = (r + (r >> 4)) & 0x0f0f0f0f0f0f0f0fULL;
42
+ r = r + (r >> 8);
43
+ r = r + (r >> 16);
44
+ r = r + (r >> 32);
45
+ return (uint64_t)(r & 0x7f);
46
+ }
47
+
48
+ uint64_t popCountMasked(uint64_t x, uint64_t pos){
49
+ return popCount(mask(x, pos));
50
+ }
51
+
52
+ uint64_t selectBlock(uint64_t r, uint64_t x, uint8_t b) {
53
+ if (!b) x = ~x;
54
+ uint64_t x1 = x - ((x & 0xAAAAAAAAAAAAAAAALLU) >> 1);
55
+ uint64_t x2 = (x1 & 0x3333333333333333LLU) + ((x1 >> 2) & 0x3333333333333333LLU);
56
+ uint64_t x3 = (x2 + (x2 >> 4)) & 0x0F0F0F0F0F0F0F0FLLU;
57
+
58
+ uint64_t pos = 0;
59
+ for (;; pos += 8){
60
+ uint64_t b = (x3 >> pos) & 0xFFLLU;
61
+ if (r <= b) break;
62
+ r -= b;
63
+ }
64
+
65
+ uint64_t v2 = (x2 >> pos) & 0xFLLU;
66
+ if (r > v2) {
67
+ r -= v2;
68
+ pos += 4;
69
+ }
70
+
71
+ uint64_t v1 = (x1 >> pos) & 0x3LLU;
72
+ if (r > v1){
73
+ r -= v1;
74
+ pos += 2;
75
+ }
76
+
77
+ uint64_t v0 = (x >> pos) & 0x1LLU;
78
+ if (v0 < r){
79
+ r -= v0;
80
+ pos += 1;
81
+ }
82
+
83
+ return pos;
84
+ }
85
+
86
+ uint64_t getBitNum(uint64_t oneNum, uint64_t num, uint8_t bit){
87
+ if (bit) return oneNum;
88
+ else return num - oneNum;
89
+ }
90
+
91
+ }
92
+
@@ -0,0 +1,35 @@
1
+ /*
2
+ * Copyright (c) 2010 Daisuke Okanohara
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions
6
+ * are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above Copyright
9
+ * notice, this list of conditions and the following disclaimer.
10
+ *
11
+ * 2. Redistributions in binary form must reproduce the above Copyright
12
+ * notice, this list of conditions and the following disclaimer in the
13
+ * documentation and/or other materials provided with the distribution.
14
+ *
15
+ * 3. Neither the name of the authors nor the names of its contributors
16
+ * may be used to endorse or promote products derived from this
17
+ * software without specific prior written permission.
18
+ */
19
+
20
+ #ifndef UX_UTIL_HPP__
21
+ #define UX_UTIL_HPP__
22
+
23
+ #include <stdint.h>
24
+
25
+ namespace ux {
26
+ uint64_t lg2(uint64_t x);
27
+ uint64_t mask(uint64_t x, uint64_t pos);
28
+ uint64_t popCount(uint64_t r);
29
+ uint64_t popCountMasked(uint64_t x, uint64_t pos);
30
+ uint64_t selectBlock(uint64_t pos, uint64_t x, uint8_t b);
31
+ uint64_t getBitNum(uint64_t oneNum, uint64_t num, uint8_t bit);
32
+ }
33
+
34
+ #endif // UX_UTIL_HPP__
35
+
@@ -0,0 +1,43 @@
1
+ APPNAME= 'ux'
2
+
3
+ top = '.'
4
+ out = 'bin'
5
+
6
+ def options(ctx):
7
+ pass
8
+
9
+ def configure(ctx):
10
+ pass
11
+
12
+ def build(bld):
13
+ bld.shlib(
14
+ source = 'uxTrie.cpp bitVec.cpp rsDic.cpp uxUtil.cpp uxMap.cpp',
15
+ target = 'ux',
16
+ name = 'UX',
17
+ includes = '.')
18
+ bld.program(
19
+ source = 'uxMain.cpp',
20
+ target = 'ux',
21
+ includes = '.',
22
+ use = 'UX')
23
+ bld.program(
24
+ features = 'gtest',
25
+ source = 'uxTest.cpp',
26
+ target = 'ux_test',
27
+ use = 'UX' ,
28
+ includes = '.')
29
+ bld.program(
30
+ features = 'gtest',
31
+ source = 'bitVecTest.cpp',
32
+ target = 'bitvec_test',
33
+ use = 'UX',
34
+ includes = '.')
35
+
36
+ bld.program(
37
+ features = 'gtest',
38
+ source = 'uxMapTest.cpp',
39
+ target = 'uxmap_test',
40
+ use = 'UX',
41
+ includes = '.')
42
+
43
+ bld.install_files('${PREFIX}/include/ux', bld.path.ant_glob('*.hpp'))
@@ -0,0 +1,166 @@
1
+ #! /usr/bin/env python
2
+ # encoding: utf-8
3
+
4
+ import os, sys
5
+ import Options, Task, Utils, Logs
6
+ from TaskGen import before, after, feature
7
+ from Constants import *
8
+
9
+ def detect(conf):
10
+ if conf.check_cfg(path = 'gtest-config',
11
+ args = '--cppflags --cxxflags --ldflags --libs',
12
+ package = '',
13
+ uselib_store = 'GTEST'):
14
+ def f(str):
15
+ if str == 'gtest':
16
+ return 'gtest_main'
17
+ else:
18
+ return str
19
+ conf.env.LIB_GTEST = map(f, conf.env.LIB_GTEST)
20
+
21
+ def set_options(opt):
22
+ opt.add_option('--check', action = 'store_true', default = False,
23
+ help = 'Execute unit tests')
24
+ opt.add_option('--checkall', action = 'store_true', default = False,
25
+ help = 'Execute all unit tests')
26
+ opt.add_option('--checkone', action = 'store', default = False,
27
+ help = 'Execute specified unit test')
28
+ opt.add_option('--checkfilter', action = 'store', default = False,
29
+ help = 'Execute unit tests sprcified by pattern')
30
+
31
+ def match_filter(filt, targ):
32
+ if isinstance(filt, str):
33
+ (pat, _, _) = filt.partition('.')
34
+ if pat == '*':
35
+ return True
36
+ return pat == targ
37
+ return False
38
+
39
+ def test_remover(self):
40
+ if not Options.options.check and not Options.options.checkall and self.target != Options.options.checkone and not match_filter(Options.options.checkfilter, self.target):
41
+ self.meths[:] = []
42
+
43
+ feature('testt', 'gtest')(test_remover)
44
+ before('apply_core')(test_remover)
45
+
46
+ def make_test(self):
47
+ if not 'cprogram' in self.features:
48
+ Logs.error('test cannot be executed %s'%self)
49
+ return
50
+ self.default_install_path = None
51
+ self.create_task('utest', self.link_task.outputs)
52
+
53
+ feature('testt', 'gtest')(make_test)
54
+ after('apply_link', 'vars_target_cprogram')(make_test)
55
+
56
+ def gtest_attach(self):
57
+ if not self.env.HAVE_GTEST:
58
+ Logs.error('gtest is not found')
59
+ self.meths[:] = []
60
+ return
61
+
62
+ if isinstance(self.uselib, str):
63
+ self.uselib += " GTEST"
64
+ else:
65
+ self.uselib.append('GTEST')
66
+
67
+ feature('gtest')(gtest_attach)
68
+ before('apply_core')(gtest_attach)
69
+
70
+ import threading
71
+ testlock = threading.Lock()
72
+
73
+ def exec_test(self):
74
+ variant = self.env.variant()
75
+ filename = self.inputs[0].abspath(self.env)
76
+
77
+ try:
78
+ fu = getattr(self.generator.bld, 'all_test_paths')
79
+ except AttributeError:
80
+ fu = os.environ.copy()
81
+ self.generator.bld.all_test_paths = fu
82
+
83
+ lst = []
84
+ for obj in self.generator.bld.all_task_gen:
85
+ link_task=getattr(obj, 'link_task', None)
86
+ if link_task and link_task.env.variant()==variant:
87
+ lst.append(link_task.outputs[0].parent.abspath(obj.env))
88
+
89
+ def add_path(dct, path, var):
90
+ dct[var] = os.pathsep.join(Utils.to_list(path)+[os.environ.get(var, '')])
91
+ if sys.platform=='win32':
92
+ add_path(fu, lst, 'PATH')
93
+ elif sys.platform=='darwin':
94
+ add_path(fu, lst, 'DYLD_LIBRARY_PATH')
95
+ add_path(fu, lst, 'LD_LIBRARY_PATH')
96
+ else:
97
+ add_path(fu, lst, 'LD_LIBRARY_PATH')
98
+
99
+ cmdline = [filename]
100
+ cwd = self.inputs[0].parent.abspath(self.env)
101
+
102
+ if isinstance(Options.options.checkfilter, str):
103
+ (_, _, filt) = Options.options.checkfilter.partition('.')
104
+ if filt != "":
105
+ cmdline += ['--gtest_filter=' + filt]
106
+
107
+ proc = Utils.pproc.Popen(cmdline, cwd = cwd, env = fu,
108
+ stderr = Utils.pproc.PIPE,
109
+ stdout = Utils.pproc.PIPE)
110
+ (stdout, stderr) = proc.communicate()
111
+ tup = (filename, proc.returncode, stdout, stderr)
112
+
113
+ testlock.acquire()
114
+ try:
115
+ try:
116
+ self.generator.bld.utest_results.append(tup)
117
+ except:
118
+ self.generator.bld.utest_results = [tup]
119
+
120
+ a = getattr(self.generator.bld, 'added_post_fun', False)
121
+ if not a:
122
+ self.generator.bld.add_post_fun(summary)
123
+ self.generator.bld.added_post_fun = True
124
+
125
+ finally:
126
+ testlock.release()
127
+
128
+ cls = Task.task_type_from_func('utest', func = exec_test, color = 'PINK', ext_in = '.bin')
129
+ old = cls.runnable_status
130
+
131
+ def test_status(self):
132
+ if Options.options.checkall:
133
+ return RUN_ME
134
+ if Options.options.checkone == self.generator.name:
135
+ return RUN_ME
136
+ if isinstance(Options.options.checkfilter, str):
137
+ if match_filter(Options.options.checkfilter, self.generator.name):
138
+ return RUN_ME
139
+ return old(self)
140
+
141
+ cls.runnable_status = test_status
142
+ cls.quiet = 1
143
+
144
+ def summary(bld):
145
+ lst = getattr(bld, 'utest_results', [])
146
+
147
+ if not lst: return
148
+
149
+ total = len(lst)
150
+ fail = len([x for x in lst if x[1]])
151
+
152
+ Utils.pprint('CYAN', 'test summary')
153
+ Utils.pprint('CYAN', ' tests that pass %d/%d' % (total-fail, total))
154
+
155
+ for (f, code, out, err) in lst:
156
+ if not code:
157
+ Utils.pprint('GREEN', ' %s' % f)
158
+ if isinstance(Options.options.checkfilter, str):
159
+ print(out)
160
+
161
+ if fail>0:
162
+ Utils.pprint('RED', ' tests that fail %d/%d' % (fail, total))
163
+ for (f, code, out, err) in lst:
164
+ if code:
165
+ Utils.pprint('RED', ' %s' % f)
166
+ print(out)