Skip to content

Commit e2684bc

Browse files
authored
Merge pull request #11 from webKrafters/arr-to-iter
protected method - addition
2 parents 84c204a + e547a7f commit e2684bc

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

docs.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ isEmpty: boolean
126126
```tsx
127127
size: number
128128
```
129-
## Methods
129+
130+
## Methods (Scope: Public)
131+
130132
### add
131133
<p>Accepts a sequence of items to merge into this instance.</p>
132134

@@ -288,6 +290,15 @@ Accepts sequences of items to remove from the trie. Will record the outcome of t
288290
removeMany(data : Array<Iterable<T>>): Array<OpStatus>
289291
```
290292

293+
## Methods (Scope: Protected)
294+
295+
### _getNodeAtPrefixEnd
296+
<p>Produces the underlying node containing the final value in <code>prefix</code> items.</p>
297+
<p>Will produce the root node for the empty <code>prefix</code> items.</p>
298+
299+
```tsx
300+
_getNodeAtPrefixEnd( prefix: Iterable<T> ): Node<T>
301+
```
291302
## Static
292303

293304
### makeTrieable

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@
5959
"test:watch": "jest --updateSnapshot --watchAll"
6060
},
6161
"types": "dist/index.d.ts",
62-
"version": "0.5.1"
62+
"version": "0.5.2"
6363
}

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
export type {
22
EqualityFn,
33
KeyType,
4+
Node,
45
Options,
56
OpStatus,
67
Status,
78
TrieableNode,
89
TrieableNodeKeyMapping
910
} from './main';
10-
1111
export { default as default } from './main';

src/main.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,15 @@ export default class Trie<T = unknown> {
335335
}
336336
return results;
337337
}
338+
protected _getNodeAtPrefixEnd( prefix : Iterable<T> ) {
339+
const pSequence = toArray( prefix );
340+
return pSequence.length
341+
? this.root.getChildPrefixEnd( pSequence )
342+
: this.root;
343+
}
338344
private _getAllStartingWith( prefix : Array<T>, completeSequencesOnly ) {
339-
const suffixStartNode = this.root.getChildPrefixEnd( prefix );
340-
if( !suffixStartNode ) { return [] }
345+
const suffixStartNode = this._getNodeAtPrefixEnd( prefix );
346+
if( !suffixStartNode || this.root === suffixStartNode ) { return [] }
341347
const sequences = suffixStartNode.asArray( completeSequencesOnly );
342348
for( let s = sequences.length; s--; ) {
343349
sequences[ s ] = prefix.concat( sequences[ s ] );

0 commit comments

Comments
 (0)