Libraryless. Click here for Pure Java version (3684L/23K).
1 | transient sclass DoubleWordIndex<A> { |
2 | new WordIndex<A> index1; // forwards (normal words) |
3 | new WordIndex<A> index2; // backwards (reversed words) |
4 | |
5 | *() {} |
6 | |
7 | *(Comparator<A> valueComparator) { |
8 | index1 = new WordIndex(valueComparator); |
9 | index2 = new WordIndex(valueComparator); |
10 | } |
11 | |
12 | *(Map<A, S> map) { fOr (A a, S text : map) add(a, text); } |
13 | |
14 | void add(A a, S text) { |
15 | Set<S> words = extractWords(text); |
16 | for (S word : words) |
17 | addWord(a, word); |
18 | } |
19 | |
20 | void addWord(A a, S word) { |
21 | index1.addWord(a, word); |
22 | index2.addWord(a, reversed(word)); |
23 | } |
24 | |
25 | Set<A> get(S word) { |
26 | ret index1.get(word); |
27 | } |
28 | |
29 | Set<S> extractWords(S text) { |
30 | ret index1.extractWords(text); |
31 | } |
32 | |
33 | L<IntRange> wordRanges(S text) { |
34 | ret index1.wordRanges(text); |
35 | } |
36 | |
37 | int numWords() { ret index1.numWords(); } |
38 | } |
Began life as a copy of #1024242
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1029004 |
Snippet name: | DoubleWordIndex - words indexed forwards and backwards |
Eternal ID of this version: | #1029004/8 |
Text MD5: | ff3a9c1ccb45f60c983f1500959080a9 |
Transpilation MD5: | b7b527e20d901a68ea24edf87b3ef102 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-07-16 20:49:17 |
Source code size: | 877 bytes / 38 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 229 / 528 |
Version history: | 7 change(s) |
Referenced in: | [show references] |