romanize-string
Version:
A fully typed, general-purpose utility for unidirectional string transliteration (non-Latin script => Latin script).
76 lines (75 loc) • 1.88 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IntervalTreeNode = exports.IntervalTree = void 0;
class IntervalTree {
root;
constructor(start, end, value) {
this.root =
start && end && value ? new IntervalTreeNode(start, end, value) : null;
}
insert(start, end, value) {
const node = new IntervalTreeNode(start, end, value);
if (this.root === null) {
this.root = node;
return node;
}
this.root.insert(node);
return node;
}
search(num) {
if (this.root === null) {
return [];
}
return this.root.search(num);
}
exists(num) {
return this.search(num).length > 0;
}
}
exports.IntervalTree = IntervalTree;
class IntervalTreeNode {
start;
end;
value;
left;
right;
constructor(start, end, value) {
this.start = start;
this.end = end;
this.value = value;
this.left = null;
this.right = null;
}
insert(node) {
if (node.start < this.start) {
if (this.left === null) {
this.left = node;
}
else {
this.left.insert(node);
}
}
else {
if (this.right === null) {
this.right = node;
}
else {
this.right.insert(node);
}
}
}
search(num) {
const result = [];
if (this.left !== null) {
result.push(...this.left.search(num));
}
if (this.start <= num && num <= this.end) {
result.push(this);
}
if (this.right !== null) {
result.push(...this.right.search(num));
}
return result;
}
}
exports.IntervalTreeNode = IntervalTreeNode;