test-pefix-tree.nut 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. auto word_list = [==[
  2. account_id
  3. accounts
  4. active
  5. address
  6. batch_order_line_id
  7. buy_description
  8. buy_discount
  9. buy_notes
  10. buy_other_costs
  11. buy_price
  12. buy_quantity_min
  13. buys
  14. cash
  15. _cdate_
  16. city
  17. code
  18. company
  19. contact
  20. country
  21. date
  22. days
  23. delete
  24. description
  25. discount_amt
  26. discount_over_sales
  27. discount_pct
  28. email
  29. entities
  30. entity_address
  31. entity_city
  32. entity_country
  33. entity_id
  34. entity_name
  35. entity_order_number
  36. entity_phone
  37. entity_sales_tax_exempt
  38. entity_state
  39. entity_tax_number
  40. entity_use_sales_tax2
  41. entity_zip
  42. fax
  43. first_total
  44. gps_coordinates
  45. group_id
  46. group_set
  47. id
  48. image
  49. image_id
  50. images
  51. inactive
  52. insert
  53. irpf_pct_retention
  54. is_active
  55. line_subtotal
  56. line_total
  57. lines_count
  58. markup_to_discount
  59. _mdate_
  60. measure_unit_id
  61. mime_type
  62. months
  63. name
  64. notes
  65. only_prices_older
  66. order_by_creation
  67. order_by_modification
  68. order_date
  69. order_id
  70. order_number
  71. order_type_id
  72. order_types
  73. order_valid_till_date
  74. orders
  75. orders_lines
  76. parent_id
  77. payment_type_id
  78. payment_types
  79. periode_count
  80. periode_type
  81. phone
  82. price
  83. price_decimals
  84. price_formula
  85. product_id
  86. products
  87. quantity
  88. query_limit
  89. reference
  90. reference_code
  91. sales
  92. sales_tax1_amt
  93. sales_tax1_pct
  94. sales_tax2_amt
  95. sales_tax2_pct
  96. sales_tax_exempt
  97. sales_tax_id
  98. sell_description
  99. sell_markup
  100. sell_notes
  101. sell_price
  102. sell_price2
  103. sell_quantity_min
  104. sell_without_stock
  105. series
  106. show_on_buys
  107. show_on_sales
  108. show_on_web
  109. show_price_on_web
  110. state
  111. stock_max
  112. stock_min
  113. subtotal_amt
  114. supplier_code
  115. tags
  116. tax_exempt
  117. tax_number
  118. thumbnail
  119. total
  120. total_amt
  121. trigger
  122. unit_weight
  123. units_by_package
  124. update
  125. use_sales_tax2
  126. user_code
  127. warranty_id
  128. web
  129. weeks
  130. weight
  131. weight_total
  132. with_accounts
  133. with_headers
  134. with_images
  135. xref_order_line_id
  136. years
  137. zip
  138. ]==];
  139. /*
  140. word_list.gmatch(
  141. "\"([^\"]+)\"",
  142. function(m)
  143. {
  144. print(m);
  145. return true;
  146. }
  147. );
  148. */
  149. word_list = word_list.split('\n');
  150. word_list.sort();
  151. //print(word_list.join("\n"));
  152. auto prefix_level = array(word_list.len());
  153. auto min(a,b) {return a < b ? a : b;}
  154. auto prev_word;
  155. foreach(idx, word in word_list)
  156. {
  157. if(idx > 0)
  158. {
  159. auto i=0, len = min(prev_word.len(), word.len());
  160. for(; i < len && (prev_word[i] == word[i]) ; ++i);
  161. prefix_level[idx] = i;
  162. }
  163. else
  164. {
  165. prefix_level[idx] = 0;
  166. }
  167. prev_word = word;
  168. }
  169. foreach(idx, word in word_list)
  170. {
  171. //if(prefix_level[idx] == 0)
  172. print(prefix_level[idx], idx, word);
  173. }
  174. /*
  175. #include "/home/mingo/dev/SquiLu/SquiLu/samples/Trie.nut"
  176. var the_trie = new Trie({});
  177. foreach(word in word_list) the_trie.add(word);
  178. print(the_trie.contains("with_images"));
  179. */
  180. /*
  181. #include "/home/mingo/dev/SquiLu/SquiLu/samples/perfect-hash.nut"
  182. var mywords = {};
  183. foreach(idx, word in word_list)
  184. {
  185. mywords[word] <- idx+1;
  186. //mywords[word] <- word;
  187. }
  188. var ph = perfect_hash_create(mywords);
  189. foreach(k,v in mywords)
  190. {
  191. print(k,v, perfect_hash_lookup(ph[0], ph[1], k));
  192. }
  193. foreach(k,v in ph[0])
  194. {
  195. print(k,v);
  196. }
  197. foreach(k,v in ph[1])
  198. {
  199. print(k,v);
  200. }
  201. */