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

astl

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

astl - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

internal/tree/MultiIteratorTree.ts

14

algorithm/sorting.ts

@@ -19,3 +19,3 @@ import { Vector } from "../container/Vector";

{
const length: usize = distance(first, last);
const length: isize = distance(first, last);
if (length <= 0)

@@ -30,4 +30,4 @@ return;

let i: usize = 1;
for (let j: usize = 1; j < length; ++j)
let i: isize = 1;
for (let j: isize = 1; j < length; ++j)
{

@@ -63,4 +63,4 @@ const jeIt: RandomAccessIterator = first.advance(j);

let i: usize = 1;
for (let j: usize = 1; j < length; ++j)
let i: isize = 1;
for (let j: isize = 1; j < length; ++j)
{

@@ -76,4 +76,4 @@ const jeIt: RandomAccessIterator = first.advance(j);

sort<RandomAccessIterator, Comparator>(first, first.advance(i - 1), comp);
sort<RandomAccessIterator, Comparator>(first.advance(i), last, comp);
stable_sort<RandomAccessIterator, Comparator>(first, first.advance(i - 1), comp);
stable_sort<RandomAccessIterator, Comparator>(first.advance(i), last, comp);
}

@@ -80,0 +80,0 @@

@@ -31,2 +31,19 @@ import { Vector } from "./Vector";

@inline()
public assign_range<InputIterator extends IForwardIterator<T, InputIterator>>
(first: InputIterator, last: InputIterator): void
{
if (this.empty() === false)
this.clear();
this.insert_range<InputIterator>(this.end(), first, last);
}
@inline()
public assign_repeatedly(length: usize, value: T): void
{
if (this.empty() === false)
this.clear();
this.insert_repeatedly(this.end(), length, value);
}
public clear(): void

@@ -33,0 +50,0 @@ {

import { IForwardIterator } from "../iterator/IForwardIterator";
import { DomainError } from "../exception/DomainError";
import { CMath } from "../internal/numeric/CMath";
import { Repeater } from "../internal/iterator/disposable/Repeater";

@@ -12,7 +14,34 @@ import { SourcePointer } from "../internal/functional/SourcePointer";

private end_: ForwardList.Iterator<T> = ForwardList.Iterator._Create(this.source_ptr_, null);
private before_begin_: ForwardList.Iterator<T> = ForwardList.Iterator._Create(this.source_ptr_, this.end_);
private end_: ForwardList.Iterator<T> = ForwardList.Iterator._Create(this.source_ptr_, null, changetype<T>(0));
private before_begin_: ForwardList.Iterator<T> = ForwardList.Iterator._Create(this.source_ptr_, this.end_, changetype<T>(0));
private size_: usize = 0;
/* ---------------------------------------------------------
CONSTRUCTORS
--------------------------------------------------------- */
@inline()
public assign_range<InputIterator extends IForwardIterator<T, InputIterator>>
(first: InputIterator, last: InputIterator): void
{
if (this.empty() === false)
this.clear();
this.insert_after_range<InputIterator>(this.before_begin_, first, last);
}
@inline()
public assign_repeatedly(length: usize, value: T): void
{
if (this.empty() === false)
this.clear();
this.insert_after_repeatedly(this.before_begin_, length, value);
}
@inline()
public clear(): void
{
ForwardList.Iterator._Set_next(this.before_begin_, this.end_);
this.size_ = 0;
}
/* ---------------------------------------------------------
ACCESSORS

@@ -67,3 +96,3 @@ --------------------------------------------------------- */

{
this.insert_after(this.before_begin(), val);
this.insert_after(this.before_begin_, val);
}

@@ -73,4 +102,3 @@

{
const it: ForwardList.Iterator<T> = ForwardList.Iterator._Create(this.source_ptr_, pos.next());
it.value = val;
const it: ForwardList.Iterator<T> = ForwardList.Iterator._Create(this.source_ptr_, pos.next(), val);
ForwardList.Iterator._Set_next<T>(pos, it);

@@ -82,2 +110,3 @@

@inline()
public insert_after_repeatedly(pos: ForwardList.Iterator<T>, n: usize, val: T): ForwardList.Iterator<T>

@@ -108,5 +137,5 @@ {

public erase_after(first: ForwardList.Iterator<T>, last: ForwardList.Iterator<T> = first.next()): ForwardList.Iterator<T>
public erase_after(first: ForwardList.Iterator<T>, last: ForwardList.Iterator<T> = first.next().next()): ForwardList.Iterator<T>
{
this.size_ -= distance(first, last);
this.size_ -= CMath.max<isize>(0, distance(first, last) - 1);
ForwardList.Iterator._Set_next<T>(first, last);

@@ -157,15 +186,13 @@

--------------------------------------------------------------- */
private constructor(sourcePtr: SourcePointer<ForwardList<T>>, next: Iterator<T> | null)
private constructor(sourcePtr: SourcePointer<ForwardList<T>>, next: Iterator<T> | null, value: T)
{
this.source_ptr_ = sourcePtr;
this.next_ = next;
if (isNullable<T>() === true)
this.value_ = null!;
this.value_ = value;
}
@inline()
public static _Create<T>(sourcePtr: SourcePointer<ForwardList<T>>, next: Iterator<T> | null): ForwardList.Iterator<T>
public static _Create<T>(sourcePtr: SourcePointer<ForwardList<T>>, next: Iterator<T> | null, value: T): ForwardList.Iterator<T>
{
return new Iterator(sourcePtr, next);
return new Iterator(sourcePtr, next, value);
}

@@ -172,0 +199,0 @@

@@ -27,2 +27,11 @@ import { MapElementList } from "../internal/container/associative/MapElementList";

}
@inline()
public assign<InputIterator extends IForwardIterator<IPair<Key, T>, InputIterator>>
(first: InputIterator, last: InputIterator): void
{
if (this.empty() === false)
this.clear();
this.insert_range<InputIterator>(first, last);
}

@@ -29,0 +38,0 @@ @inline()

@@ -28,2 +28,11 @@ import { MapElementList } from "../internal/container/associative/MapElementList";

@inline()
public assign<InputIterator extends IForwardIterator<IPair<Key, T>, InputIterator>>
(first: InputIterator, last: InputIterator): void
{
if (this.empty() === false)
this.clear();
this.insert_range<InputIterator>(first, last);
}
@inline()
public clear(): void

@@ -30,0 +39,0 @@ {

@@ -26,2 +26,11 @@ import { SetElementList } from "../internal/container/associative/SetElementList";

@inline()
public assign<InputIterator extends IForwardIterator<Key, InputIterator>>
(first: InputIterator, last: InputIterator): void
{
if (this.empty() === false)
this.clear();
this.insert_range<InputIterator>(first, last);
}
@inline()
public clear(): void

@@ -28,0 +37,0 @@ {

@@ -24,2 +24,11 @@ import { SetElementList } from "../internal/container/associative/SetElementList";

}
@inline()
public assign<InputIterator extends IForwardIterator<Key, InputIterator>>
(first: InputIterator, last: InputIterator): void
{
if (this.empty() === false)
this.clear();
this.insert_range<InputIterator>(first, last);
}

@@ -26,0 +35,0 @@ @inline()

export * from "./Deque";
// export * from "./ForwardList";
export * from "./ForwardList";
export * from "./HashMap";

@@ -4,0 +4,0 @@ export * from "./HashMultiMap";

@@ -24,2 +24,19 @@ import { IForwardIterator } from "../iterator/IForwardIterator";

--------------------------------------------------------- */
@inline()
public assign_range<InputIterator extends IForwardIterator<T, InputIterator>>
(first: InputIterator, last: InputIterator): void
{
if (this.empty() === false)
this.clear();
this.insert_range<InputIterator>(this.end(), first, last);
}
@inline()
public assign_repeatedly(length: usize, value: T): void
{
if (this.empty() === false)
this.clear();
this.insert_repeatedly(this.end(), length, value);
}
public clear(): void

@@ -26,0 +43,0 @@ {

import { MapElementList } from "../internal/container/associative/MapElementList";
import { IteratorTree } from "../internal/tree/IteratorTree";
import { XTree } from "../internal/tree/XTree";
import { XTreeNode } from "../internal/tree/XTreeNode";

@@ -8,5 +9,5 @@ import { IForwardIterator } from "../iterator/IForwardIterator";

import { Entry } from "../utility/Entry";
import { ErrorGenerator } from "../internal/exception/ErrorGenerator";
import { Comparator } from "../internal/functional/Comparator";
import { ErrorGenerator } from "../internal/exception/ErrorGenerator";
import { less } from "../functional/comparators";

@@ -17,3 +18,3 @@

private data_: MapElementList<Key, T, true, TreeMap<Key, T>> = new MapElementList(<TreeMap<Key, T>>this);
private tree_: IteratorTree<Key, TreeMap.Iterator<Key, T>>;
public tree_: XTree<Key, TreeMap.Iterator<Key, T>>;

@@ -25,6 +26,15 @@ /* ---------------------------------------------------------

{
this.tree_ = new IteratorTree(it => it.first, comp);
this.tree_ = new XTree(it => it.first, comp);
}
@inline()
public assign<InputIterator extends IForwardIterator<IPair<Key, T>, InputIterator>>
(first: InputIterator, last: InputIterator): void
{
if (this.empty() === false)
this.clear();
this.insert_range<InputIterator>(first, last);
}
@inline()
public clear(): void

@@ -46,3 +56,3 @@ {

// SWAP TREE
const tree: IteratorTree<Key, TreeMap.Iterator<Key, T>> = this.tree_;
const tree: XTree<Key, TreeMap.Iterator<Key, T>> = this.tree_;
this.tree_ = obj.tree_;

@@ -94,4 +104,6 @@ obj.tree_ = tree;

{
const node = this.tree_.find(key);
return (node !== null) ? node.value : this.end();
const node: XTreeNode<TreeMap.Iterator<Key, T>> | null = this.tree_.lower_bound(key);
return (node !== null && this.key_comp()(key, node.value.first) === false)
? node.value
: this.end();
}

@@ -102,3 +114,3 @@

{
return this.tree_.find(key) !== null;
return this.find(key) != this.end();
}

@@ -116,6 +128,6 @@

{
const node = this.tree_.find(key);
if (node === null)
const it: TreeMap.Iterator<Key, T> = this.find(key);
if (it == this.end())
throw ErrorGenerator.key_nout_found("TreeMap.get()", key);
return node.value.second;
return it.second;
}

@@ -132,3 +144,6 @@

{
return this.tree_.lower_bound(this.end(), key);
const node: XTreeNode<TreeMap.Iterator<Key, T>> | null = this.tree_.lower_bound(key);
return (node !== null)
? node.value
: this.end();
}

@@ -139,3 +154,4 @@

{
return this.tree_.upper_bound(this.end(), key);
const lower: TreeMap.Iterator<Key, T> = this.lower_bound(key);
return this._Upper_bound(key, lower);
}

@@ -146,5 +162,16 @@

{
return this.tree_.equal_range(this.end(), key);
const lower: TreeMap.Iterator<Key, T> = this.lower_bound(key);
const upper: TreeMap.Iterator<Key, T> = this._Upper_bound(key, lower);
return new Pair(lower, upper);
}
@inline()
private _Upper_bound(key: Key, lower: TreeMap.Iterator<Key, T>): TreeMap.Iterator<Key, T>
{
if (lower != this.end() && this.key_comp()(key, lower.first) === false)
return lower.next();
else
return lower;
}
/* ---------------------------------------------------------

@@ -175,2 +202,3 @@ ELEMENTS I/O

@inline()
public emplace_hint(hint: TreeMap.Iterator<Key, T>, key: Key, value: T): TreeMap.Iterator<Key, T>

@@ -199,8 +227,8 @@ {

{
const node = this.tree_.find(key);
if (node == null)
const it: TreeMap.Iterator<Key, T> = this.find(key);
if (it == this.end())
return 0;
this.data_.erase(node.value);
this.tree_.erase(node.value);
this.data_.erase(it);
this.tree_.erase(it);
return 1;

@@ -207,0 +235,0 @@ }

import { MapElementList } from "../internal/container/associative/MapElementList";
import { IteratorTree } from "../internal/tree/IteratorTree";
import { MultiIteratorTree } from "../internal/tree/MultiIteratorTree";
import { XTreeNode } from "../internal/tree/XTreeNode";

@@ -15,7 +16,7 @@ import { IForwardIterator } from "../iterator/IForwardIterator";

private data_: MapElementList<Key, T, false, TreeMultiMap<Key, T>> = new MapElementList(<TreeMultiMap<Key, T>>this);
private tree_: IteratorTree<Key, TreeMultiMap.Iterator<Key, T>>;
private tree_: MultiIteratorTree<Key, TreeMultiMap.Iterator<Key, T>>;
public constructor(comp: Comparator<Key> = (x, y) => less(x, y))
{
this.tree_ = new IteratorTree
this.tree_ = new MultiIteratorTree
(

@@ -29,2 +30,11 @@ it => it.first,

@inline()
public assign<InputIterator extends IForwardIterator<IPair<Key, T>, InputIterator>>
(first: InputIterator, last: InputIterator): void
{
if (this.empty() === false)
this.clear();
this.insert_range<InputIterator>(first, last);
}
@inline()
public clear(): void

@@ -46,3 +56,3 @@ {

// SWAP TREE
const tree: IteratorTree<Key, TreeMultiMap.Iterator<Key, T>> = this.tree_;
const tree: MultiIteratorTree<Key, TreeMultiMap.Iterator<Key, T>> = this.tree_;
this.tree_ = obj.tree_;

@@ -94,4 +104,6 @@ obj.tree_ = tree;

{
const node = this.tree_.find(key);
return (node !== null) ? node.value : this.end();
const node: XTreeNode<TreeMultiMap.Iterator<Key, T>> | null = this.tree_.lower_bound(key);
return (node !== null && this.key_comp()(key, node.value.first) === false)
? node.value
: this.end();
}

@@ -102,3 +114,3 @@

{
return this.tree_.find(key) !== null;
return this.find(key) != this.end();
}

@@ -124,3 +136,6 @@

{
return this.tree_.lower_bound(this.end(), key);
const node: XTreeNode<TreeMultiMap.Iterator<Key, T>> | null = this.tree_.lower_bound(key);
return (node !== null)
? node.value
: this.end();
}

@@ -137,3 +152,7 @@

{
return this.tree_.equal_range(this.end(), key);
const lower: TreeMultiMap.Iterator<Key, T> = this.lower_bound(key);
const upper: TreeMultiMap.Iterator<Key, T> = (lower != this.end() && this.key_comp()(key, lower.first) === false)
? this.upper_bound(key)
: lower;
return new Pair(lower, upper);
}

@@ -177,8 +196,8 @@

{
const node = this.tree_.find(key);
if (node == null)
let it: TreeMultiMap.Iterator<Key, T> = this.find(key);
if (it == this.end())
return 0;
let count: usize = 0;
for (let it = node.value; it != this.end() && this.key_comp()(key, it.first) === false;)
while (it != this.end() && this.key_comp()(key, it.first) === false)
{

@@ -185,0 +204,0 @@ it = this.erase(it);

import { SetElementList } from "../internal/container/associative/SetElementList";
import { IteratorTree } from "../internal/tree/IteratorTree";
import { MultiIteratorTree } from "../internal/tree/MultiIteratorTree";
import { XTreeNode } from "../internal/tree/XTreeNode";

@@ -13,7 +14,7 @@ import { IForwardIterator } from "../iterator/IForwardIterator";

private data_: SetElementList<Key, false, TreeMultiSet<Key>> = new SetElementList(<TreeMultiSet<Key>>this);
private tree_: IteratorTree<Key, TreeMultiSet.Iterator<Key>>;
private tree_: MultiIteratorTree<Key, TreeMultiSet.Iterator<Key>>;
public constructor(comp: Comparator<Key> = (x, y) => less(x, y))
{
this.tree_ = new IteratorTree
this.tree_ = new MultiIteratorTree
(

@@ -27,2 +28,11 @@ it => it.value,

@inline()
public assign<InputIterator extends IForwardIterator<Key, InputIterator>>
(first: InputIterator, last: InputIterator): void
{
if (this.empty() === false)
this.clear();
this.insert_range<InputIterator>(first, last);
}
@inline()
public clear(): void

@@ -44,3 +54,3 @@ {

// SWAP TREE
const tree: IteratorTree<Key, TreeMultiSet.Iterator<Key>> = this.tree_;
const tree: MultiIteratorTree<Key, TreeMultiSet.Iterator<Key>> = this.tree_;
this.tree_ = obj.tree_;

@@ -92,4 +102,6 @@ obj.tree_ = tree;

{
const node = this.tree_.find(key);
return (node !== null) ? node.value : this.end();
const node: XTreeNode<TreeMultiSet.Iterator<Key>> | null = this.tree_.lower_bound(key);
return (node !== null && this.key_comp()(key, node.value.value) === false)
? node.value
: this.end();
}

@@ -100,3 +112,3 @@

{
return this.tree_.find(key) !== null;
return this.find(key) != this.end();
}

@@ -122,3 +134,6 @@

{
return this.tree_.lower_bound(this.end(), key);
const node: XTreeNode<TreeMultiSet.Iterator<Key>> | null = this.tree_.lower_bound(key);
return (node !== null)
? node.value
: this.end();
}

@@ -135,3 +150,7 @@

{
return this.tree_.equal_range(this.end(), key);
const lower: TreeMultiSet.Iterator<Key> = this.lower_bound(key);
const upper: TreeMultiSet.Iterator<Key> = (lower != this.end() && this.key_comp()(key, lower.value) === false)
? this.upper_bound(key)
: lower;
return new Pair(lower, upper);
}

@@ -175,8 +194,8 @@

{
const node = this.tree_.find(key);
if (node == null)
let it: TreeMultiSet.Iterator<Key> = this.find(key);
if (it == this.end())
return 0;
let count: usize = 0;
for (let it = node.value; it != this.end() && this.key_comp()(key, it.value) === false; )
while (it != this.end() && this.key_comp()(key, it.value) === false)
{

@@ -183,0 +202,0 @@ it = this.erase(it);

import { SetElementList } from "../internal/container/associative/SetElementList";
import { IteratorTree } from "../internal/tree/IteratorTree";
import { XTree } from "../internal/tree/XTree";
import { XTreeNode } from "../internal/tree/XTreeNode";

@@ -13,3 +14,3 @@ import { IForwardIterator } from "../iterator/IForwardIterator";

private data_: SetElementList<Key, true, TreeSet<Key>> = new SetElementList(<TreeSet<Key>>this);
private tree_: IteratorTree<Key, TreeSet.Iterator<Key>>;
private tree_: XTree<Key, TreeSet.Iterator<Key>>;

@@ -21,6 +22,15 @@ /* ---------------------------------------------------------

{
this.tree_ = new IteratorTree(it => it.value, comp);
this.tree_ = new XTree(it => it.value, comp);
}
@inline()
public assign<InputIterator extends IForwardIterator<Key, InputIterator>>
(first: InputIterator, last: InputIterator): void
{
if (this.empty() === false)
this.clear();
this.insert_range<InputIterator>(first, last);
}
@inline()
public clear(): void

@@ -42,3 +52,3 @@ {

// SWAP TREE
const tree: IteratorTree<Key, TreeSet.Iterator<Key>> = this.tree_;
const tree: XTree<Key, TreeSet.Iterator<Key>> = this.tree_;
this.tree_ = obj.tree_;

@@ -90,4 +100,6 @@ obj.tree_ = tree;

{
const node = this.tree_.find(key);
return (node !== null) ? node.value : this.end();
const node: XTreeNode<TreeSet.Iterator<Key>> | null = this.tree_.lower_bound(key);
return (node !== null && this.key_comp()(key, node.value.value) === false)
? node.value
: this.end();
}

@@ -98,3 +110,3 @@

{
return this.tree_.find(key) !== null;
return this.find(key) != this.end();
}

@@ -117,3 +129,6 @@

{
return this.tree_.lower_bound(this.end(), key);
const node: XTreeNode<TreeSet.Iterator<Key>> | null = this.tree_.lower_bound(key);
return (node !== null)
? node.value
: this.end();
}

@@ -124,3 +139,4 @@

{
return this.tree_.upper_bound(this.end(), key);
const lower: TreeSet.Iterator<Key> = this.lower_bound(key);
return this._Upper_bound(key, lower);
}

@@ -131,5 +147,16 @@

{
return this.tree_.equal_range(this.end(), key);
const lower: TreeSet.Iterator<Key> = this.lower_bound(key);
const upper: TreeSet.Iterator<Key> = this._Upper_bound(key, lower);
return new Pair(lower, upper);
}
@inline()
private _Upper_bound(key: Key, lower: TreeSet.Iterator<Key>): TreeSet.Iterator<Key>
{
if (lower != this.end() && this.key_comp()(key, lower.value) === false)
return lower.next();
else
return lower;
}
/* ---------------------------------------------------------

@@ -150,2 +177,3 @@ ELEMENTS I/O

@inline()
public insert_hint(hint: TreeSet.Iterator<Key>, key: Key): TreeSet.Iterator<Key>

@@ -174,8 +202,8 @@ {

{
const node = this.tree_.find(key);
if (node == null)
const it: TreeSet.Iterator<Key> = this.find(key);
if (it == this.end())
return 0;
this.data_.erase(node.value);
this.tree_.erase(node.value);
this.data_.erase(it);
this.tree_.erase(it);
return 1;

@@ -182,0 +210,0 @@ }

@@ -10,2 +10,22 @@ import { VectorContainer } from "../internal/container/linear/VectorContainer";

/* ---------------------------------------------------------
CONSTRUCTORS
--------------------------------------------------------- */
@inline()
public assign_range<InputIterator extends IForwardIterator<T, InputIterator>>
(first: InputIterator, last: InputIterator): void
{
if (this.empty() === false)
this.clear();
this.insert_range<InputIterator>(this.end(), first, last);
}
@inline()
public assign_repeatedly(length: usize, value: T): void
{
if (this.empty() === false)
this.clear();
this.insert_repeatedly(this.end(), length, value);
}
/* ---------------------------------------------------------
ACCESSORS

@@ -12,0 +32,0 @@ --------------------------------------------------------- */

@@ -14,3 +14,3 @@ import { MapElementVector } from "../../internal/container/associative/MapElementVector";

{
public data_: MapElementVector<Key, T, true, FlatMap<Key, T>> = new MapElementVector(<FlatMap<Key, T>>this);
private data_: MapElementVector<Key, T, true, FlatMap<Key, T>> = new MapElementVector(<FlatMap<Key, T>>this);

@@ -26,2 +26,11 @@ /* ---------------------------------------------------------

@inline()
public assign<InputIterator extends IForwardIterator<IPair<Key, T>, InputIterator>>
(first: InputIterator, last: InputIterator): void
{
if (this.empty() === false)
this.clear();
this.insert_range<InputIterator>(first, last);
}
@inline()
public clear(): void

@@ -166,2 +175,3 @@ {

@inline()
public emplace_hint(hint: FlatMap.Iterator<Key, T>, key: Key, value: T): FlatMap.Iterator<Key, T>

@@ -179,2 +189,3 @@ {

@inline()
public erase(first: FlatMap.Iterator<Key, T>, last: FlatMap.Iterator<Key, T> = first.next()): FlatMap.Iterator<Key, T>

@@ -181,0 +192,0 @@ {

@@ -23,2 +23,11 @@ import { MapElementVector } from "../../internal/container/associative/MapElementVector";

@inline()
public assign<InputIterator extends IForwardIterator<IPair<Key, T>, InputIterator>>
(first: InputIterator, last: InputIterator): void
{
if (this.empty() === false)
this.clear();
this.insert_range<InputIterator>(first, last);
}
@inline()
public clear(): void

@@ -141,2 +150,3 @@ {

@inline()
public emplace_hint(hint: FlatMultiMap.Iterator<Key, T>, key: Key, value: T): FlatMultiMap.Iterator<Key, T>

@@ -154,2 +164,3 @@ {

@inline()
public erase(first: FlatMultiMap.Iterator<Key, T>, last: FlatMultiMap.Iterator<Key, T> = first.next()): FlatMultiMap.Iterator<Key, T>

@@ -156,0 +167,0 @@ {

@@ -21,2 +21,11 @@ import { SetElementVector } from "../../internal/container/associative/SetElementVector";

@inline()
public assign<InputIterator extends IForwardIterator<Key, InputIterator>>
(first: InputIterator, last: InputIterator): void
{
if (this.empty() === false)
this.clear();
this.insert_range<InputIterator>(first, last);
}
@inline()
public clear(): void

@@ -139,2 +148,3 @@ {

@inline()
public insert_hint(hint: FlatMultiSet.Iterator<Key>, key: Key): FlatMultiSet.Iterator<Key>

@@ -152,2 +162,4 @@ {

@inline()
public erase(first: FlatMultiSet.Iterator<Key>, last: FlatMultiSet.Iterator<Key> = first.next()): FlatMultiSet.Iterator<Key>

@@ -154,0 +166,0 @@ {

@@ -22,2 +22,11 @@ import { SetElementVector } from "../../internal/container/associative/SetElementVector";

@inline()
public assign<InputIterator extends IForwardIterator<Key, InputIterator>>
(first: InputIterator, last: InputIterator): void
{
if (this.empty() === false)
this.clear();
this.insert_range<InputIterator>(first, last);
}
@inline()
public clear(): void

@@ -141,2 +150,3 @@ {

@inline()
public insert_hint(hint: FlatSet.Iterator<Key>, key: Key): FlatSet.Iterator<Key>

@@ -154,2 +164,3 @@ {

@inline()
public erase(first: FlatSet.Iterator<Key>, last: FlatSet.Iterator<Key> = first.next()): FlatSet.Iterator<Key>

@@ -156,0 +167,0 @@ {

@@ -9,3 +9,3 @@ import { XTreeNode } from "./XTreeNode";

protected root_: XTreeNode<Elem> | null;
protected unique_: boolean;
private readonly unique_: boolean;

@@ -55,10 +55,4 @@ protected readonly fetcher_: (elem: Elem) => Key;

@inline()
private key_eq_(x: Key, y: Key): boolean
private value_comp_(x: Elem, y: Elem): boolean
{
return !this.key_comp_(x, y) && !this.key_comp_(y, x);
}
public value_comp_(x: Elem, y: Elem): boolean
{
const ret: boolean = this.key_comp_(this.fetcher_(x), this.fetcher_(y));

@@ -74,3 +68,3 @@ if (ret === false &&

@inline()
public value_eq_(x: Elem, y: Elem): boolean
private value_eq_(x: Elem, y: Elem): boolean
{

@@ -88,19 +82,46 @@ return !this.value_comp_(x, y) && !this.value_comp_(y, x);

--------------------------------------------------------- */
public find(key: Key): XTreeNode<Elem> | null
public lower_bound(key: Key): XTreeNode<Elem> | null
{
const ret = this.nearest(key);
if (ret === null || !this.key_eq_(key, this.fetcher_(ret.value)))
// NEED NOT TO ITERATE
if (this.root_ === null)
return null;
//----
// ITERATE
//----
let ret: XTreeNode<Elem> = this.root_!;
let matched: XTreeNode<Elem> | null = null;
// UNTIL MEET THE MATCHED VALUE OR FINAL BRANCH
while (true)
{
const candidate: Key = this.fetcher_(ret.value);
let child: XTreeNode<Elem> | null = null;
// COMPARE
if (this.key_comp_(candidate, key) === true)
child = ret.right;
else if (this.key_comp_(candidate, key) === false)
{
matched = ret;
child = ret.left;
}
else
child = ret.left;
// FINAL BRANCH? OR KEEP GOING
if (child === null)
break;
ret = child;
}
// RETURNS
if (matched !== null)
return matched;
else if (this.key_comp_(this.fetcher_(ret.value), key) === true)
return null;
else
return ret;
}
@inline()
public nearest(key: Key): XTreeNode<Elem> | null
{
return (this.unique_ === true)
? XTree.unique_nearest(this, key)
: XTree.multi_nearest(this, key, node => node.left);
}
private find_value(value: Elem): XTreeNode<Elem> | null

@@ -154,83 +175,2 @@ {

}
/* ---------------------------------------------------------
UNIQUE
--------------------------------------------------------- */
private static unique_nearest<Key, Elem>
(tree: XTree<Key, Elem>, key: Key): XTreeNode<Elem> | null
{
// NEED NOT TO ITERATE
if (tree.root_ === null)
return null;
//----
// ITERATE
//----
let ret: XTreeNode<Elem> = tree.root_!;
while (true) // UNTIL MEET THE MATCHED VALUE OR FINAL BRANCH
{
let child: XTreeNode<Elem> | null = null;
// COMPARE
if (tree.key_comp_(key, tree.fetcher_(ret.value)))
child = ret.left;
else if (tree.key_comp_(tree.fetcher_(ret.value), key))
child = ret.right;
else
return ret; // MATCHED VALUE
// FINAL BRANCH? OR KEEP GOING
if (child !== null)
ret = child;
else
break;
}
return ret; // DIFFERENT NODE
}
/* ---------------------------------------------------------
DUPLICATED
--------------------------------------------------------- */
protected static multi_nearest<Key, Elem>
(tree: XTree<Key, Elem>, key: Key, equalMover: (node: XTreeNode<Elem>) => XTreeNode<Elem> | null): XTreeNode<Elem> | null
{
// NEED NOT TO ITERATE
if (tree.root_ === null)
return null;
//----
// ITERATE
//----
let ret: XTreeNode<Elem> = tree.root_!;
let matched: XTreeNode<Elem> | null = null;
while (true)
{
const candidate: Elem = ret.value;
let node: XTreeNode<Elem> | null = null;
// COMPARE
if (tree.key_comp_(key, tree.fetcher_(candidate)))
node = ret.left;
else if (tree.key_comp_(tree.fetcher_(candidate), key))
node = ret.right;
else
{
matched = ret;
node = equalMover(ret);
}
// ULTIL CHILD NODE EXISTS
if (node === null)
break;
ret = node;
}
// RETURNS -> MATCHED OR NOT
if (matched !== null)
return matched;
else
return ret;
}

@@ -237,0 +177,0 @@ /* =========================================================

@@ -0,5 +1,7 @@

import { IPointer } from "../functional/IPointer";
export interface IForwardIterator<T, Iterator extends IForwardIterator<T, Iterator>>
extends IPointer<T>
{
value: T;
next(): Iterator;
}

@@ -9,3 +9,3 @@ {

},
"version": "0.0.7",
"version": "0.0.8",
"main": "./index.ts",

@@ -12,0 +12,0 @@ "scripts": {

@@ -13,4 +13,4 @@ # AssemblyScript Standard Template Library

- Iterators
- ~~Algorithms~~
- ~~Functors~~
- Algorithms
- Functors

@@ -17,0 +17,0 @@ **ASTL** is an open-source project providing features of the STL, migrated from the *C++* to the *AssemblyScript*. You can enjoy those STL's own specific *containers*, *algorithms* and *functors* in the AssemblyScript.

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