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

cspell-trie-lib

Package Overview
Dependencies
Maintainers
1
Versions
295
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cspell-trie-lib - npm Package Compare versions

Comparing version 4.1.5 to 4.1.6

dist/lib/convertToTrieRefNodes.d.ts

2

dist/lib/consolidate.d.ts

@@ -6,2 +6,2 @@ import { TrieNode } from './TrieNode';

*/
export declare function consolidate(root: TrieNode, iterations?: number): TrieNode;
export declare function consolidate(root: TrieNode): TrieNode;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const TrieNode_1 = require("./TrieNode");
/**

@@ -7,3 +8,3 @@ * Consolidate to DAWG

*/
function consolidate(root, iterations = 5) {
function consolidate(root) {
let count = 0;

@@ -20,12 +21,25 @@ const signatures = new Map();

}
function canCache(n) {
if (!n.c)
return true;
for (const v of n.c) {
if (!cached.has(v[1]))
function findEow(n) {
if (n.f && !n.c)
return n;
let r;
// istanbul ignore else
if (n.c) {
for (const c of n.c.values()) {
r = findEow(c);
// istanbul ignore else
if (r)
break;
}
}
return r;
}
function compareMaps(a, b) {
for (const e of a) {
if (b.get(e[0]) !== e[1])
return false;
}
return true;
return a.length === b.size;
}
function deepConvert(n) {
function deepCopy(n) {
if (knownMap.has(n)) {

@@ -35,6 +49,7 @@ return knownMap.get(n);

const orig = n;
n = Object.isFrozen(n) ? Object.assign(Object.assign({}, n), { c: n.c && new Map(n.c) }) : n;
if (n.c) {
const children = [...n.c].sort((a, b) => a[0] < b[0] ? -1 : 1);
n.c = new Map(children.map(c => [c[0], deepConvert(c[1])]));
const children = [...n.c].map(c => [c[0], deepCopy(c[1])]);
if (!compareMaps(children, n.c)) {
n = { f: n.f, c: new Map(children) };
}
}

@@ -45,5 +60,2 @@ const sig = signature(n);

knownMap.set(orig, ref);
if (!cached.has(ref)) {
cached.set(ref, count++);
}
return ref;

@@ -57,3 +69,3 @@ }

}
function convert(n) {
function process(n) {
if (cached.has(n)) {

@@ -63,32 +75,22 @@ return n;

if (Object.isFrozen(n)) {
return knownMap.get(n) || deepConvert(n);
return knownMap.get(n) || deepCopy(n);
}
if (n.c) {
const children = [...n.c].sort((a, b) => a[0] < b[0] ? -1 : 1);
n.c = new Map(children.map(c => [c[0], convert(c[1])]));
const children = [...n.c].sort((a, b) => a[0] < b[0] ? -1 : 1).map(c => [c[0], process(c[1])]);
n.c = new Map(children);
}
if (!canCache(n)) {
return n;
}
const sig = signature(n);
const ref = signatures.get(sig);
if (ref) {
if (!cached.has(ref)) {
cached.set(ref, count++);
}
return ref;
}
signatures.set(sig, n);
cached.set(n, count++);
return n;
}
// Add end of word to the set of signatures and cache it.
const eow = { f: 1 };
const eow = findEow(root) || { f: TrieNode_1.FLAG_WORD, c: undefined };
signatures.set(signature(eow), eow);
cached.set(eow, count++);
for (let i = 0; i < iterations; ++i) {
const n = cached.size;
root = convert(root);
if (n === cached.size)
break;
}
root = process(root);
return root;

@@ -95,0 +97,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const TrieNode_1 = require("./TrieNode");
const flatten_1 = require("./flatten");
const gensequence_1 = require("gensequence");
const convertToTrieRefNodes_1 = require("./convertToTrieRefNodes");
const EOW = '*';
exports.DATA = EOW;
function flattenToReferences(node) {
return gensequence_1.genSequence(flatten_1.flattenToTrieRefNodeIterable(node));
function toReferences(node) {
return gensequence_1.genSequence(convertToTrieRefNodes_1.convertToTrieRefNodes(node));
}

@@ -57,3 +57,3 @@ const regExpEscapeChars = /([\[\]\\,:{}*])/;

const radix = base > 36 ? 36 : base < 10 ? 10 : base;
const rows = flattenToReferences(root)
const rows = toReferences(root)
.map(node => {

@@ -60,0 +60,0 @@ const row = [

{
"name": "cspell-trie-lib",
"version": "4.1.5",
"version": "4.1.6",
"description": "Trie Data Structure to support cspell.",

@@ -59,3 +59,3 @@ "main": "dist/index.js",

},
"gitHead": "9682c2d23fabc9e823cbd5d610fe590feac78ac2"
"gitHead": "d3d97247b35d1c755ae6dc95cc72e4b8381b68f6"
}
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