-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f71673f
commit 5670613
Showing
5 changed files
with
130 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es2021": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"indent": [ | ||
"error", | ||
"tab" | ||
], | ||
"linebreak-style": [ | ||
"error", | ||
"unix" | ||
], | ||
"quotes": [ | ||
"error", | ||
"single" | ||
], | ||
"semi": [ | ||
"error", | ||
"always" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Helper class for visited vertex metadata. | ||
*/ | ||
export default class VisitMetadata { | ||
constructor({ discoveryTime, lowDiscoveryTime }) { | ||
this.discoveryTime = discoveryTime; | ||
this.lowDiscoveryTime = lowDiscoveryTime; | ||
// We need this in order to check graph root node, whether it has two | ||
// disconnected children or not. | ||
this.independentChildrenCount = 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,103 @@ | ||
import _ from 'lodash'; | ||
import Iter from 'es-iter'; | ||
|
||
export const getAllIndexes = (arr, val) => { | ||
var indexes = [], i; | ||
|
||
for(i = 0; i < arr.length; i++) | ||
if (arr[i] === val) | ||
const indexes = []; | ||
let i; | ||
|
||
for (i = 0; i < arr.length; i++) { | ||
if (arr[i] === val) { | ||
indexes.push(i); | ||
|
||
} | ||
} | ||
|
||
return indexes; | ||
} | ||
}; | ||
|
||
export const cyclicSort = (array, index) => { | ||
if(array.length < index){ | ||
console.error('Error: Provided index '+index+' greater than array length '+array.length); | ||
if (array.length < index) { | ||
const category = 'Error'; | ||
const subject = 'Provided index '+index; | ||
const condition = 'greater than array length '+array.length; | ||
|
||
console.error(category+' : '+subject+' '+condition); | ||
} | ||
let head = array.slice(index); | ||
let tail = array.slice(0, index); | ||
|
||
const head = array.slice(index); | ||
const tail = array.slice(0, index); | ||
|
||
return head.concat(tail); | ||
} | ||
}; | ||
|
||
export const isCyclicEqual = (control_, treatment_) => { | ||
let control_len = control_.length; | ||
let treatment_len = treatment_.length; | ||
|
||
if(control_len != treatment_len){ | ||
if (control_.length != treatment_.length) { | ||
return false; | ||
} | ||
|
||
for(let i=0; i<treatment_len; i++){ | ||
if(cyclicSort(treatment_, i) == control_){ | ||
return true | ||
for (let i=0; i<treatment_.length; i++) { | ||
if (cyclicSort(treatment_, i) == control_) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
}; | ||
|
||
export const getUniques = (vec) => { | ||
return Array.from(new Set(vec)); | ||
} | ||
}; | ||
|
||
export const extendedVenn = (sets) => { | ||
const keys = Object.keys(sets); | ||
const extended_venn = {}; | ||
let comb_sets_inter = {}; | ||
let comb_sets_union = {}; | ||
let comb_sets_excl = {}; | ||
|
||
for (const i of _.rangeRight(1, keys.length+1)) { | ||
for (const comb_keys of new Iter(keys).combinations(i)) { | ||
const comb_sets = comb_keys.map((key) => sets[key]); | ||
|
||
// Intersection of elements | ||
comb_sets_inter = Object | ||
.values(comb_sets) | ||
.reduce((acc, arr) => arr.filter(Set.prototype.has, | ||
new Set(acc))); | ||
|
||
// No intersection means no exclusive value | ||
if (comb_sets_inter.length==0) { | ||
break; | ||
} | ||
|
||
const ev_keys_i_to_n = []; | ||
Object | ||
.keys(extended_venn) | ||
.forEach( | ||
(key) => { | ||
if (key.split(',').length >= i) { | ||
ev_keys_i_to_n.push(key); | ||
}; | ||
}, | ||
); | ||
|
||
// Intersection of elements | ||
comb_sets_union = ev_keys_i_to_n.length==0 ? [] : | ||
ev_keys_i_to_n.reduce( | ||
(acc, key) => [ | ||
...new Set( | ||
[ | ||
...acc, | ||
...extended_venn[key], | ||
])], []); | ||
|
||
// Exclusive combination set elements | ||
comb_sets_excl = _.difference(comb_sets_inter, comb_sets_union); | ||
|
||
if (comb_sets_inter.length!=0) { | ||
extended_venn[comb_keys.toString()] = comb_sets_excl; | ||
} | ||
} | ||
} | ||
|
||
return extended_venn; | ||
}; |