Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ isEmpty: boolean
```tsx
size: number
```
## Methods

## Methods (Scope: Public)

### add
<p>Accepts a sequence of items to merge into this instance.</p>

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

## Methods (Scope: Protected)

### _getNodeAtPrefixEnd
<p>Produces the underlying node containing the final value in <code>prefix</code> items.</p>
<p>Will produce the root node for the empty <code>prefix</code> items.</p>

```tsx
_getNodeAtPrefixEnd( prefix: Iterable<T> ): Node<T>
```
## Static

### makeTrieable
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@
"test:watch": "jest --updateSnapshot --watchAll"
},
"types": "dist/index.d.ts",
"version": "0.5.1"
"version": "0.5.2"
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export type {
EqualityFn,
KeyType,
Node,
Options,
OpStatus,
Status,
TrieableNode,
TrieableNodeKeyMapping
} from './main';

export { default as default } from './main';
10 changes: 8 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,15 @@ export default class Trie<T = unknown> {
}
return results;
}
protected _getNodeAtPrefixEnd( prefix : Iterable<T> ) {
const pSequence = toArray( prefix );
return pSequence.length
? this.root.getChildPrefixEnd( pSequence )
: this.root;
}
private _getAllStartingWith( prefix : Array<T>, completeSequencesOnly ) {
const suffixStartNode = this.root.getChildPrefixEnd( prefix );
if( !suffixStartNode ) { return [] }
const suffixStartNode = this._getNodeAtPrefixEnd( prefix );
if( !suffixStartNode || this.root === suffixStartNode ) { return [] }
const sequences = suffixStartNode.asArray( completeSequencesOnly );
for( let s = sequences.length; s--; ) {
sequences[ s ] = prefix.concat( sequences[ s ] );
Expand Down