Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 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
cb35809
Suffix Array
thsubaku9 Nov 25, 2020
b7ed118
Suffix shift bug
thsubaku9 Nov 25, 2020
8164511
lcp and suffix array
thsubaku9 Nov 27, 2020
9f65756
Suffix and LCP Array
thsubaku9 Nov 28, 2020
3b0211b
Merge branch 'main' into work-branch
thsubaku9 Nov 28, 2020
a839750
minor update
thsubaku9 Nov 29, 2020
9f52561
Merge branch 'main' into work-branch
thsubaku9 Nov 29, 2020
62f71fd
BWT
thsubaku9 Nov 29, 2020
f8cb891
Merge branch 'main' into work-branch
thsubaku9 Nov 29, 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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ List of supported Data Structures and Algorithms are :
- [Aho Corasick](https://github.com/thsubaku9/string-dsa/blob/main/src/search/AhoCorasick.js)
- [Bloom Filter](https://github.com/thsubaku9/string-dsa/blob/main/src/BloomFilter.js)
- [Bracket Balance](https://github.com/thsubaku9/string-dsa/blob/main/src/bracketBalance.js)
- [Burrows Wheeler Transform](https://github.com/thsubaku9/string-dsa/blob/main/src/suffix/BWT.js)
- [Burst Sort](https://github.com/thsubaku9/string-dsa/blob/main/src/sort/burstSort.js)
- [Custom Sort](https://github.com/thsubaku9/string-dsa/blob/main/src/sort/stringSort.js)
- [Dice Coefficient](https://github.com/thsubaku9/string-dsa/blob/main/src/dice_coeff.js)
Expand Down Expand Up @@ -68,4 +69,4 @@ $ npm run coverage

## License

[ISC](https://github.com/thsubaku9/string-dsa/blob/main/LICENSE)
[GNU General Public License v3.0](https://github.com/thsubaku9/string-dsa/blob/main/LICENSE)
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "string-dsa",
"version": "1.5.1",
"version": "2.0.0",
"description": "String Data Structures and Algorithms Library in JavaScript",
"main": "src/index.js",
"files": [
Expand All @@ -23,6 +23,7 @@
"String Data Structures",
"Aho Corasick",
"Bloom Filter",
"Burrows Wheeler Transform",
"Custom Sort",
"Levenshtein Distance",
"Suffix Array",
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ const editDist = require('./edit_distance');
const lcs = require('./lcs');
const { AhoCorasick, kmp, rabinKarp } = require('./search');
const { burstSort, customSort, sorted } = require('./sort');
const { Suffix } = require('./suffix');
const { BWT, Suffix } = require('./suffix');
const Trie = require('./Trie');

module.exports = {
AhoCorasick,
BloomFilter,
bracketBalance,
burstSort,
BWT,
customSort,
diceCoeff,
editDist,
Expand Down
50 changes: 50 additions & 0 deletions src/suffix/BWT.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const { sort } = require("../sort/stringSort");
const Suffix = require("./SuffixMain");

/**
* Burrows Wheeler Transformation
*
* @param {String} text the string that you wish to find BWT of
*
* @returns {String} the respective BWT of the string
*/
function transform(text) {
let mySfx = new Suffix(text);
let bwt_t = "";

let res = mySfx.suffixArray();

for (let i = 0; i < res.length; i++) {
bwt_t += mySfx.originalString[(res[i] + res.length - 1) % res.length];
}

return bwt_t;
}

/**
* inverse Burrows Wheeler Transformation
*
* @param {String} bwt_t the BWT representation of the string
*
* @returns {String} the original string
*/
function inverse_transform(bwt_t) {
let index_sort = sort(bwt_t.split(""), true);
let inverse_index_pos = new Array(bwt_t.length);
for (let i = 0; i < bwt_t.length; i++) inverse_index_pos[index_sort[i]] = i;

let start_pos = index_sort[0]; let end_pos = 0;
let text = bwt_t[start_pos];

while (end_pos != index_sort[0]) {
text = bwt_t[end_pos] + text;
start_pos = end_pos;
end_pos = inverse_index_pos[end_pos];
}
return text;
}

module.exports = {
transform,
inverse_transform,
};
2 changes: 1 addition & 1 deletion src/suffix/SuffixMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class SuffixMain {
}

/**
* This function computes the suffixArray of the given string in linear time
* This function computes the suffixArray of the given string
*
* @returns {Array} indexed based suffix array
*/
Expand Down
2 changes: 2 additions & 0 deletions src/suffix/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const Suffix = require("./SuffixMain");
const BWT = require("./BWT");

module.exports = {
BWT,
Suffix,
};
23 changes: 23 additions & 0 deletions test/suffix/test_BWT.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const assert = require("assert");
const BWT = require("../../src").BWT
describe("BWT tests", () =>{

const st1 = "candy" , st2 = "banana"
const bwt1 = "yc$nad", bwt2 = "annb$aa"
const inv1 = `${st1}$`, inv2 = `${st2}$`
it("should find the correct BWT", () =>{
const res1 = BWT.transform(st1)
const res2 = BWT.transform(st2)

assert.deepStrictEqual(res1, bwt1);
assert.deepStrictEqual(res2, bwt2);
})

it("should find the correct iBWT", () =>{
const res1 = BWT.inverse_transform(bwt1)
const res2 = BWT.inverse_transform(bwt2)

assert.deepStrictEqual(res1,inv1);
assert.deepStrictEqual(res2,inv2);
})
})