Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@datastructures-js/trie

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@datastructures-js/trie - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

8

index.js

@@ -102,5 +102,4 @@ /**

let nodesCount = 1;
let wordsCount = 1;
let wordsCount = 0;
let rootNode = node('');
rootNode.setEndOfWord(true);

@@ -208,6 +207,5 @@ /**

const clear = () => {
rootNode = node(''); // empty word
rootNode.setEndOfWord(true);
nodesCount = 1;
wordsCount = 1;
wordsCount = 0;
rootNode = node('');
};

@@ -214,0 +212,0 @@

@@ -28,7 +28,6 @@ const { expect } = require('chai');

it('should get the count of words', () =>
expect(trie.countWords()).to.equal(9)));
expect(trie.countWords()).to.equal(8)));
describe('.search(word)', () =>
it('should find the inserted words into the trie', () => {
expect(trie.search('')).to.not.equal(null);
expect(trie.search('hi')).to.not.equal(null);

@@ -56,5 +55,4 @@ expect(trie.search('hello')).to.not.equal(null);

trie.traverse(word => words.push(word));
expect(words).to.have.lengthOf(9)
expect(words).to.have.lengthOf(8)
.and.to.have.members([
'',
'hi',

@@ -76,3 +74,3 @@ 'hit',

expect(trie.countNodes()).to.equal(22);
expect(trie.countWords()).to.equal(8);
expect(trie.countWords()).to.equal(7);

@@ -82,3 +80,3 @@ trie.remove('hi');

expect(trie.countNodes()).to.equal(22);
expect(trie.countWords()).to.equal(7);
expect(trie.countWords()).to.equal(6);

@@ -88,3 +86,3 @@ trie.remove('hide');

expect(trie.countNodes()).to.equal(19);
expect(trie.countWords()).to.equal(6);
expect(trie.countWords()).to.equal(5);

@@ -94,3 +92,3 @@ trie.remove('hello');

expect(trie.countNodes()).to.equal(14);
expect(trie.countWords()).to.equal(5);
expect(trie.countWords()).to.equal(4);

@@ -100,3 +98,3 @@ trie.remove('safe');

expect(trie.countNodes()).to.equal(12);
expect(trie.countWords()).to.equal(4);
expect(trie.countWords()).to.equal(3);

@@ -106,3 +104,3 @@ trie.remove('sand');

expect(trie.countNodes()).to.equal(8);
expect(trie.countWords()).to.equal(3);
expect(trie.countWords()).to.equal(2);

@@ -112,3 +110,3 @@ trie.remove('noun');

expect(trie.countNodes()).to.equal(5);
expect(trie.countWords()).to.equal(2);
expect(trie.countWords()).to.equal(1);

@@ -118,8 +116,8 @@ trie.remove('name');

expect(trie.countNodes()).to.equal(1);
expect(trie.countWords()).to.equal(1);
expect(trie.countWords()).to.equal(0);
trie.remove(''); // should not remove empty word.
expect(trie.search('')).to.not.equal(null);
expect(trie.search('')).to.equal(null);
expect(trie.countNodes()).to.equal(1);
expect(trie.countWords()).to.equal(1);
expect(trie.countWords()).to.equal(0);

@@ -136,4 +134,4 @@ expect(() => trie.remove()).to.throw(Error)

expect(trie.countNodes()).to.equal(1);
expect(trie.countWords()).to.equal(1);
expect(trie.countWords()).to.equal(0);
}));
});
{
"name": "@datastructures-js/trie",
"version": "1.0.1",
"version": "1.0.2",
"description": "trie implementation in javascript",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -16,3 +16,3 @@ # @datastrucures-js/trie

// by default, the trie has 1 node, the root, which also forms 1 default word, the empty string.
// by default, the trie has 1 node, the root node.
```

@@ -37,3 +37,3 @@

```javascript
```js
const n = trie.node('T');

@@ -49,3 +49,3 @@ console.log(n.getChar()); // T

```javascript
```js
try {

@@ -70,3 +70,3 @@ trie.insert('hi');

```javascript
```js
try {

@@ -87,5 +87,4 @@ const n1 = trie.search('hi');

```javascript
```js
trie.traverse(console.log);
//
// hi

@@ -105,3 +104,3 @@ // hit

```javascript
```js
try {

@@ -120,3 +119,3 @@ trie.remove('hit');

```javascript
```js
console.log(trie.countNodes()); // 22

@@ -129,4 +128,4 @@ ```

```javascript
console.log(trie.countWords()); // 8
```js
console.log(trie.countWords()); // 7
```

@@ -138,6 +137,6 @@

```javascript
```js
trie.clear();
console.log(trie.countNodes()); // 1 (root default node)
console.log(trie.countWords()); // 1 (empty string default word)
console.log(trie.countWords()); // 0
```

@@ -144,0 +143,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc