Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
5ce9398
Bracket Balance
thsubaku9 Oct 7, 2020
050f089
README update
thsubaku9 Oct 7, 2020
1801f4b
README update
thsubaku9 Oct 7, 2020
96784bd
README update
thsubaku9 Oct 7, 2020
0b0d182
Bloom Filter Update!
thsubaku9 Oct 8, 2020
c1f956d
readme changes
thsubaku9 Oct 8, 2020
cd3a235
Merge branch 'main' into work-branch
thsubaku9 Oct 8, 2020
a6b376d
Merge branch 'main' of https://github.com/thsubaku9/string-dsa into w…
thsubaku9 Oct 8, 2020
8549287
spacing
thsubaku9 Oct 8, 2020
2ada1ad
Custom string sort supported
thsubaku9 Oct 10, 2020
5453837
Custom string sort supported
thsubaku9 Oct 10, 2020
b082d22
Custom string sort supported
thsubaku9 Oct 10, 2020
5eccfad
Custom string sort supported
thsubaku9 Oct 10, 2020
247e354
Merge branch 'main' of https://github.com/thsubaku9/string-dsa into w…
thsubaku9 Oct 10, 2020
10f4b66
sorted implemented
thsubaku9 Oct 16, 2020
a6c301b
webpack config
thsubaku9 Oct 17, 2020
11084bd
Edit Distance and 0.3.0 changes
thsubaku9 Oct 19, 2020
2bd2264
Merge branch 'main' into work-branch
thsubaku9 Oct 19, 2020
db92912
Merge branch 'main' into work-branch
thsubaku9 Oct 28, 2020
c8be77f
temp
thsubaku9 Oct 29, 2020
ac3a413
Trie almost done
thsubaku9 Oct 29, 2020
4c66325
README enhancement
thsubaku9 Oct 29, 2020
55fd012
Trie done
thsubaku9 Oct 30, 2020
0790164
tried and tested
thsubaku9 Oct 30, 2020
6cac38f
Trie enhancements
thsubaku9 Nov 4, 2020
2df3a0a
Merge branch 'main' into work-branch
thsubaku9 Nov 4, 2020
ca54462
LCS supported
thsubaku9 Nov 8, 2020
0bd5276
Merge branch 'main' into work-branch
thsubaku9 Nov 8, 2020
d6f55e7
few minor fixes, started linting work
thsubaku9 Nov 10, 2020
7fb45da
Merge branch 'main' into work-branch
thsubaku9 Nov 10, 2020
48eff45
linting ongoing
thsubaku9 Nov 10, 2020
493c473
Minor updates
thsubaku9 Nov 13, 2020
5fd4fde
Merge branch 'main' into work-branch
thsubaku9 Nov 13, 2020
0590e93
merge modification
thsubaku9 Nov 13, 2020
9cb5508
LF update
thsubaku9 Nov 13, 2020
65d609e
LF update
thsubaku9 Nov 13, 2020
6d416a3
Aho Corasick main files
thsubaku9 Nov 18, 2020
3c41b78
Aho Corasick Polishing
thsubaku9 Nov 18, 2020
24e064c
Merge branch 'main' into work-branch
thsubaku9 Nov 18, 2020
e28e34f
Update index.js
thsubaku9 Nov 18, 2020
f220a70
Update index.js
thsubaku9 Nov 18, 2020
54e567a
main merge
thsubaku9 Nov 18, 2020
553142d
darn mini annotation bugs
thsubaku9 Nov 18, 2020
2811d95
AhoCorasick fix
thsubaku9 Nov 20, 2020
b2dc098
Merge branch 'main' into work-branch
thsubaku9 Nov 20, 2020
e5a6827
Burst Sort support
thsubaku9 Nov 25, 2020
2243125
Merge branch 'main' into work-branch
thsubaku9 Nov 25, 2020
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "string-dsa",
"version": "1.3.2",
"version": "1.4.0",
"description": "String Data Structures and Algorithms Library in JavaScript",
"main": "src/index.js",
"files": [
Expand Down
38 changes: 38 additions & 0 deletions src/Trie.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,44 @@ class Trie {
}
return res;
}

/**
* @returns {String[]} returns the ordered value of keys using BurstSort
*/
burstSort() {
const arr = [];
this._burstSortInternal(this._rootNode, arr, "");
return arr;
}

_burstSortInternal(node, arr, collectorString) {
let c;
if (node.$ === true) arr.push(collectorString);

// Numerics
for (let i = 0; i < 10; i++) {
c = String(0 + i);
if (node[c] !== undefined) {
this._burstSortInternal(node[c], arr, collectorString + c);
}
}

// Upper Case
for (let i = 0; i < 26; i++) {
c = String.fromCharCode(i + "A".charCodeAt(0));
if (node[c] !== undefined) {
this._burstSortInternal(node[c], arr, collectorString + c);
}
}

// Lower Case
for (let i = 0; i < 26; i++) {
c = String.fromCharCode(i + "a".charCodeAt(0));
if (node[c] !== undefined) {
this._burstSortInternal(node[c], arr, collectorString + c);
}
}
}
}

module.exports = Trie;
2 changes: 1 addition & 1 deletion src/edit_distance.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function editDistance(string1, string2) {
if (string1.charAt(i - 1) === string2.charAt(j - 1)) {
editDistanceMatrix[i][j] = editDistanceMatrix[i - 1][j - 1];
} else {
editDistanceMatrix[i][j] = min(min(editDistanceMatrix[i - 1][j - 1], editDistanceMatrix[i][j - 1]), min(editDistanceMatrix[i][j - 1], editDistanceMatrix[i - 1][j])) + 1;
editDistanceMatrix[i][j] = min(editDistanceMatrix[i - 1][j - 1], min(editDistanceMatrix[i][j - 1], editDistanceMatrix[i - 1][j])) + 1;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function lcs(string1, string2) {
if (string1[i1 - 1] == string2[i2 - 1]) {
matchMatrix[i1][i2] = matchMatrix[i1 - 1][i2 - 1] + 1;
} else {
matchMatrix[i1][i2] = max(max(matchMatrix[i1 - 1][i2 - 1], matchMatrix[i1 - 1][i2]), max(matchMatrix[i1 - 1][i2 - 1], matchMatrix[i1][i2 - 1]));
matchMatrix[i1][i2] = max(max(matchMatrix[i1][i2 - 1], matchMatrix[i1 - 1][i2]), matchMatrix[i1 - 1][i2 - 1]);
}
}
}
Expand Down
100 changes: 100 additions & 0 deletions src/suffix/SuffixMain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
"use strict";

// const Suffix = require("./src/suffix").Suffixer
// mySfx = new Suffix("marijuana")

class Suffixer {
constructor(mainString) {
this.CHAR_LIM = 27;
this.originalString = `${mainString.toLowerCase()}$`;

this.order = new Array(this.originalString.length);
this.class = new Array(this.originalString.length);
this.lcpArray = new Array(this.originalString.length);
this.suffixConstructed = false;
}

charOrder() {
let charCount = new Array(this.CHAR_LIM);
for (let i = 0; i < this.CHAR_LIM; i++) charCount[i] = 0;

for (let i = 0; i < this.originalString.length; i++) {
if (this.originalString.charAt(i) === "$") {
charCount[0] += 1;
} else {
charCount[this.originalString.charCodeAt(i) - "a".charCodeAt(0) + 1] += 1;
}
}

for (let i = 1; i < this.CHAR_LIM; i++) {
charCount[i] += charCount[i - 1];
}

for (let i = this.originalString.length - 1; i >= 0; i--) {
let c;
if (this.originalString.charAt(i) === "$") {
c = 0;
} else {
c = this.originalString.charCodeAt(i) - "a".charCodeAt(0) + 1;
}
charCount[c] -= 1;
this.order[charCount[c]] = i;
}
}

charClass() {
let pos = 0; let
classNumber = 0;
this.class[this.order[pos]] = classNumber;
pos++;
while (pos < this.originalString.length) {
if (this.originalString.charAt(this.order[pos - 1]) !== this.originalString.charAt(this.order[pos])) {
classNumber += 1;
}
this.class[this.order[pos]] = classNumber;
pos++;
}
}

/*
sortDouble(L) {
let newOrder = new Array(this.originalString.length);

return newOrder;
}

updateClass(L) {
let newClass = new Array(this.originalString.length);

return newClass;
}
*/

suffixArray() {
if (this.suffixConstructed) return this.order;

let L = 1;
this.charOrder();
this.charClass();
while (L < this.originalString.length) {
// this.order = this.sortDouble(L);
// this.class = this.updateClass(L);
L *= 2;
}

this.suffixConstructed = true;
return this.order;
}

/*
lcpArray(){
if(!this.suffixConstructed) this.suffixArray()

for (let i=0; i< this.originalString.length; i++) this.lcpArray[i] = 0

// Do LCP stuff
}
*/
}

module.exports = Suffixer;
5 changes: 5 additions & 0 deletions src/suffix/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const Suffixer = require("./SuffixMain");

module.exports = {
Suffixer,
};
7 changes: 7 additions & 0 deletions test/test_Trie.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ describe("Trie based tests", () => {
const searchSpace = "can the real candy ban?";
const resultPos = [[0, 2], [13, 15], [13, 17], [19, 21]];
const existResult = [true, true, true, false];
const orderedKeys = [st3,st1,st2];

it("should insert a bunch of keys", () => {
myT.insertList([st1, st2, st3]);
assert.deepStrictEqual(myT.listAllElements(), [st1, st2, st3]);
Expand All @@ -30,4 +32,9 @@ describe("Trie based tests", () => {
const res = myT.containsList([st1, st2, st3, na1]);
assert.deepStrictEqual(res, existResult);
});

it("should perform burstsort properly",() =>{
const res = myT.burstSort();
assert.deepStrictEqual(res,orderedKeys);
});
});