diff --git a/3d-bin-packing/3d-bin-packing-tests.ts b/3d-bin-packing/3d-bin-packing-tests.ts index 319624d597..8e394e46bb 100644 --- a/3d-bin-packing/3d-bin-packing-tests.ts +++ b/3d-bin-packing/3d-bin-packing-tests.ts @@ -1,5 +1,5 @@ import packer = require("3d-bin-packing"); -import samchon = require("samchon-framework"); +import samchon = require("samchon"); function main(): void { diff --git a/3d-bin-packing/index.d.ts b/3d-bin-packing/index.d.ts index 14228f3141..8165ea513e 100644 --- a/3d-bin-packing/index.d.ts +++ b/3d-bin-packing/index.d.ts @@ -1,20 +1,22 @@ -// Type definitions for 3d-bin-packing +// Type definitions for 3d-bin-packing v1.1.2 // Project: https://github.com/betterwaysystems/packer // Definitions by: Jeongho Nam // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.1 -/// -/// -/// -/// -/// +/// declare module "3d-bin-packing" { - export = bws.packer; + export = bws.packer; +} + +/// +/// +declare namespace bws.packer { + export import library = samchon.library; + export import protocol = samchon.protocol; + function _Test(): void; } -declare var ReactDataGrid: typeof AdazzleReactDataGrid.ReactDataGrid; declare namespace boxologic { /** *

An abstract instance of boxologic.

@@ -62,122 +64,6 @@ declare namespace boxologic { constructor(width: number, height: number, length: number); } } -declare namespace bws.packer { - /** - * @brief Packer, a solver of 3d bin packing with multiple wrappers. - * - * @details - *

Packer is a facade class supporting packing operations in user side. You can solve a packing problem - * by constructing Packer class with {@link WrapperArray wrappers} and {@link InstanceArray instances} to - * pack and executing {@link optimize Packer.optimize()} method.

- * - *

In background side, deducting packing solution, those algorithms are used.

- * - * - * @author Jeongho Nam - */ - class Packer extends samchon.protocol.Entity { - /** - * Candidate wrappers who can contain instances. - */ - protected wrapperArray: WrapperArray; - /** - * Instances trying to pack into the wrapper. - */ - protected instanceArray: InstanceArray; - /** - * Default Constructor. - */ - constructor(); - /** - * Construct from members. - * - * @param wrapperArray Candidate wrappers who can contain instances. - * @param instanceArray Instances to be packed into some wrappers. - */ - constructor(wrapperArray: WrapperArray, instanceArray: InstanceArray); - /** - * @inheritdoc - */ - construct(xml: samchon.library.XML): void; - /** - * Get wrapperArray. - */ - getWrapperArray(): WrapperArray; - /** - * Get instanceArray. - */ - getInstanceArray(): InstanceArray; - /** - *

Deduct - * - */ - optimize(): WrapperArray; - /** - * @brief Initialize sequence list (gene_array). - * - * @details - *

Deducts initial sequence list by such assumption:

- * - *
    - *
  • Cost of larger wrapper is less than smaller one, within framework of price per volume unit.
  • - *
      - *
    • Wrapper Larger: (price: $1,000, volume: 100cm^3 -> price per volume unit: $10 / cm^3)
    • - *
    • Wrapper Smaller: (price: $700, volume: 50cm^3 -> price per volume unit: $14 / cm^3)
    • - *
    • Larger's cost is less than Smaller, within framework of price per volume unit
    • - *
    - *
- * - *

Method {@link initGenes initGenes()} constructs {@link WrapperGroup WrapperGroups} corresponding - * with the {@link wrapperArray} and allocates {@link instanceArray instances} to a {@link WrapperGroup}, - * has the smallest cost between containbles.

- * - *

After executing packing solution by {@link WrapperGroup.optimize WrapperGroup.optimize()}, trying to - * {@link repack re-pack} each {@link WrapperGroup} to another type of {@link Wrapper}, deducts the best - * solution between them. It's the initial sequence list of genetic algorithm.

- * - * @return Initial sequence list. - */ - protected initGenes(): GAWrapperArray; - /** - * Try to repack each wrappers to another type. - * - * @param $wrappers Wrappers to repack. - * @return Re-packed wrappers. - */ - protected repack($wrappers: WrapperArray): WrapperArray; - /** - * @inheritdoc - */ - TAG(): string; - /** - * @inheritdoc - */ - toXML(): samchon.library.XML; - } -} -declare namespace flex { - class TabNavigator extends React.Component { - render(): JSX.Element; - private handle_change(index, event); - } - class NavigatorContent extends React.Component { - render(): JSX.Element; - } - interface TabNavigatorProps extends React.Props { - selectedIndex?: number; - style?: React.CSSProperties; - } - interface NavigatorContentProps extends React.Props { - label: string; - } -} declare namespace boxologic { /** * A box, trying to pack into a {@link Pallet}. @@ -589,7 +475,7 @@ declare namespace bws.packer { * * @author Jeongho Nam */ - class PackerForm extends samchon.protocol.Entity { + class PackerForm extends protocol.Entity { /** * Form of Instances to pack. */ @@ -609,12 +495,12 @@ declare namespace bws.packer { * @param wrapperArray Type of Wrappers to be used. */ constructor(instanceFormArray: InstanceFormArray, wrapperArray: WrapperArray); - construct(xml: samchon.library.XML): void; + construct(xml: library.XML): void; optimize(): WrapperArray; getInstanceFormArray(): InstanceFormArray; getWrapperArray(): WrapperArray; TAG(): string; - toXML(): samchon.library.XML; + toXML(): library.XML; toPacker(): Packer; } /** @@ -622,12 +508,12 @@ declare namespace bws.packer { * * @author Jeongho Nam */ - class InstanceFormArray extends samchon.protocol.EntityArrayCollection { + class InstanceFormArray extends protocol.EntityArrayCollection { /** * Default Constructor. */ constructor(); - createChild(xml: samchon.library.XML): InstanceForm; + createChild(xml: library.XML): InstanceForm; TAG(): string; CHILD_TAG(): string; /** @@ -645,7 +531,7 @@ declare namespace bws.packer { * * @author Jeongho Nam */ - class InstanceForm extends samchon.protocol.Entity { + class InstanceForm extends protocol.Entity { /** * A duplicated Instance. */ @@ -661,7 +547,7 @@ declare namespace bws.packer { /** * @inheritdoc */ - construct(xml: samchon.library.XML): void; + construct(xml: library.XML): void; private createInstance(xml); key(): any; getInstance(): Instance; @@ -679,7 +565,7 @@ declare namespace bws.packer { /** * @inheritdoc */ - toXML(): samchon.library.XML; + toXML(): library.XML; /** *

Repeated {@link instance} to {@link InstanceArray}. * @@ -694,7 +580,7 @@ declare namespace bws.packer { } } declare namespace bws.packer { - class WrapperArray extends samchon.protocol.EntityArrayCollection { + class WrapperArray extends protocol.EntityArrayCollection { /** * Default Constructor. */ @@ -702,7 +588,7 @@ declare namespace bws.packer { /** * @inheritdoc */ - createChild(xml: samchon.library.XML): Wrapper; + createChild(xml: library.XML): Wrapper; /** * Get (calculate) price. */ @@ -756,7 +642,7 @@ declare namespace bws.packer { * * @author Jeongho Nam */ - interface Instance extends samchon.protocol.IEntity { + interface Instance extends protocol.IEntity { /** * Get name. */ @@ -813,7 +699,7 @@ declare namespace bws.packer { * * @author Jeongho Nam */ - class InstanceArray extends samchon.protocol.EntityArray { + class InstanceArray extends protocol.EntityArray { /** * Default Constructor. */ @@ -821,7 +707,7 @@ declare namespace bws.packer { /** * @inheritdoc */ - createChild(xml: samchon.library.XML): Instance; + createChild(xml: library.XML): Instance; /** * @inheritdoc */ @@ -832,13 +718,113 @@ declare namespace bws.packer { CHILD_TAG(): string; } } +declare namespace bws.packer { + /** + * @brief Packer, a solver of 3d bin packing with multiple wrappers. + * + * @details + *

Packer is a facade class supporting packing operations in user side. You can solve a packing problem + * by constructing Packer class with {@link WrapperArray wrappers} and {@link InstanceArray instances} to + * pack and executing {@link optimize Packer.optimize()} method.

+ * + *

In background side, deducting packing solution, those algorithms are used.

+ * + * + * @author Jeongho Nam + */ + class Packer extends protocol.Entity { + /** + * Candidate wrappers who can contain instances. + */ + protected wrapperArray: WrapperArray; + /** + * Instances trying to pack into the wrapper. + */ + protected instanceArray: InstanceArray; + /** + * Default Constructor. + */ + constructor(); + /** + * Construct from members. + * + * @param wrapperArray Candidate wrappers who can contain instances. + * @param instanceArray Instances to be packed into some wrappers. + */ + constructor(wrapperArray: WrapperArray, instanceArray: InstanceArray); + /** + * @inheritdoc + */ + construct(xml: library.XML): void; + /** + * Get wrapperArray. + */ + getWrapperArray(): WrapperArray; + /** + * Get instanceArray. + */ + getInstanceArray(): InstanceArray; + /** + *

Deduct + * + */ + optimize(): WrapperArray; + /** + * @brief Initialize sequence list (gene_array). + * + * @details + *

Deducts initial sequence list by such assumption:

+ * + *
    + *
  • Cost of larger wrapper is less than smaller one, within framework of price per volume unit.
  • + *
      + *
    • Wrapper Larger: (price: $1,000, volume: 100cm^3 -> price per volume unit: $10 / cm^3)
    • + *
    • Wrapper Smaller: (price: $700, volume: 50cm^3 -> price per volume unit: $14 / cm^3)
    • + *
    • Larger's cost is less than Smaller, within framework of price per volume unit
    • + *
    + *
+ * + *

Method {@link initGenes initGenes()} constructs {@link WrapperGroup WrapperGroups} corresponding + * with the {@link wrapperArray} and allocates {@link instanceArray instances} to a {@link WrapperGroup}, + * has the smallest cost between containbles.

+ * + *

After executing packing solution by {@link WrapperGroup.optimize WrapperGroup.optimize()}, trying to + * {@link repack re-pack} each {@link WrapperGroup} to another type of {@link Wrapper}, deducts the best + * solution between them. It's the initial sequence list of genetic algorithm.

+ * + * @return Initial sequence list. + */ + protected initGenes(): GAWrapperArray; + /** + * Try to repack each wrappers to another type. + * + * @param $wrappers Wrappers to repack. + * @return Re-packed wrappers. + */ + protected repack($wrappers: WrapperArray): WrapperArray; + /** + * @inheritdoc + */ + TAG(): string; + /** + * @inheritdoc + */ + toXML(): library.XML; + } +} declare namespace bws.packer { /** * A product. * * @author Jeongho Nam */ - class Product extends samchon.protocol.Entity implements Instance { + class Product extends protocol.Entity implements Instance { /** *

Name, key of the Product.

* @@ -921,7 +907,7 @@ declare namespace bws.packer { /** * @inheritdoc */ - toXML(): samchon.library.XML; + toXML(): library.XML; } } declare namespace bws.packer { @@ -937,7 +923,7 @@ declare namespace bws.packer { * * @author Jeongho Nam */ - class Wrap extends samchon.protocol.Entity { + class Wrap extends protocol.Entity { /** * A wrapper wrapping the {@link instance}. */ @@ -962,10 +948,6 @@ declare namespace bws.packer { * Placement orientation of wrapped {@link instance}. */ protected orientation: number; - /** - * - */ - protected color: number; /** * Construct from a Wrapper. * @@ -996,7 +978,7 @@ declare namespace bws.packer { /** * @inheritdoc */ - construct(xml: samchon.library.XML): void; + construct(xml: library.XML): void; /** * Factory method of wrapped Instance. * @@ -1058,11 +1040,11 @@ declare namespace bws.packer { /** * Get width. */ - getWidth(): number; + getLayoutWidth(): number; /** * Get height. */ - getHeight(): number; + getLayoutHeight(): number; /** * Get length. */ @@ -1071,9 +1053,9 @@ declare namespace bws.packer { * Get volume. */ getVolume(): number; - $instanceName: string; - $layoutScale: string; - $position: string; + readonly $instanceName: string; + readonly $layoutScale: string; + readonly $position: string; /** * @inheritdoc */ @@ -1081,19 +1063,7 @@ declare namespace bws.packer { /** * @inheritdoc */ - toXML(): samchon.library.XML; - /** - * Thickness of boundary lines of a shape represents the {@link instance}. - */ - private static BOUNDARY_THICKNESS; - /** - * - * - * @param geometry - * - * @return A shape and its boundary lines as 3D-objects. - */ - toDisplayObjects(geometry: THREE.Geometry): std.Vector; + toXML(): library.XML; } } declare namespace bws.packer { @@ -1102,7 +1072,7 @@ declare namespace bws.packer { * * @author Jeongho Nam */ - class Wrapper extends samchon.protocol.EntityDeque implements Instance { + class Wrapper extends protocol.EntityDeque implements Instance { /** *

Name, key of the Wrapper.

* @@ -1151,11 +1121,10 @@ declare namespace bws.packer { * @param thickness A thickness causes shrinkness on containable volume. */ constructor(name: string, price: number, width: number, height: number, length: number, thickness: number); - construct(xml: samchon.library.XML): void; /** * @inheritdoc */ - createChild(xml: samchon.library.XML): Wrap; + createChild(xml: library.XML): Wrap; /** * Key of a Wrapper is its name. */ @@ -1232,7 +1201,7 @@ declare namespace bws.packer { * @return utilization ratio. */ getUtilization(): number; - equal_to(obj: Wrapper): boolean; + equals(obj: Wrapper): boolean; /** *

Wrapper is enough greater?

* @@ -1272,8 +1241,8 @@ declare namespace bws.packer { $height: string; $length: string; $thickness: string; - $scale: string; - $spaceUtilization: string; + readonly $scale: string; + readonly $spaceUtilization: string; /** * @inheritdoc */ @@ -1289,25 +1258,7 @@ declare namespace bws.packer { /** * @inheritdoc */ - toXML(): samchon.library.XML; - private static scene; - private static renderer; - private static camera; - private static trackball; - private static mouse; - private static BOUNDARY_THICKNESS; - /** - *

Convert to a canvas containing 3D elements.

- * - * @param endIndex - * - * @return A 3D-canvans printing the Wrapper and its children {@link Wrap wrapped} - * {@link Instance instances} with those boundary lines. - */ - toCanvas(endIndex?: number): HTMLCanvasElement; - private static handleMouseMove(event); - private static animate(); - private static render(); + toXML(): library.XML; } } declare namespace bws.packer { @@ -1430,72 +1381,3 @@ declare namespace bws.packer { TAG(): string; } } -declare namespace bws.packer { - abstract class Editor extends React.Component<{ - dataProvider: samchon.protocol.EntityArrayCollection; - }, {}> { - private columns; - private selected_index; - /** - * Default Constructor. - */ - constructor(); - protected abstract createColumns(): AdazzleReactDataGrid.Column[]; - private get_row(index); - private insert_instance(event); - private erase_instances(event); - private handle_data_change(event); - private handle_row_change(event); - private handle_select(event); - render(): JSX.Element; - } -} -declare namespace bws.packer { - interface ItemEditorProps extends React.Props { - application: PackerApplication; - instances: InstanceFormArray; - wrappers: WrapperArray; - } - class ItemEditor extends React.Component { - private clear(event); - private open(event); - private save(event); - private pack(event); - render(): JSX.Element; - } - class InstanceEditor extends Editor { - protected createColumns(): AdazzleReactDataGrid.Column[]; - } - class WrapperEditor extends Editor { - protected createColumns(): AdazzleReactDataGrid.Column[]; - } -} -declare namespace bws.packer { - class PackerApplication extends React.Component<{}, {}> { - private instances; - private wrappers; - private result; - /** - * Default Constructor. - */ - constructor(); - pack(): void; - drawWrapper(wrapper: Wrapper, index?: number): void; - render(): JSX.Element; - static main(): void; - } -} -declare namespace bws.packer { - class ResultViewer extends React.Component { - drawWrapper(wrapper: Wrapper, index?: number): void; - private clear(event); - private open(event); - private save(event); - refresh(): void; - render(): JSX.Element; - } - interface WrapperViewerProps extends React.Props { - application: PackerApplication; - wrappers: WrapperArray; - } -} diff --git a/samchon-framework/index.d.ts b/samchon-framework/index.d.ts index 558efd674a..fa540e033d 100644 --- a/samchon-framework/index.d.ts +++ b/samchon-framework/index.d.ts @@ -1,10811 +1,13 @@ -// Type definitions for Samchon Framework 2.0 +// Type definitions for Samchon Framework v2.0.x // Project: https://github.com/samchon/framework // Definitions by: Jeongho Nam // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/// +/// +// Samchon-Framework is renamed to Samchon declare module "samchon-framework" { + import samchon = require("samchon"); export = samchon; -} - -/** - * # Samchon-Framework - * - * - * - * - * Samchon, a OON (Object-Oriented Network) framework. - * - * With Samchon Framework, you can implement distributed processing system within framework of OOD like handling S/W - * objects (classes). You can realize cloud and distributed system very easily with provided system templates and even - * integration with C++ is possible. - * - * The goal, ultimate utilization model of Samchon Framework is, building cloud system with NodeJS and taking heavy works - * to C++ distributed systems with provided modules (those are system templates). - * - * @git https://github.com/samchon/framework - * @author Jeongho Nam - */ -declare namespace samchon { - /** - * Running on Node. - * - * Test whether the JavaScript is running on Node. - * - * @references http://stackoverflow.com/questions/17575790/environment-detection-node-js-or-browser - */ - function is_node(): boolean; -} -declare namespace samchon.collections { - /** - * A {@link Vector} who can detect element I/O events. - * - * Below is the list of methods who are dispatching {@link CollectionEvent}: - * - *insert* typed events: - * - {@link assign} - * - {@link insert} - * - {@link push} - * - {@link push_back} - * - {@link unshift} - * - *erase* typed events: - * - {@link assign} - * - {@link clear} - * - {@link erase} - * - {@link pop_back} - * - {@link shift} - * - {@link pop} - * - {@link splice} - * - *refresh* typed events: - * - {@link refresh} - * - * #### [Inherited] {@link Vector} - * {@link Vector Vectors}s are sequence containers representing arrays that can change in size. - * - * Just like arrays, {@link Vector}s use contiguous storage locations for their elements, which means that their - * elements can also be accessed using offsets on regular pointers to its elements, and just as efficiently as in - * arrays. But unlike arrays, their size can change dynamically, with their storage being handled automatically - * by the container. - * - * Internally, {@link Vector}s use a dynamically allocated array to store their elements. This array may need to - * be reallocated in order to grow in size when new elements are inserted, which implies allocating a new array - * and moving all elements to it. This is a relatively expensive task in terms of processing time, and thus, - * {@link Vector}s do not reallocate each time an element is added to the container. - * - * Instead, {@link Vector} containers may allocate some extra storage to accommodate for possible growth, and - * thus the container may have an actual {@link capacity} greater than the storage strictly needed to contain its - * elements (i.e., its {@link size}). Libraries can implement different strategies for growth to balance between - * memory usage and reallocations, but in any case, reallocations should only happen at logarithmically growing - * intervals of {@link size} so that the insertion of individual elements at the end of the {@link Vector} can be - * provided with amortized constant time complexity (see {@link push_back push_back()}). - * - * Therefore, compared to arrays, {@link Vector}s consume more memory in exchange for the ability to manage - * storage and grow dynamically in an efficient way. - * - * Compared to the other dynamic sequence containers ({@link Deque}s, {@link List}s), {@link Vector Vectors} are - * very efficient accessing its elements (just like arrays) and relatively efficient adding or removing elements - * from its end. For operations that involve inserting or removing elements at positions other than the end, they - * perform worse than the others, and have less consistent iterators and references than {@link List}s. - * - * - * - * - * - *

Container properties

- *
- *
Sequence
- *
- * Elements in sequence containers are ordered in a strict linear sequence. Individual elements are - * accessed by their position in this sequence. - *
- * - *
Dynamic array
- *
- * Allows direct access to any element in the sequence, even through pointer arithmetics, and provides - * relatively fast addition/removal of elements at the end of the sequence. - *
- *
- * - * @param Type of the elements. - * - * @reference http://www.cplusplus.com/reference/vector/vector - * @handbook [Collections](https://github.com/samchon/framework/wiki/TypeScript-STL#collections) - * @author Jeongho Nam - */ - class ArrayCollection extends std.Vector implements ICollection { - /** - * A chain object taking responsibility of dispatching events. - */ - private event_dispatcher_; - /** - * @inheritdoc - */ - push(...items: T[]): number; - /** - * @inheritdoc - */ - push_back(val: T): void; - /** - * @hidden - */ - protected _Insert_by_repeating_val(position: std.VectorIterator, n: number, val: T): std.VectorIterator; - /** - * @hidden - */ - protected _Insert_by_range>(position: std.VectorIterator, begin: InputIterator, end: InputIterator): std.VectorIterator; - /** - * @hidden - */ - protected _Erase_by_range(first: std.VectorIterator, last: std.VectorIterator): std.VectorIterator; - /** - * @hidden - */ - private notify_insert(first, last); - /** - * @hidden - */ - private notify_erase(first, last); - /** - * @inheritdoc - */ - hasEventListener(type: string): boolean; - /** - * @inheritdoc - */ - dispatchEvent(event: library.BasicEvent): boolean; - /** - * @inheritdoc - */ - refresh(): void; - /** - * @inheritdoc - */ - refresh(it: std.VectorIterator): void; - /** - * @inheritdoc - */ - refresh(first: std.VectorIterator, last: std.VectorIterator): void; - /** - * @inheritdoc - */ - addEventListener(type: string, listener: library.BasicEventListener): void; - addEventListener(type: "insert", listener: CollectionEventListener): void; - addEventListener(type: "erase", listener: CollectionEventListener): void; - addEventListener(type: "refresh", listener: CollectionEventListener): void; - /** - * @inheritdoc - */ - addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - addEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; - addEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; - addEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; - /** - * @inheritdoc - */ - removeEventListener(type: string, listener: library.BasicEventListener): void; - removeEventListener(type: "insert", listener: CollectionEventListener): void; - removeEventListener(type: "erase", listener: CollectionEventListener): void; - removeEventListener(type: "refresh", listener: CollectionEventListener): void; - /** - * @inheritdoc - */ - removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - removeEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; - removeEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; - removeEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; - /** - * @inheritdoc - */ - unshift(...items: U[]): number; - /** - * @inheritdoc - */ - pop(): T; - /** - * @inheritdoc - */ - splice(start: number): T[]; - /** - * @inheritdoc - */ - splice(start: number, deleteCount: number, ...items: T[]): T[]; - } -} -declare namespace samchon.library { - /** - * A basic event class of Samchon Framework. - * - * @reference https://developer.mozilla.org/en-US/docs/Web/API/Event - * @handbook https://github.com/samchon/framework/wiki/TypeScript-Library-EventDispatcher - * @author Jeongho Nam - */ - class BasicEvent { - protected type_: string; - protected target_: IEventDispatcher; - private currentTarget_; - protected trusted_: boolean; - protected bubbles_: boolean; - protected cancelable_: boolean; - protected defaultPrevented_: boolean; - protected cancelBubble_: boolean; - private timeStamp_; - constructor(type: string, bubbles?: boolean, cancelable?: boolean); - /** - * @inheritdoc - */ - initEvent(type: string, bubbles: boolean, cancelable: boolean): void; - /** - * @inheritdoc - */ - /** - * @inheritdoc - */ - stopImmediatePropagation(): void; - /** - * @inheritdoc - */ - stopPropagation(): void; - /** - * @inheritdoc - */ - readonly type: string; - /** - * @inheritdoc - */ - target: IEventDispatcher; - /** - * @inheritdoc - */ - readonly currentTarget: IEventDispatcher; - /** - * @inheritdoc - */ - readonly isTrusted: boolean; - /** - * @inheritdoc - */ - readonly bubbles: boolean; - /** - * @inheritdoc - */ - readonly cancelable: boolean; - /** - * @inheritdoc - */ - readonly eventPhase: number; - /** - * @inheritdoc - */ - readonly defaultPrevented: boolean; - /** - * @inheritdoc - */ - readonly srcElement: Element; - /** - * @inheritdoc - */ - readonly cancelBubble: boolean; - /** - * @inheritdoc - */ - readonly timeStamp: number; - /** - * Don't know what it is. - */ - readonly returnValue: boolean; - } -} -declare namespace samchon.collections { - /** - * Type of function pointer for listener of {@link CollectionEvent CollectionEvents}. - */ - type CollectionEventListener = (event: CollectionEvent) => void; -} -declare namespace samchon.collections { - /** - * An event occured in a {@link ICollection collection} object. - * - * @handbook [Collections](https://github.com/samchon/framework/wiki/TypeScript-STL#collections) - * @author Jeongho Nam - */ - class CollectionEvent extends library.BasicEvent { - /** - * @hidden - */ - private first_; - /** - * @hidden - */ - private last_; - /** - * @hidden - */ - private temporary_container_; - /** - * @hidden - */ - private origin_first_; - /** - * Initialization Constructor. - * - * @param type Type of collection event. - * @param first An {@link Iterator} to the initial position in this {@link CollectionEvent}. - * @param last An {@link Iterator} to the final position in this {@link CollectionEvent}. - */ - constructor(type: string, first: std.Iterator, last: std.Iterator); - constructor(type: "insert", first: std.Iterator, last: std.Iterator); - constructor(type: "erase", first: std.Iterator, last: std.Iterator); - constructor(type: "refresh", first: std.Iterator, last: std.Iterator); - /** - * Associative target, the {@link ICollection collection}. - */ - readonly target: ICollection; - /** - * An {@link Iterator} to the initial position in this {@link CollectionEvent}. - */ - readonly first: std.Iterator; - /** - * An {@link Iterator} to the final position in this {@link CollectionEvent}. - */ - readonly last: std.Iterator; - /** - * @inheritdoc - */ - preventDefault(): void; - } -} -declare namespace samchon.collections.CollectionEvent { - const INSERT: "insert"; - const ERASE: "erase"; - const REFRESH: "refresh"; -} -declare namespace samchon.collections { - /** - * A {@link Deque} who can detect element I/O events. - * - * Below is the list of methods who are dispatching {@link CollectionEvent}: - * - *insert* typed events: - * - {@link assign} - * - {@link insert} - * - {@link push} - * - {@link push_front} - * - {@link push_back} - * - *erase* typed events: - * - {@link assign} - * - {@link clear} - * - {@link erase} - * - {@link pop_front} - * - {@link pop_back} - * - *refresh* typed events: - * - {@link refresh} - * - * #### [Inherited] {@link Deque} - * {@link Deque} (usually pronounced like "*deck*") is an irregular acronym of **d**ouble-**e**nded **q**ueue. - * Double-ended queues are sequence containers with dynamic sizes that can be expanded or contracted on both ends - * (either its front or its back). - * - * Specific libraries may implement deques in different ways, generally as some form of dynamic array. But in any - * case, they allow for the individual elements to be accessed directly through random access iterators, with - * storage handled automatically by expanding and contracting the container as needed. - * - * Therefore, they provide a functionality similar to vectors, but with efficient insertion and deletion of - * elements also at the beginning of the sequence, and not only at its end. But, unlike {@link Vector Vectors}, - * {@link Deque Deques} are not guaranteed to store all its elements in contiguous storage locations: accessing - * elements in a deque by offsetting a pointer to another element causes undefined behavior. - * - * Both {@link Vector}s and {@link Deque}s provide a very similar interface and can be used for similar purposes, - * but internally both work in quite different ways: While {@link Vector}s use a single array that needs to be - * occasionally reallocated for growth, the elements of a {@link Deque} can be scattered in different chunks of - * storage, with the container keeping the necessary information internally to provide direct access to any of its - * elements in constant time and with a uniform sequential interface (through iterators). Therefore, - * {@link Deque Deques} are a little more complex internally than {@link Vector}s, but this allows them to grow - * more efficiently under certain circumstances, especially with very long sequences, where reallocations become - * more expensive. - * - * For operations that involve frequent insertion or removals of elements at positions other than the beginning or - * the end, {@link Deque Deques} perform worse and have less consistent iterators and references than - * {@link List Lists}. - * - * - * - * - * - *

Container properties

- *
- *
Sequence
- *
Elements in sequence containers are ordered in a strict linear sequence. Individual elements - * are accessed by their position in this sequence.
- * - *
Dynamic array
- *
Generally implemented as a dynamic array, it allows direct access to any element in the - * sequence and provides relatively fast addition/removal of elements at the beginning or the end - * of the sequence.
- *
- * - * @param Type of the elements. - * - * @reference http://www.cplusplus.com/reference/deque/deque/ - * @handbook [Collections](https://github.com/samchon/framework/wiki/TypeScript-STL#collections) - * @author Jeongho Nam - */ - class DequeCollection extends std.Deque implements ICollection { - /** - * A chain object taking responsibility of dispatching events. - */ - private event_dispatcher_; - /** - * @inheritdoc - */ - push(...items: T[]): number; - /** - * @inheritdoc - */ - push_back(val: T): void; - /** - * @hidden - */ - protected _Insert_by_repeating_val(position: std.DequeIterator, n: number, val: T): std.DequeIterator; - /** - * @hidden - */ - protected _Insert_by_range>(position: std.DequeIterator, begin: InputIterator, end: InputIterator): std.DequeIterator; - /** - * @inheritdoc - */ - pop_back(): void; - /** - * @hidden - */ - protected _Erase_by_range(first: std.DequeIterator, last: std.DequeIterator): std.DequeIterator; - /** - * @hidden - */ - private notify_insert(first, last); - /** - * @hidden - */ - private notify_erase(first, last); - /** - * @inheritdoc - */ - hasEventListener(type: string): boolean; - /** - * @inheritdoc - */ - dispatchEvent(event: library.BasicEvent): boolean; - /** - * @inheritdoc - */ - refresh(): void; - /** - * @inheritdoc - */ - refresh(it: std.DequeIterator): void; - /** - * @inheritdoc - */ - refresh(first: std.DequeIterator, last: std.DequeIterator): void; - /** - * @inheritdoc - */ - addEventListener(type: string, listener: library.BasicEventListener): void; - addEventListener(type: "insert", listener: CollectionEventListener): void; - addEventListener(type: "erase", listener: CollectionEventListener): void; - addEventListener(type: "refresh", listener: CollectionEventListener): void; - /** - * @inheritdoc - */ - addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - addEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; - addEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; - addEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; - /** - * @inheritdoc - */ - removeEventListener(type: string, listener: library.BasicEventListener): void; - removeEventListener(type: "insert", listener: CollectionEventListener): void; - removeEventListener(type: "erase", listener: CollectionEventListener): void; - removeEventListener(type: "refresh", listener: CollectionEventListener): void; - /** - * @inheritdoc - */ - removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - removeEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; - removeEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; - removeEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; - } -} -declare namespace samchon.collections { - /** - * A {@link HashMap} who can detect element I/O events. - * - * Below is the list of methods who are dispatching {@link MapCollectionEvent}: - * - *insert* typed events: - * - {@link assign} - * - {@link insert} - * - {@link insert_or_assign} - * - {@link emplace} - * - {@link set} - * - {@link push} - * - *erase* typed events: - * - {@link assign} - * - {@link clear} - * - {@link erase} - * - {@link extract} - * - *refresh* typed events: - * - {@link refresh} - * - * #### [Inherited] {@link HashMap} - * {@link HashMap HashMaps} are associative containers that store elements formed by the combination of a - * *key value* and a *mapped value*, and which allows for fast retrieval of individual elements based on their - * *keys*. - * - * In an {@link HashMap}, the *key value* is generally used to uniquely identify the element, while the - * *mapped value* is an object with the content associated to this *key*. Types of *key* and *mapped value* may - * differ. - * - * Internally, the elements in the {@link HashMap} are not sorted in any particular order with respect to either - * their *key* or *mapped values*, but organized into *buckets* depending on their hash values to allow for fast - * access to individual elements directly by their *key values* (with a constant average time complexity on - * average). - * - * {@link HashMap} containers are faster than {@link TreeMap} containers to access individual elements by their - * *key*, although they are generally less efficient for range iteration through a subset of their elements. - * - * - * - * - * - *

Container properties

- *
- *
Associative
- *
Elements in associative containers are referenced by their *key* and not by their absolute - * position in the container.
- * - *
Hashed
- *
Hashed containers organize their elements using hash tables that allow for fast access to elements - * by their *key*.
- * - *
Map
- *
Each element associates a *key* to a *mapped value*: - * *Keys* are meant to identify the elements whose main content is the *mapped value*.
- * - *
Unique keys
- *
No two elements in the container can have equivalent keys.
- *
- * - * @param Type of the key values. - * Each element in an {@link HashMap} is uniquely identified by its key value. - * @param Type of the mapped value. - * Each element in an {@link HashMap} is used to store some data as its mapped value. - * - * @reference http://www.cplusplus.com/reference/unordered_map/unordered_map - * @handbook [Collections](https://github.com/samchon/framework/wiki/TypeScript-STL#collections) - * @author Jeongho Nam - */ - class HashMapCollection extends std.HashMap implements ICollection> { - /** - * A chain object taking responsibility of dispatching events. - */ - private event_dispatcher_; - /** - * @inheritdoc - */ - protected _Handle_insert(first: std.MapIterator, last: std.MapIterator): void; - /** - * @inheritdoc - */ - protected _Handle_erase(first: std.MapIterator, last: std.MapIterator): void; - /** - * @inheritdoc - */ - hasEventListener(type: string): boolean; - /** - * @inheritdoc - */ - dispatchEvent(event: library.BasicEvent): boolean; - /** - * @inheritdoc - */ - refresh(): void; - /** - * @inheritdoc - */ - refresh(it: std.MapIterator): void; - /** - * @inheritdoc - */ - refresh(first: std.MapIterator, last: std.MapIterator): void; - /** - * @inheritdoc - */ - addEventListener(type: string, listener: library.BasicEventListener): void; - addEventListener(type: "insert", listener: MapCollectionEventListener): void; - addEventListener(type: "erase", listener: MapCollectionEventListener): void; - addEventListener(type: "refresh", listener: MapCollectionEventListener): void; - /** - * @inheritdoc - */ - addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - addEventListener(type: "insert", listener: MapCollectionEventListener, thisArg: Object): void; - addEventListener(type: "erase", listener: MapCollectionEventListener, thisArg: Object): void; - addEventListener(type: "refresh", listener: MapCollectionEventListener, thisArg: Object): void; - /** - * @inheritdoc - */ - removeEventListener(type: string, listener: library.BasicEventListener): void; - removeEventListener(type: "insert", listener: MapCollectionEventListener): void; - removeEventListener(type: "erase", listener: MapCollectionEventListener): void; - removeEventListener(type: "refresh", listener: MapCollectionEventListener): void; - /** - * @inheritdoc - */ - removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - removeEventListener(type: "insert", listener: MapCollectionEventListener, thisArg: Object): void; - removeEventListener(type: "erase", listener: MapCollectionEventListener, thisArg: Object): void; - removeEventListener(type: "refresh", listener: MapCollectionEventListener, thisArg: Object): void; - } -} -declare namespace samchon.collections { - /** - * A {@link HashMultiMap} who can detect element I/O events. - * - * Below is the list of methods who are dispatching {@link MapCollectionEvent}: - * - *insert* typed events: - * - {@link assign} - * - {@link insert} - * - {@link emplace} - * - {@link push} - * - *erase* typed events: - * - {@link assign} - * - {@link clear} - * - {@link erase} - * - *refresh* typed events: - * - {@link refresh} - * - * #### [Inherited] {@link HashMultiMap} - * {@link HashMultiMap HashMultiMap}s are associative containers that store elements formed by the combination of - * a *key value* and a *mapped value*, much like {@link HashMultiMap} containers, but allowing different elements - * to have equivalent *keys*. - * - * In an {@link HashMultiMap}, the *key value* is generally used to uniquely identify the element, while the - * *mapped value* is an object with the content associated to this *key*. Types of *key* and *mapped value* may - * differ. - * - * Internally, the elements in the {@link HashMultiMap} are not sorted in any particular order with respect to - * either their *key* or *mapped values*, but organized into *buckets* depending on their hash values to allow for - * fast access to individual elements directly by their *key values* (with a constant average time complexity on - * average). - * - * Elements with equivalent *keys* are grouped together in the same bucket and in such a way that an iterator can - * iterate through all of them. Iterators in the container are doubly linked iterators. - * - * - * - * - * - *

Container properties

- *
- *
Associative
- *
Elements in associative containers are referenced by their *key* and not by their absolute - * position in the container.
- * - *
Hashed
- *
Hashed containers organize their elements using hash tables that allow for fast access to elements - * by their *key*.
- * - *
Map
- *
Each element associates a *key* to a *mapped value*: - * *Keys* are meant to identify the elements whose main content is the *mapped value*.
- * - *
Multiple equivalent keys
- *
The container can hold multiple elements with equivalent *keys*.
- *
- * - * @param Type of the key values. - * Each element in an {@link HashMultiMap} is identified by a key value. - * @param Type of the mapped value. - * Each element in an {@link HashMultiMap} is used to store some data as its mapped value. - * - * @reference http://www.cplusplus.com/reference/unordered_map/unordered_multimap - * @handbook [Collections](https://github.com/samchon/framework/wiki/TypeScript-STL#collections) - * @author Jeongho Nam - */ - class HashMultiMapCollection extends std.HashMap implements ICollection> { - /** - * A chain object taking responsibility of dispatching events. - */ - private event_dispatcher_; - /** - * @inheritdoc - */ - protected _Handle_insert(first: std.MapIterator, last: std.MapIterator): void; - /** - * @inheritdoc - */ - protected _Handle_erase(first: std.MapIterator, last: std.MapIterator): void; - /** - * @inheritdoc - */ - hasEventListener(type: string): boolean; - /** - * @inheritdoc - */ - dispatchEvent(event: library.BasicEvent): boolean; - /** - * @inheritdoc - */ - refresh(): void; - /** - * @inheritdoc - */ - refresh(it: std.MapIterator): void; - /** - * @inheritdoc - */ - refresh(first: std.MapIterator, last: std.MapIterator): void; - /** - * @inheritdoc - */ - addEventListener(type: string, listener: library.BasicEventListener): void; - addEventListener(type: "insert", listener: MapCollectionEventListener): void; - addEventListener(type: "erase", listener: MapCollectionEventListener): void; - addEventListener(type: "refresh", listener: MapCollectionEventListener): void; - /** - * @inheritdoc - */ - addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - addEventListener(type: "insert", listener: MapCollectionEventListener, thisArg: Object): void; - addEventListener(type: "erase", listener: MapCollectionEventListener, thisArg: Object): void; - addEventListener(type: "refresh", listener: MapCollectionEventListener, thisArg: Object): void; - /** - * @inheritdoc - */ - removeEventListener(type: string, listener: library.BasicEventListener): void; - removeEventListener(type: "insert", listener: MapCollectionEventListener): void; - removeEventListener(type: "erase", listener: MapCollectionEventListener): void; - removeEventListener(type: "refresh", listener: MapCollectionEventListener): void; - /** - * @inheritdoc - */ - removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - removeEventListener(type: "insert", listener: MapCollectionEventListener, thisArg: Object): void; - removeEventListener(type: "erase", listener: MapCollectionEventListener, thisArg: Object): void; - removeEventListener(type: "refresh", listener: MapCollectionEventListener, thisArg: Object): void; - } -} -declare namespace samchon.collections { - /** - * A {@link HashMultiSet} who can detect element I/O events. - * - * Below is the list of methods who are dispatching {@link CollectionEvent}: - * - *insert* typed events: - * - {@link assign} - * - {@link insert} - * - {@link push} - * - *erase* typed events: - * - {@link assign} - * - {@link clear} - * - {@link erase} - * - *refresh* typed events: - * - {@link refresh} - * - * #### [Inherited] {@link HashMultiSet} - * {@link HashMultiSet HashMultiSets} are containers that store elements in no particular order, allowing fast - * retrieval of individual elements based on their value, much like {@link HashMultiSet} containers, but allowing - * different elements to have equivalent values. - * - * In an {@link HashMultiSet}, the value of an element is at the same time its *key*, used to identify it. *Keys* - * are immutable, therefore, the elements in an {@link HashMultiSet} cannot be modified once in the container - - * they can be inserted and removed, though. - * - * Internally, the elements in the {@link HashMultiSet} are not sorted in any particular, but organized into - * *buckets* depending on their hash values to allow for fast access to individual elements directly by their - * *values* (with a constant average time complexity on average). - * - * Elements with equivalent values are grouped together in the same bucket and in such a way that an iterator can - * iterate through all of them. Iterators in the container are doubly linked iterators. - * - * - * - * - * - *

Container properties

- *
- *
Associative
- *
Elements in associative containers are referenced by their *key* and not by their absolute - * position in the container.
- * - *
Hashed
- *
Hashed containers organize their elements using hash tables that allow for fast access to elements - * by their *key*.
- * - *
Set
- *
The value of an element is also the *key* used to identify it.
- * - *
Multiple equivalent keys
- *
The container can hold multiple elements with equivalent *keys*.
- *
- * - * @param Type of the elements. - * Each element in an {@link UnorderedMultiSet} is also identified by this value.. - * - * @reference http://www.cplusplus.com/reference/unordered_set/unordered_multiset - * @handbook [Collections](https://github.com/samchon/framework/wiki/TypeScript-STL#collections) - * @author Jeongho Nam - */ - class HashMultiSetCollection extends std.HashMultiSet implements ICollection { - /** - * A chain object taking responsibility of dispatching events. - */ - private event_dispatcher_; - /** - * @inheritdoc - */ - protected _Handle_insert(first: std.SetIterator, last: std.SetIterator): void; - /** - * @inheritdoc - */ - protected _Handle_erase(first: std.SetIterator, last: std.SetIterator): void; - /** - * @inheritdoc - */ - hasEventListener(type: string): boolean; - /** - * @inheritdoc - */ - dispatchEvent(event: library.BasicEvent): boolean; - /** - * @inheritdoc - */ - refresh(): void; - /** - * @inheritdoc - */ - refresh(it: std.SetIterator): void; - /** - * @inheritdoc - */ - refresh(first: std.SetIterator, last: std.SetIterator): void; - /** - * @inheritdoc - */ - addEventListener(type: string, listener: library.BasicEventListener): void; - addEventListener(type: "insert", listener: CollectionEventListener): void; - addEventListener(type: "erase", listener: CollectionEventListener): void; - addEventListener(type: "refresh", listener: CollectionEventListener): void; - /** - * @inheritdoc - */ - addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - addEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; - addEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; - addEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; - /** - * @inheritdoc - */ - removeEventListener(type: string, listener: library.BasicEventListener): void; - removeEventListener(type: "insert", listener: CollectionEventListener): void; - removeEventListener(type: "erase", listener: CollectionEventListener): void; - removeEventListener(type: "refresh", listener: CollectionEventListener): void; - /** - * @inheritdoc - */ - removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - removeEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; - removeEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; - removeEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; - } -} -declare namespace samchon.collections { - /** - * A {@link HashSet} who can detect element I/O events. - * - * Below is the list of methods who are dispatching {@link CollectionEvent}: - * - *insert* typed events: - * - {@link assign} - * - {@link insert} - * - {@link push} - * - {@link insert_or_assign} - * - *erase* typed events: - * - {@link assign} - * - {@link clear} - * - {@link erase} - * - {@link extract} - * - *refresh* typed events: - * - {@link refresh} - * - * #### [Inherited] {@link HashSet} - * {@link HashSet HashSets} are containers that store unique elements in no particular order, and which allow for - * fast retrieval of individual elements based on their value. - * - * In an {@link HashSet}, the value of an element is at the same time its *key*, that identifies it uniquely. - * Keys are immutable, therefore, the elements in an {@link HashSet} cannot be modified once in the container - - * they can be inserted and removed, though. - * - * Internally, the elements in the {@link HashSet} are not sorted in any particular order, but organized into - * buckets depending on their hash values to allow for fast access to individual elements directly by their - * *values* (with a constant average time complexity on average). - * - * {@link HashSet} containers are faster than {@link TreeSet} containers to access individual elements by their - * *key*, although they are generally less efficient for range iteration through a subset of their elements. - * - * - * - * - * - *

Container properties

- *
- *
Associative
- *
Elements in associative containers are referenced by their *key* and not by their absolute - * position in the container.
- * - *
Hashed
- *
Hashed containers organize their elements using hash tables that allow for fast access to elements - * by their *key*.
- * - *
Set
- *
The value of an element is also the *key* used to identify it.
- * - *
Unique keys
- *
No two elements in the container can have equivalent *keys*.
- *
- * - * @param Type of the elements. - * Each element in an {@link HashSet} is also uniquely identified by this value. - * - * @reference http://www.cplusplus.com/reference/unordered_set/unordered_set - * @handbook [Collections](https://github.com/samchon/framework/wiki/TypeScript-STL#collections) - * @author Jeongho Nam - */ - class HashSetCollection extends std.HashSet implements ICollection { - /** - * A chain object taking responsibility of dispatching events. - */ - private event_dispatcher_; - /** - * @inheritdoc - */ - protected _Handle_insert(first: std.SetIterator, last: std.SetIterator): void; - /** - * @inheritdoc - */ - protected _Handle_erase(first: std.SetIterator, last: std.SetIterator): void; - /** - * @inheritdoc - */ - hasEventListener(type: string): boolean; - /** - * @inheritdoc - */ - dispatchEvent(event: library.BasicEvent): boolean; - /** - * @inheritdoc - */ - refresh(): void; - /** - * @inheritdoc - */ - refresh(it: std.SetIterator): void; - /** - * @inheritdoc - */ - refresh(first: std.SetIterator, last: std.SetIterator): void; - /** - * @inheritdoc - */ - addEventListener(type: string, listener: library.BasicEventListener): void; - addEventListener(type: "insert", listener: CollectionEventListener): void; - addEventListener(type: "erase", listener: CollectionEventListener): void; - addEventListener(type: "refresh", listener: CollectionEventListener): void; - /** - * @inheritdoc - */ - addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - addEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; - addEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; - addEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; - /** - * @inheritdoc - */ - removeEventListener(type: string, listener: library.BasicEventListener): void; - removeEventListener(type: "insert", listener: CollectionEventListener): void; - removeEventListener(type: "erase", listener: CollectionEventListener): void; - removeEventListener(type: "refresh", listener: CollectionEventListener): void; - /** - * @inheritdoc - */ - removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - removeEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; - removeEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; - removeEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; - } -} -/** - * Collections, elements I/O detectable STL containers. - * - * STL Containers | Collections - * ---------------------|------------------- - * {@link Vector} | {@link ArrayCollection} - * {@link List} | {@link ListCollection} - * {@link Deque} | {@link DequeCollection} - * | - * {@link TreeSet} | {@link TreeSetCollection} - * {@link HashSet} | {@link HashSetCollection} - * {@link TreeMultiSet} | {@link TreeMultiSetCollection} - * {@link HashMultiSet} | {@link HashMultiSetCollection} - * | - * {@link TreeMap} | {@link TreeMapCollection} - * {@link HashMap} | {@link HashMapCollection} - * {@link TreeMultiMap} | {@link TreeMultiMapCollection} - * {@link HashMultiMap} | {@link HashMultiMapCollection} - * - * @author Jeongho Nam - */ -declare namespace samchon.collections { - /** - * An interface for {@link IContainer containers} who can detect element I/O events. - * - * Below are list of methods who are dispatching {@link CollectionEvent}: - * - *insert* typed events: - * - {@link assign} - * - {@link insert} - * - {@link push} - * - *erase* typed events: - * - {@link assign} - * - {@link clear} - * - {@link erase} - * - *refresh* typed events: - * - {@link refresh} - * - * @author Jeongho Nam - */ - interface ICollection extends std.base.IContainer, library.IEventDispatcher { - /** - * Dispatch a {@link CollectionEvent} with *refresh* typed. - * - * {@link ICollection} dispatches {@link CollectionEvent} typed *insert* or *erase* whenever elements I/O has - * occured. However, unlike those elements I/O events, content change in element level can't be detected. - * There's no way to detect those events automatically by {@link IContainer}. - * - * If you want to dispatch those typed events (notifying change on contents in element level), you've to - * dispatch *refresh* typed event manually, by yourself. Call {@link refresh refresh()} with specified - * iterators who're pointing the elements whose content have changed. Then a {@link CollectionEvent} with - * *refresh* typed will be dispatched. - * - * If you don't specify any iterator, then the range of the *refresh* event will be all elements in this - * {@link ICollection collection}; {@link begin begin()} to {@link end end()}. - */ - refresh(): void; - /** - * Dispatch a {@link CollectionEvent} with *refresh* typed. - * - * {@link ICollection} dispatches {@link CollectionEvent} typed *insert* or *erase* whenever elements I/O has - * occured. However, unlike those elements I/O events, content change in element level can't be detected. - * There's no way to detect those events automatically by {@link IContainer}. - * - * If you want to dispatch those typed events (notifying change on contents in element level), you've to - * dispatch *refresh* typed event manually, by yourself. Call {@link refresh refresh()} with specified - * iterators who're pointing the elements whose content have changed. Then a {@link CollectionEvent} with - * *refresh* typed will be dispatched. - * - * @param it An iterator targeting the content changed element. - */ - refresh(it: std.Iterator): void; - /** - * Dispatch a {@link CollectionEvent} with *refresh* typed. - * - * {@link ICollection} dispatches {@link CollectionEvent} typed *insert* or *erase* whenever elements I/O has - * occured. However, unlike those elements I/O events, content change in element level can't be detected. - * There's no way to detect those events automatically by {@link IContainer}. - * - * If you want to dispatch those typed events (notifying change on contents in element level), you've to - * dispatch *refresh* typed event manually, by yourself. Call {@link refresh refresh()} with specified - * iterators who're pointing the elements whose content have changed. Then a {@link CollectionEvent} with - * *refresh* typed will be dispatched. - * - * @param first An Iterator to the initial position in a sequence of the content changed elmeents. - * @param last An {@link Iterator} to the final position in a sequence of the content changed elements. The range - * used is [*first*, *last*), which contains all the elements between *first* and - * *last*, including the element pointed by *first* but not the element pointed by - * *last*. - */ - refresh(first: std.Iterator, last: std.Iterator): void; - /** - * @inheritdoc - */ - addEventListener(type: string, listener: library.BasicEventListener): void; - addEventListener(type: "insert", listener: CollectionEventListener): void; - addEventListener(type: "erase", listener: CollectionEventListener): void; - addEventListener(type: "refresh", listener: CollectionEventListener): void; - /** - * @inheritdoc - */ - addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - addEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; - addEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; - addEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; - /** - * @inheritdoc - */ - removeEventListener(type: string, listener: library.BasicEventListener): void; - removeEventListener(type: "insert", listener: CollectionEventListener): void; - removeEventListener(type: "erase", listener: CollectionEventListener): void; - removeEventListener(type: "refresh", listener: CollectionEventListener): void; - /** - * @inheritdoc - */ - removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - removeEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; - removeEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; - removeEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; - } - /** - * @hidden - */ - namespace ICollection { - /** - * @hidden - */ - function _Dispatch_CollectionEvent(collection: ICollection, type: string, first: std.Iterator, last: std.Iterator): void; - /** - * @hidden - */ - function _Dispatch_MapCollectionEvent(collection: ICollection>, type: string, first: std.MapIterator, last: std.MapIterator): void; - } -} -declare namespace samchon.collections { - /** - * A {@link List} who can detect element I/O events. - * - * Below is the list of methods who are dispatching {@link CollectionEvent}: - * - *insert* typed events: - * - {@link assign} - * - {@link insert} - * - {@link push} - * - {@link push_front} - * - {@link push_back} - * - {@link merge} - * - *erase* typed events: - * - {@link assign} - * - {@link clear} - * - {@link erase} - * - {@link pop_front} - * - {@link pop_back} - * - {@link unique} - * - {@link remove} - * - {@link remove_if} - * - {@link splice} - * - *refresh* typed events: - * - {@link refresh} - * - {@link sort} - * - * #### [Inherited] {@link List} - * {@link List Lists} are sequence containers that allow constant time insert and erase operations anywhere within - * the sequence, and iteration in both directions. - * - * List containers are implemented as doubly-linked lists; Doubly linked lists can store each of the elements they - * contain in different and unrelated storage locations. The ordering is kept internally by the association to - * each element of a link to the element preceding it and a link to the element following it. - * - * They are very similar to forward_list: The main difference being that forward_list objects are single-linked - * lists, and thus they can only be iterated forwards, in exchange for being somewhat smaller and more efficient. - * - * Compared to other base standard sequence containers (array, vector and deque), lists perform generally better - * in inserting, extracting and moving elements in any position within the container for which an iterator has - * already been obtained, and therefore also in algorithms that make intensive use of these, like sorting - * algorithms. - * - * The main drawback of lists and forward_lists compared to these other sequence containers is that they lack - * direct access to the elements by their position; For example, to access the sixth element in a list, one has to - * iterate from a known position (like the beginning or the end) to that position, which takes linear time in the - * distance between these. They also consume some extra memory to keep the linking information associated to each - * element (which may be an important factor for large lists of small-sized elements). - * - * - * - * - * - *

Container properties

- *
- *
Sequence
- *
Elements in sequence containers are ordered in a strict linear sequence. Individual elements are accessed by - * their position in this sequence.
- * - *
Doubly-linked list
- *
Each element keeps information on how to locate the next and the previous elements, allowing constant time - * insert and erase operations before or after a specific element (even of entire ranges), but no direct random - * access.
- *
- * - * @param Type of the elements. - * - * @reference http://www.cplusplus.com/reference/list/list/ - * @handbook [Collections](https://github.com/samchon/framework/wiki/TypeScript-STL#collections) - * @author Jeongho Nam - */ - class ListCollection extends std.List implements ICollection { - /** - * A chain object taking responsibility of dispatching events. - */ - private event_dispatcher_; - /** - * @inheritdoc - */ - push(...items: T[]): number; - /** - * @inheritdoc - */ - push_front(val: T): void; - /** - * @inheritdoc - */ - push_back(val: T): void; - /** - * @hidden - */ - protected _Insert_by_repeating_val(position: std.ListIterator, n: number, val: T): std.ListIterator; - /** - * @hidden - */ - protected _Insert_by_range>(position: std.ListIterator, begin: InputIterator, end: InputIterator): std.ListIterator; - /** - * @inheritdoc - */ - pop_front(): void; - /** - * @inheritdoc - */ - pop_back(): void; - /** - * @hidden - */ - protected _Erase_by_range(first: std.ListIterator, last: std.ListIterator): std.ListIterator; - /** - * @hidden - */ - private notify_insert(first, last); - /** - * @hidden - */ - private notify_erase(first, last); - /** - * @inheritdoc - */ - hasEventListener(type: string): boolean; - /** - * @inheritdoc - */ - dispatchEvent(event: library.BasicEvent): boolean; - /** - * @inheritdoc - */ - refresh(): void; - /** - * @inheritdoc - */ - refresh(it: std.ListIterator): void; - /** - * @inheritdoc - */ - refresh(first: std.ListIterator, last: std.ListIterator): void; - /** - * @inheritdoc - */ - addEventListener(type: string, listener: library.BasicEventListener): void; - addEventListener(type: "insert", listener: CollectionEventListener): void; - addEventListener(type: "erase", listener: CollectionEventListener): void; - addEventListener(type: "refresh", listener: CollectionEventListener): void; - /** - * @inheritdoc - */ - addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - addEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; - addEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; - addEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; - /** - * @inheritdoc - */ - removeEventListener(type: string, listener: library.BasicEventListener): void; - removeEventListener(type: "insert", listener: CollectionEventListener): void; - removeEventListener(type: "erase", listener: CollectionEventListener): void; - removeEventListener(type: "refresh", listener: CollectionEventListener): void; - /** - * @inheritdoc - */ - removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - removeEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; - removeEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; - removeEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; - } -} -declare namespace samchon.collections { - type MapCollectionEventListener = (event: MapCollectionEvent) => void; - /** - * An event occured in a {@link MapContainer map container} object. - * - * @handbook [Collections](https://github.com/samchon/framework/wiki/TypeScript-STL#collections) - * @author Jeongho Nam - */ - class MapCollectionEvent extends CollectionEvent> { - /** - * @inheritdoc - */ - readonly first: std.MapIterator; - /** - * @inheritdoc - */ - readonly last: std.MapIterator; - } -} -declare namespace samchon.collections { - /** - * A {@link TreeMap} who can detect element I/O events. - * - * Below is the list of methods who are dispatching {@link MapCollectionEvent}: - * - *insert* typed events: - * - {@link assign} - * - {@link insert} - * - {@link insert_or_assign} - * - {@link emplace} - * - {@link set} - * - {@link push} - * - *erase* typed events: - * - {@link assign} - * - {@link clear} - * - {@link erase} - * - {@link extract} - * - *refresh* typed events: - * - {@link refresh} - * - * #### [Inherited] {@link TreeMap} - * {@link TreeMap TreeMaps} are associative containers that store elements formed by a combination of a - * *key value* (*Key*) and a *mapped value* (*T*), following order. - * - * In a {@link TreeMap}, the *key values* are generally used to sort and uniquely identify the elements, while the - * *mapped values* store the content associated to this key. The types of *key* and *mapped value* may differ, and - * are grouped together in member type *value_type*, which is a {@link Pair} type combining both: - * - * ```typedef Pair value_type;``` - * - * Internally, the elements in a {@link TreeMap} are always sorted by its *key* following a *strict weak ordering* - * criterion indicated by its internal comparison method {@link less}. - * - * {@link TreeMap} containers are generally slower than {@link HashMap HashMap} containers to access individual - * elements by their *key*, but they allow the direct iteration on subsets based on their order. - * - * {@link TreeMap}s are typically implemented as binary search trees. - * - * - * - * - * - *

Container properties

- *
- *
Associative
- *
Elements in associative containers are referenced by their *key* and not by their absolute - * position in the container.
- * - *
Ordered
- *
The elements in the container follow a strict order at all times. All inserted elements are - * given a position in this order.
- * - *
Map
- *
Each element associates a *key* to a *mapped value*: - * *Keys* are meant to identify the elements whose main content is the *mapped value*.
- * - *
Unique keys
- *
No two elements in the container can have equivalent *keys*.
- *
- * - * @param Type of the keys. Each element in a map is uniquely identified by its key value. - * @param Type of the mapped value. Each element in a map stores some data as its mapped value. - * - * @reference http://www.cplusplus.com/reference/map/map - * @handbook [Collections](https://github.com/samchon/framework/wiki/TypeScript-STL#collections) - * @author Jeongho Nam - */ - class TreeMapCollection extends std.TreeMap implements ICollection> { - /** - * A chain object taking responsibility of dispatching events. - */ - private event_dispatcher_; - /** - * @inheritdoc - */ - protected _Handle_insert(first: std.MapIterator, last: std.MapIterator): void; - /** - * @inheritdoc - */ - protected _Handle_erase(first: std.MapIterator, last: std.MapIterator): void; - /** - * @inheritdoc - */ - hasEventListener(type: string): boolean; - /** - * @inheritdoc - */ - dispatchEvent(event: library.BasicEvent): boolean; - /** - * @inheritdoc - */ - refresh(): void; - /** - * @inheritdoc - */ - refresh(it: std.MapIterator): void; - /** - * @inheritdoc - */ - refresh(first: std.MapIterator, last: std.MapIterator): void; - /** - * @inheritdoc - */ - addEventListener(type: string, listener: library.BasicEventListener): void; - addEventListener(type: "insert", listener: MapCollectionEventListener): void; - addEventListener(type: "erase", listener: MapCollectionEventListener): void; - addEventListener(type: "refresh", listener: MapCollectionEventListener): void; - /** - * @inheritdoc - */ - addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - addEventListener(type: "insert", listener: MapCollectionEventListener, thisArg: Object): void; - addEventListener(type: "erase", listener: MapCollectionEventListener, thisArg: Object): void; - addEventListener(type: "refresh", listener: MapCollectionEventListener, thisArg: Object): void; - /** - * @inheritdoc - */ - removeEventListener(type: string, listener: library.BasicEventListener): void; - removeEventListener(type: "insert", listener: MapCollectionEventListener): void; - removeEventListener(type: "erase", listener: MapCollectionEventListener): void; - removeEventListener(type: "refresh", listener: MapCollectionEventListener): void; - /** - * @inheritdoc - */ - removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - removeEventListener(type: "insert", listener: MapCollectionEventListener, thisArg: Object): void; - removeEventListener(type: "erase", listener: MapCollectionEventListener, thisArg: Object): void; - removeEventListener(type: "refresh", listener: MapCollectionEventListener, thisArg: Object): void; - } -} -declare namespace samchon.collections { - /** - * A {@link TreeMultiMap} who can detect element I/O events. - * - * Below is the list of methods who are dispatching {@link MapCollectionEvent}: - * - *insert* typed events: - * - {@link assign} - * - {@link insert} - * - {@link emplace} - * - {@link push} - * - *erase* typed events: - * - {@link assign} - * - {@link clear} - * - {@link erase} - * - *refresh* typed events: - * - {@link refresh} - * - * #### [Inherited] {@link TreeMultiMap} - * {@link TreeMultiMap TreeMultiMaps} are associative containers that store elements formed by a combination of a - * *key value* and a *mapped value*, following a specific order, and where multiple elements can have equivalent - * keys. - * - * In a {@link TreeMultiMap}, the *key values* are generally used to sort and uniquely identify the elements, - * while the *mapped values* store the content associated to this *key*. The types of *key* and *mapped value* may - * differ, and are grouped together in member type ```value_type```, which is a {@link Pair} type combining both: - * - * ```typedef Pair value_type;``` - * - * Internally, the elements in a {@link TreeMultiMap}are always sorted by its key following a strict weak ordering - * criterion indicated by its internal comparison method (of {@link less}). - * - * {@link TreeMultiMap}containers are generally slower than {@link HashMap} containers to access individual - * elements by their *key*, but they allow the direct iteration on subsets based on their order. - * - * {@link TreeMultiMap TreeMultiMaps} are typically implemented as binary search trees. - * - * < - * img src="http://samchon.github.io/typescript-stl/images/design/class_diagram/map_containers.png" style="max-width: 100%" /> - * - * - *

Container properties

- *
- *
Associative
- *
- * Elements in associative containers are referenced by their *key* and not by their absolute - * position in the container. - *
- * - *
Ordered
- *
- * The elements in the container follow a strict order at all times. All inserted elements are - * given a position in this order. - *
- * - *
Map
- *
- * Each element associates a *key* to a *mapped value*: - * *Keys* are meant to identify the elements whose main content is the *mapped value*. - *
- * - *
Multiple equivalent keys
- *
Multiple elements in the container can have equivalent *keys*.
- *
- * - * @param Type of the keys. Each element in a map is uniquely identified by its key value. - * @param Type of the mapped value. Each element in a map stores some data as its mapped value. - * - * @reference http://www.cplusplus.com/reference/map/multimap - * @handbook [Collections](https://github.com/samchon/framework/wiki/TypeScript-STL#collections) - * @author Jeongho Nam - */ - class TreeMultiMapCollection extends std.TreeMultiMap implements ICollection> { - /** - * A chain object taking responsibility of dispatching events. - */ - private event_dispatcher_; - /** - * @inheritdoc - */ - protected _Handle_insert(first: std.MapIterator, last: std.MapIterator): void; - /** - * @inheritdoc - */ - protected _Handle_erase(first: std.MapIterator, last: std.MapIterator): void; - /** - * @inheritdoc - */ - hasEventListener(type: string): boolean; - /** - * @inheritdoc - */ - dispatchEvent(event: library.BasicEvent): boolean; - /** - * @inheritdoc - */ - refresh(): void; - /** - * @inheritdoc - */ - refresh(it: std.MapIterator): void; - /** - * @inheritdoc - */ - refresh(first: std.MapIterator, last: std.MapIterator): void; - /** - * @inheritdoc - */ - addEventListener(type: string, listener: library.BasicEventListener): void; - addEventListener(type: "insert", listener: MapCollectionEventListener): void; - addEventListener(type: "erase", listener: MapCollectionEventListener): void; - addEventListener(type: "refresh", listener: MapCollectionEventListener): void; - /** - * @inheritdoc - */ - addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - addEventListener(type: "insert", listener: MapCollectionEventListener, thisArg: Object): void; - addEventListener(type: "erase", listener: MapCollectionEventListener, thisArg: Object): void; - addEventListener(type: "refresh", listener: MapCollectionEventListener, thisArg: Object): void; - /** - * @inheritdoc - */ - removeEventListener(type: string, listener: library.BasicEventListener): void; - removeEventListener(type: "insert", listener: MapCollectionEventListener): void; - removeEventListener(type: "erase", listener: MapCollectionEventListener): void; - removeEventListener(type: "refresh", listener: MapCollectionEventListener): void; - /** - * @inheritdoc - */ - removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - removeEventListener(type: "insert", listener: MapCollectionEventListener, thisArg: Object): void; - removeEventListener(type: "erase", listener: MapCollectionEventListener, thisArg: Object): void; - removeEventListener(type: "refresh", listener: MapCollectionEventListener, thisArg: Object): void; - } -} -declare namespace samchon.collections { - /** - * A {@link TreeMultiSet} who can detect element I/O events. - * - * Below is the list of methods who are dispatching {@link CollectionEvent}: - * - *insert* typed events: - * - {@link assign} - * - {@link insert} - * - {@link push} - * - *erase* typed events: - * - {@link assign} - * - {@link clear} - * - {@link erase} - * - *refresh* typed events: - * - {@link refresh} - * - * #### [Inherited] {@link TreeMultiSet} - * {@link TreeMultiSet TreeMultiSets} are containers that store elements following a specific order, and where - * multiple elements can have equivalent values. - * - * In a {@link TreeMultiSet}, the value of an element also identifies it (the value is itself the *key*, of type - * *T*). The value of the elements in a {@link TreeMultiSet} cannot be modified once in the container (the - * elements are always const), but they can be inserted or removed from the container. - * - * Internally, the elements in a {@link TreeMultiSet TreeMultiSets} are always sorted following a strict weak - * ordering criterion indicated by its internal comparison method (of {@link IComparable.less less}). - * - * {@link TreeMultiSet} containers are generally slower than {@link HashMultiSet} containers to access individual - * elements by their *key*, but they allow the direct iteration on subsets based on their order. - * - *

{@link TreeMultiSet TreeMultiSets} are typically implemented as binary search trees.

- * - *

- *

- * - *

Container properties

- *
- *
Associative
- *
- * Elements in associative containers are referenced by their *key* and not by their absolute - * position in the container. - *
- * - *
Ordered
- *
- * The elements in the container follow a strict order at all times. All inserted elements are - * given a position in this order. - *
- * - *
Set
- *
The value of an element is also the *key* used to identify it.
- * - *
Multiple equivalent keys
- *
Multiple elements in the container can have equivalent *keys*.
- *
- * - * @param Type of the elements. Each element in a {@link TreeMultiSet} container is also identified - * by this value (each value is itself also the element's *key*). - * - * @reference http://www.cplusplus.com/reference/set/multiset - * @handbook [Collections](https://github.com/samchon/framework/wiki/TypeScript-STL#collections) - * @author Jeongho Nam - */ - class TreeMultiSetCollection extends std.TreeMultiSet implements ICollection { - /** - * A chain object taking responsibility of dispatching events. - */ - private event_dispatcher_; - /** - * @inheritdoc - */ - protected _Handle_insert(first: std.SetIterator, last: std.SetIterator): void; - /** - * @inheritdoc - */ - protected _Handle_erase(first: std.SetIterator, last: std.SetIterator): void; - /** - * @inheritdoc - */ - hasEventListener(type: string): boolean; - /** - * @inheritdoc - */ - dispatchEvent(event: library.BasicEvent): boolean; - /** - * @inheritdoc - */ - refresh(): void; - /** - * @inheritdoc - */ - refresh(it: std.SetIterator): void; - /** - * @inheritdoc - */ - refresh(first: std.SetIterator, last: std.SetIterator): void; - /** - * @inheritdoc - */ - addEventListener(type: string, listener: library.BasicEventListener): void; - addEventListener(type: "insert", listener: CollectionEventListener): void; - addEventListener(type: "erase", listener: CollectionEventListener): void; - addEventListener(type: "refresh", listener: CollectionEventListener): void; - /** - * @inheritdoc - */ - addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - addEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; - addEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; - addEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; - /** - * @inheritdoc - */ - removeEventListener(type: string, listener: library.BasicEventListener): void; - removeEventListener(type: "insert", listener: CollectionEventListener): void; - removeEventListener(type: "erase", listener: CollectionEventListener): void; - removeEventListener(type: "refresh", listener: CollectionEventListener): void; - /** - * @inheritdoc - */ - removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - removeEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; - removeEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; - removeEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; - } -} -declare namespace samchon.collections { - /** - * A {@link TreeMap} who can detect element I/O events. - * - * Below is the list of methods who are dispatching {@link CollectionEvent}: - * - *insert* typed events: - * - {@link assign} - * - {@link insert} - * - {@link insert_or_assign} - * - {@link push} - * - *erase* typed events: - * - {@link assign} - * - {@link clear} - * - {@link erase} - * - {@link extract} - * - *refresh* typed events: - * - {@link refresh} - * - * #### [Inherited] {@link TreeSet} - * {@link TreeSet TreeSets} are containers that store unique elements following a specific order. - * - * In a {@link TreeSet}, the value of an element also identifies it (the value is itself the *key*, of type *T*), - * and each value must be unique. The value of the elements in a {@link TreeSet} cannot be modified once in the - * container (the elements are always const), but they can be inserted or removed from the container. - * - * Internally, the elements in a {@link TreeSet} are always sorted following a specific strict weak ordering - * criterion indicated by its internal comparison method (of {@link less}). - * - * {@link TreeSet} containers are generally slower than {@link HashSet} containers to access individual elements - * by their *key*, but they allow the direct iteration on subsets based on their order. - * - * {@link TreeSet}s are typically implemented as binary search trees. - * - * - * - * - * - *

Container properties

- *
- *
Associative
- *
- * Elements in associative containers are referenced by their *key* and not by their absolute - * position in the container. - *
- * - *
Ordered
- *
- * The elements in the container follow a strict order at all times. All inserted elements are - * given a position in this order. - *
- * - *
Set
- *
The value of an element is also the *key* used to identify it.
- * - *
Unique keys
- *
No two elements in the container can have equivalent *keys*.
- *
- * - * @param Type of the elements. - * Each element in an {@link TreeSet} is also uniquely identified by this value. - * - * @reference http://www.cplusplus.com/reference/set/set - * @handbook [Collections](https://github.com/samchon/framework/wiki/TypeScript-STL#collections) - * @author Jeongho Nam - */ - class TreeSetCollection extends std.TreeSet implements ICollection { - /** - * A chain object taking responsibility of dispatching events. - */ - private event_dispatcher_; - /** - * @inheritdoc - */ - protected _Handle_insert(first: std.SetIterator, last: std.SetIterator): void; - /** - * @inheritdoc - */ - protected _Handle_erase(first: std.SetIterator, last: std.SetIterator): void; - /** - * @inheritdoc - */ - hasEventListener(type: string): boolean; - /** - * @inheritdoc - */ - dispatchEvent(event: library.BasicEvent): boolean; - /** - * @inheritdoc - */ - refresh(): void; - /** - * @inheritdoc - */ - refresh(it: std.SetIterator): void; - /** - * @inheritdoc - */ - refresh(first: std.SetIterator, last: std.SetIterator): void; - /** - * @inheritdoc - */ - addEventListener(type: string, listener: library.BasicEventListener): void; - addEventListener(type: "insert", listener: CollectionEventListener): void; - addEventListener(type: "erase", listener: CollectionEventListener): void; - addEventListener(type: "refresh", listener: CollectionEventListener): void; - /** - * @inheritdoc - */ - addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - addEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; - addEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; - addEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; - /** - * @inheritdoc - */ - removeEventListener(type: string, listener: library.BasicEventListener): void; - removeEventListener(type: "insert", listener: CollectionEventListener): void; - removeEventListener(type: "erase", listener: CollectionEventListener): void; - removeEventListener(type: "refresh", listener: CollectionEventListener): void; - /** - * @inheritdoc - */ - removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - removeEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; - removeEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; - removeEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; - } -} -declare namespace samchon.library { - /** - * Case generator. - * - * {@link CaseGenerator} is an abstract case generator being used like a matrix. - *
    - *
  • n��r(n^r) -> {@link CombinedPermutationGenerator}
  • - *
  • nPr -> {@link PermutationGenerator}
  • - *
  • n! -> {@link FactorialGenerator}
  • - *
- * - * @author Jeongho Nam - */ - abstract class CaseGenerator { - /** - * Size, the number of all cases. - */ - protected size_: number; - /** - * N, size of the candidates. - */ - protected n_: number; - /** - * R, size of elements of each case. - */ - protected r_: number; - /** - * Construct from size of N and R. - * - * @param n Size of candidates. - * @param r Size of elements of each case. - */ - constructor(n: number, r: number); - /** - * Get size of all cases. - * - * @return Get a number of the all cases. - */ - size(): number; - /** - * Get size of the N. - */ - n(): number; - /** - * Get size of the R. - */ - r(): number; - /** - * Get index'th case. - * - * @param index Index number - * @return The row of the index'th in combined permuation case - */ - abstract at(index: number): number[]; - } - /** - * A combined-permutation case generator. - * - * n��r - * - * @author Jeongho Nam - */ - class CombinedPermutationGenerator extends CaseGenerator { - /** - * An array using for dividing each element index. - */ - private divider_array; - /** - * Construct from size of N and R. - * - * @param n Size of candidates. - * @param r Size of elements of each case. - */ - constructor(n: number, r: number); - at(index: number): number[]; - } - /** - * A permutation case generator. - * - * nPr - * - * @author Jeongho Nam - */ - class PermuationGenerator extends CaseGenerator { - /** - * Construct from size of N and R. - * - * @param n Size of candidates. - * @param r Size of elements of each case. - */ - constructor(n: number, r: number); - /** - * @inheritdoc - */ - at(index: number): number[]; - } - /** - * Factorial case generator. - * - * n! = nPn - * - * @author Jeongho Nam - */ - class FactorialGenerator extends PermuationGenerator { - /** - * Construct from factorial size N. - * - * @param n Factoria size N. - */ - constructor(n: number); - } -} -declare namespace samchon.library { - type BasicEventListener = (event: BasicEvent) => void; - /** - * The IEventDispatcher interface defines methods for adding or removing event listeners, checks whether specific - * types of event listeners are registered, and dispatches events. - * - * The event target serves as the local point for how events flow through the display list hierarchy. When an - * event such as a mouse click or a key press occurs, an event object is dispatched into the event flow from the - * root of the display list. The event object makes a round-trip journey to the event target, which is - * conceptually divided into three phases: the capture phase includes the journey from the root to the last node - * before the event target's node; the target phase includes only the event target node; and the bubbling phase - * includes any subsequent nodes encountered on the return trip to the root of the display list. - * - * In general, the easiest way for a user-defined class to gain event dispatching capabilities is to extend - * {@link EventDispatcher}. If this is impossible (that is, if the class is already extending another class), you - * can instead implement the {@link IEventDispatcher} interface, create an {@link EventDispatcher} member, and - * write simple hooks to route calls into the aggregated {@link EventDispatcher}. - * - * @reference http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/IEventDispatcher.html - * @handbook https://github.com/samchon/framework/wiki/TypeScript-Library-EventDispatcher - * @author Migrated by Jeongho Nam - */ - interface IEventDispatcher { - /** - * Checks whether the {@link EventDispatcher} object has any listeners registered for a specific type of event. - * This allows you to determine where an {@link EventDispatcher} object has altered handling of an event type - * in the event flow hierarchy. To determine whether a specific event type actually triggers an event listener, - * use {@link willTrigger willTrigger()}. - * - * The difference between {@link hasEventListener hasEventListener()} and {@link willTrigger willTrigger()} is - * that {@link hasEventListener} examines only the object to which it belongs, whereas {@link willTrigger} - * examines the entire event flow for the event specified by the type parameter. - * - * @param type The type of event. - */ - hasEventListener(type: string): boolean; - /** - * Dispatches an event into the event flow. - * - * The event target is the {@link EventDispatcher} object upon which the {@link dispatchEvent dispatchEvent()} - * method is called. - * - * @param event The {@link BasicEvent} object that is dispatched into the event flow. If the event is being - * redispatched, a clone of the event is created automatically. After an event is dispatched, its - * target property cannot be changed, so you must create a new copy - * of the event for redispatching to work. - */ - dispatchEvent(event: library.BasicEvent): boolean; - /** - * Registers an event listener object with an {@link EventDispatcher} object so that the listener receives - * notification of an event. You can register event listeners on all nodes in the display list for a specific - * type of event, phase, and priority. - * - * After you successfully register an event listener, you cannot change its priority through additional calls - * to {@link addEventListener addEventListener()|} To change a listener's priority, you must first call - * {@link removeEventListener removeEventListener()}. Then you can register the listener again with the new - * priority level. - * - * Keep in mind that after the listener is registered, subsequent calls to {@link addEventListener} with a - * different type or useCapture value result in the creation of a separate listener registration. For example, - * if you first register a listener with useCapture set to true, it listens only during the capture phase. If - * you call {@link addEventListener} again using the same listener object, but with useCapture set to false, - * you have two separate listeners: one that listens during the capture phase and another that listens during - * the target and bubbling phases. - * - * You cannot register an event listener for only the target phase or the bubbling phase. Those phases are - * coupled during registration because bubbling applies only to the ancestors of the target node. - * - * If you no longer need an event listener, remove it by calling {@link removeEventListener}, or memory - * problems could result. Event listeners are not automatically removed from memory because the garbage - * collector does not remove the listener as long as the dispatching object exists (unless the - * useWeakReference parameter is set to true). - * - * Copying an {@link EventDispatcher} instance does not copy the event listeners attached to it. (If your n - * ewly created node needs an event listener, you must attach the listener after creating the node.) However, - * if you move an {@link EventDispatcher} instance, the event listeners attached to it move along with it. - * - * If the event listener is being registered on a node while an event is also being processed on this node, - * the event listener is not triggered during the current phase but may be triggered during a later phase in - * the event flow, such as the bubbling phase. - * - * If an event listener is removed from a node while an event is being processed on the node, it is still - * triggered by the current actions. After it is removed, the event listener is never invoked again (unless it - * is registered again for future processing). - * - * @param event The type of event. - * @param listener The listener function that processes the event. - * This function must accept an Event object as its only parameter and must return - * nothing. - */ - addEventListener(type: string, listener: library.BasicEventListener): void; - /** - * Registers an event listener object with an {@link EventDispatcher} object so that the listener receives - * notification of an event. You can register event listeners on all nodes in the display list for a specific - * type of event, phase, and priority. - * - * After you successfully register an event listener, you cannot change its priority through additional calls - * to {@link addEventListener addEventListener()|} To change a listener's priority, you must first call - * {@link removeEventListener removeEventListener()}. Then you can register the listener again with the new - * priority level. - * - * Keep in mind that after the listener is registered, subsequent calls to {@link addEventListener} with a - * different type or useCapture value result in the creation of a separate listener registration. For example, - * if you first register a listener with useCapture set to true, it listens only during the capture phase. If - * you call {@link addEventListener} again using the same listener object, but with useCapture set to false, - * you have two separate listeners: one that listens during the capture phase and another that listens during - * the target and bubbling phases. - * - * You cannot register an event listener for only the target phase or the bubbling phase. Those phases are - * coupled during registration because bubbling applies only to the ancestors of the target node. - * - * If you no longer need an event listener, remove it by calling {@link removeEventListener}, or memory - * problems could result. Event listeners are not automatically removed from memory because the garbage - * collector does not remove the listener as long as the dispatching object exists (unless the - * useWeakReference parameter is set to true). - * - * Copying an {@link EventDispatcher} instance does not copy the event listeners attached to it. (If your n - * ewly created node needs an event listener, you must attach the listener after creating the node.) However, - * if you move an {@link EventDispatcher} instance, the event listeners attached to it move along with it. - * - * If the event listener is being registered on a node while an event is also being processed on this node, - * the event listener is not triggered during the current phase but may be triggered during a later phase in - * the event flow, such as the bubbling phase. - * - * If an event listener is removed from a node while an event is being processed on the node, it is still - * triggered by the current actions. After it is removed, the event listener is never invoked again (unless it - * is registered again for future processing). - * - * @param event The type of event. - * @param listener The listener function that processes the event. - * This function must accept an Event object as its only parameter and must return - * nothing. - * @param thisArg The object to be used as the **this** object. - */ - addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - /** - * Removes a listener from the {@link EventDispatcher} object. If there is no matching listener registered - * with the {@link EventDispatcher} object, a call to this method has no effect. - * - * @param type The type of event. - * @param listener The listener object to remove. - */ - removeEventListener(type: string, listener: library.BasicEventListener): void; - /** - * Removes a listener from the {@link EventDispatcher} object. If there is no matching listener registered - * with the {@link EventDispatcher} object, a call to this method has no effect. - * - * @param type The type of event. - * @param listener The listener object to remove. - * @param thisArg The object to be used as the **this** object. - */ - removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - } - /** - * The {@link EventDispatcher} class is the base class for all classes that dispatch events. The - * {@link EventDispatcher} class implements the {@link IEventDispatcher} interface and is the base class for the - * {@link DisplayObject} class. The {@link EventDispatcher} class allows any object on the display list to be an - * event target and as such, to use the methods of the {@link IEventDispatcher} interface. - * - * The event target serves as the local point for how events flow through the display list hierarchy. When an - * event such as a mouse click or a key press occurs, an event object is dispatched into the event flow from the - * root of the display list. The event object makes a round-trip journey to the event target, which is - * conceptually divided into three phases: the capture phase includes the journey from the root to the last node - * before the event target's node; the target phase includes only the event target node; and the bubbling phase - * includes any subsequent nodes encountered on the return trip to the root of the display list. - * - * In general, the easiest way for a user-defined class to gain event dispatching capabilities is to extend - * {@link EventDispatcher}. If this is impossible (that is, if the class is already extending another class), you - * can instead implement the {@link IEventDispatcher} interface, create an {@link EventDispatcher} member, and - * write simple hooks to route calls into the aggregated {@link EventDispatcher}. - * - * @reference http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/EventDispatcher.html - * @author Migrated by Jeongho Nam - */ - class EventDispatcher implements IEventDispatcher { - /** - * @hidden - */ - private event_dispatcher_; - /** - * @hidden - */ - private event_listeners_; - /** - * Default Constructor. - */ - constructor(); - /** - * Construct from the origin event dispatcher. - * - * @param dispatcher The origin object who issuing events. - */ - constructor(dispatcher: IEventDispatcher); - /** - * @inheritdoc - */ - hasEventListener(type: string): boolean; - /** - * @inheritdoc - */ - dispatchEvent(event: library.BasicEvent): boolean; - /** - * @inheritdoc - */ - addEventListener(type: string, listener: library.BasicEventListener): void; - /** - * @inheritdoc - */ - addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - /** - * @inheritdoc - */ - removeEventListener(type: string, listener: library.BasicEventListener): void; - /** - * @inheritdoc - */ - removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; - } -} -declare namespace samchon.library { - /** - * The {@link FileReference} class provides a means to load and save files in browser level. - * - * The {@link FileReference} class provides a means to {@link load} and {@link save} files in browser level. A - * browser-system dialog box prompts the user to select a file to {@link load} or a location for {@link svae}. Each - * {@link FileReference} object refers to a single file on the user's disk and has properties that contain - * information about the file's size, type, name, creation date, modification date, and creator type (Macintosh only). - * - * - * FileReference instances are created in the following ways: - *
    - *
  • - * When you use the new operator with the {@link FileReference} constructor: - * let myFileReference: FileReference = new FileReference(); - *
  • - *
  • - * When you call the {@link FileReferenceList.browse} method, which creates an array of {@link FileReference} - * objects. - *
  • - *
- * - * During a load operation, all the properties of a {@link FileReference} object are populated by calls to the - * {@link FileReference.browse} or {@link FileReferenceList.browse} methods. During a save operation, the name - * property is populated when the select event is dispatched; all other properties are populated when the complete - * event is dispatched. - * - * The {@link browse browse()} method opens an browser-system dialog box that prompts the user to select a file - * for {@link load}. The {@link FileReference.browse} method lets the user select a single file; the - * {@link FileReferenceList.browse} method lets the user select multiple files. After a successful call to the - * {@link browse browse()} method, call the {@link FileReference.load} method to load one file at a time. The - * {@link FileReference.save} method prompts the user for a location to save the file and initiates downloading from - * a binary or string data. - * - * The {@link FileReference} and {@link FileReferenceList} classes do not let you set the default file location - * for the dialog box that the {@link browse} or {@link save} methods generate. The default location shown in the - * dialog box is the most recently browsed folder, if that location can be determined, or the desktop. The classes do - * not allow you to read from or write to the transferred file. They do not allow the browser that initiated the - * {@link load} or {@link save} to access the loaded or saved file or the file's location on the user's disk. - * - * @references http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html - * @author Jeongho Nam - */ - class FileReference extends EventDispatcher { - /** - * @hidden - */ - private file_; - /** - * @hidden - */ - private data_; - /** - * Default Constructor. - */ - constructor(); - /** - * The data from the loaded file after a successful call to the {@link load load()} method. - * - * If the {@link FileReference} object was not populated (by a valid call to {@link FileReference.browse}), - * an {@link LogicError exception} will be thrown when you try to get the value of this property. - * - * All the properties of a {@link FileReference} object are populated by calling the {@link browse browse()}. - * - */ - readonly data: any; - /** - * The name of the file on the local disk. - * - * If the {@link FileReference} object was not populated (by a valid call to {@link FileReference.browse}), - * an {@link LogicError exception} will be thrown when you try to get the value of this property. - * - * All the properties of a {@link FileReference} object are populated by calling the {@link browse browse()}. - * - */ - readonly name: string; - /** - * The filename extension. - * - * A file's extension is the part of the name following (and not including) the final dot ("."). If - * there is no dot in the filename, the extension is null. - * - * If the {@link FileReference} object was not populated (by a valid call to {@link FileReference.browse}), - * an {@link LogicError exception} will be thrown when you try to get the value of this property. - * - * All the properties of a {@link FileReference} object are populated by calling the {@link browse browse()}. - * - */ - readonly extension: string; - /** - * The file type, metadata of the {@link extension}. - * - * If the {@link FileReference} object was not populated (by a valid call to {@link FileReference.browse}), - * an {@link LogicError exception} will be thrown when you try to get the value of this property. - * - * All the properties of a {@link FileReference} object are populated by calling the {@link browse browse()}. - * - */ - readonly type: string; - /** - * The size of the file on the local disk in bytes. - * - * If the {@link FileReference} object was not populated (by a valid call to {@link FileReference.browse}), - * an {@link LogicError exception} will be thrown when you try to get the value of this property. - * - * All the properties of a {@link FileReference} object are populated by calling the {@link browse browse()}. - * - */ - readonly size: number; - /** - * The date that the file on the local disk was last modified. - * - * If the {@link FileReference} object was not populated (by a valid call to {@link FileReference.browse}), - * an {@link LogicError exception} will be thrown when you try to get the value of this property. - * - * All the properties of a {@link FileReference} object are populated by calling the {@link browse browse()}. - * - */ - readonly modificationDate: Date; - /** - * Displays a file-browsing dialog box that lets the user select a file to upload. The dialog box is native - * to the user's browser system. The user can select a file on the local computer or from other systems, for - * example, through a UNC path on Windows. - * - * When you call this method and the user successfully selects a file, the properties of this - * {@link FileReference} object are populated with the properties of that file. Each subsequent time that the - * {@link FileReference.browse} method is called, the {@link FileReference} object's properties are reset to - * the file that the user selects in the dialog box. Only one {@link browse browse()} can be performed at a time - * (because only one dialog box can be invoked at a time). - * - * Using the *typeFilter parameter*, you can determine which files the dialog box displays. - * - * @param typeFilter An array of filter strings used to filter the files that are displayed in the dialog box. - * If you omit this parameter, all files are displayed. - */ - browse(...typeFilter: string[]): void; - /** - * Starts the load of a local file selected by a user. - * - * You must call the {@link FileReference.browse} or {@link FileReferenceList.browse} method before you call - * the {@link load load()} method. - * - * Listeners receive events to indicate the progress, success, or failure of the load. Although you can use - * the {@link FileReferenceList} object to let users select multiple files to load, you must {@link load} the - * {@link FileReferenceList files} one by one. To {@link load} the files one by one, iterate through the - * {@link FileReferenceList.fileList} array of {@link FileReference} objects. - * - * If the file finishes loading successfully, its contents are stored in the {@link data} property. - */ - load(): void; - /** - * Save a file to local filesystem. - * - * {@link FileReference.save} implemented the save function by downloading a file from a hidden anchor tag. - * However, the plan, future's {@link FileReference} will follow such rule: - * - * Opens a dialog box that lets the user save a file to the local filesystem. - * - * The {@link save save()} method first opens an browser-system dialog box that asks the user to enter a - * filename and select a location on the local computer to save the file. When the user selects a location and - * confirms the save operation (for example, by clicking Save), the save process begins. Listeners receive events - * to indicate the progress, success, or failure of the save operation. To ascertain the status of the dialog box - * and the save operation after calling {@link save save()}, your code must listen for events such as cancel, - * open, progress, and complete. - * - * When the file is saved successfully, the properties of the {@link FileReference} object are populated with - * the properties of the local file. The complete event is dispatched if the save is successful. - * - * Only one {@link browse browse()} or {@link save()} session can be performed at a time (because only one - * dialog box can be invoked at a time). - * - * @param data The data to be saved. The data can be in one of several formats, and will be treated appropriately. - * @param fileName File name to be saved. - */ - save(data: string, fileName: string): void; - /** - * Save a file to local filesystem. - * - * {@link FileReference.save} implemented the save function by downloading a file from a hidden anchor tag. - * However, the plan, future's {@link FileReference} will follow such rule: - * - * Opens a dialog box that lets the user save a file to the local filesystem. - * - * The {@link save save()} method first opens an browser-system dialog box that asks the user to enter a - * filename and select a location on the local computer to save the file. When the user selects a location and - * confirms the save operation (for example, by clicking Save), the save process begins. Listeners receive events - * to indicate the progress, success, or failure of the save operation. To ascertain the status of the dialog box - * and the save operation after calling {@link save save()}, your code must listen for events such as cancel, - * open, progress, and complete. - * - * When the file is saved successfully, the properties of the {@link FileReference} object are populated with - * the properties of the local file. The complete event is dispatched if the save is successful. - * - * Only one {@link browse browse()} or {@link save()} session can be performed at a time (because only one - * dialog box can be invoked at a time). - * - * @param data The data to be saved. The data can be in one of several formats, and will be treated appropriately. - * @param fileName File name to be saved. - */ - static save(data: string, fileName: string): void; - } - /** - * The {@link FileReferenceList} class provides a means to let users select one or more files for - * {@link FileReference.load loading}. A {@link FileReferenceList} object represents a group of one or more local - * files on the user's disk as an array of {@link FileReference} objects. For detailed information and important - * considerations about {@link FileReference} objects and the FileReference class, which you use with - * {@link FileReferenceList}, see the {@link FileReference} class. - * - * To work with the {@link FileReferenceList} class: - *
    - *
  • Instantiate the class: var myFileRef = new FileReferenceList();
  • - *
  • - * Call the {@link FileReferenceList.browse} method, which opens a dialog box that lets the user select one or - * more files for upload: myFileRef.browse(); - *
  • - *
  • - * After the {@link browse browse()} method is called successfully, the {@link fileList} property of the - * {@link FileReferenceList} object is populated with an array of {@link FileReference} objects. - *
  • - *
  • Call {@link FileReference.load} on each element in the {@link fileList} array.
  • - *
- * - * The {@link FileReferenceList} class includes a {@link browse browse()} method and a {@link fileList} property - * for working with multiple files. - * - * @reference http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReferenceList.html - * @author Jeongho Nam - */ - class FileReferenceList extends EventDispatcher { - /** - * @hidden - */ - file_list: std.Vector; - /** - * Default Constructor. - */ - constructor(); - /** - * An array of {@link FileReference} objects. - * - * When the {@link FileReferenceList.browse} method is called and the user has selected one or more files - * from the dialog box that the {@link browse browse()} method opens, this property is populated with an array of - * {@link FileReference} objects, each of which represents the files the user selected. - * - * The {@link fileList} property is populated anew each time {@link browse browse()} is called on that - * {@link FileReferenceList} object. - */ - readonly fileList: std.Vector; - /** - * Displays a file-browsing dialog box that lets the user select one or more local files to upload. The - * dialog box is native to the user's browser system. - * - * When you call this method and the user successfully selects files, the {@link fileList} property of this - * {@link FileReferenceList} object is populated with an array of {@link FileReference} objects, one for each - * file that the user selects. Each subsequent time that the {@link FileReferenceList.browse} method is called, - * the {@link FileReferenceList.fileList} property is reset to the file(s) that the user selects in the dialog - * box. - * - * Using the *typeFilter* parameter, you can determine which files the dialog box displays. - * - * Only one {@link FileReference.browse}, {@link FileReference.load}, or {@link FileReferenceList.browse} - * session can be performed at a time on a {@link FileReferenceList} object (because only one dialog box can be - * opened at a time). - * - * @param typeFilter An array of filter strings used to filter the files that are displayed in the dialog box. - * If you omit this parameter, all files are displayed. - */ - browse(...typeFilter: string[]): void; - } -} -declare namespace samchon.library { - /** - * A genetic algorithm class. - * - * In the field of artificial intelligence, a genetic algorithm (GA) is a search heuristic that mimics the - * process of natural selection. This heuristic (also sometimes called a metaheuristic) is routinely used to generate - * useful solutions to optimization and search problems. - * - * Genetic algorithms belong to the larger class of evolutionary algorithms (EA), which generate solutions to - * optimization problems using techniques inspired by natural evolution, such as inheritance, {@link mutate mutation}, - * {@link selection}, and {@link crossover}. - * - * @reference https://en.wikipedia.org/wiki/Genetic_algorithm - * @author Jeongho Nam - */ - class GeneticAlgorithm { - /** - * Whether each element (Gene) is unique in their GeneArray. - */ - private unique_; - /** - * Rate of mutation. - * - * The {@link mutation_rate} determines the percentage of occurence of mutation in GeneArray. - * - *
    - *
  • When {@link mutation_rate} is too high, it is hard to ancitipate studying on genetic algorithm.
  • - *
  • - * When {@link mutation_rate} is too low and initial set of genes (GeneArray) is far away from optimal, the - * evolution tends to wandering outside of he optimal. - *
  • - *
- */ - private mutation_rate_; - /** - * Number of tournaments in selection. - */ - private tournament_; - /** - * Initialization Constructor. - * - * @param unique Whether each Gene is unique in their GeneArray. - * @param mutation_rate Rate of mutation. - * @param tournament Number of tournaments in selection. - */ - constructor(unique?: boolean, mutation_rate?: number, tournament?: number); - /** - * Evolove *GeneArray*. - * - * Convenient method accessing to {@link evolvePopulation evolvePopulation()}. - * - * @param individual An initial set of genes; sequence listing. - * @param population Size of population in a generation. - * @param generation Size of generation in evolution. - * @param compare A comparison function returns whether left gene is more optimal. - * - * @return An evolved *GeneArray*, optimally. - * - * @see {@link GAPopulation.compare} - */ - evolveGeneArray>(individual: GeneArray, population: number, generation: number, compare?: (left: T, right: T) => boolean): GeneArray; - /** - * Evolve *population*, a mass of *GeneArraies*. - * - * @param population An initial population. - * @param compare A comparison function returns whether left gene is more optimal. - * - * @return An evolved population. - * - * @see {@link GAPopulation.compare} - */ - evolvePopulation>(population: GAPopulation, compare?: (left: T, right: T) => boolean): GAPopulation; - /** - * Select the best GeneArray in *population* from tournament. - * - * {@link selection Selection} is the stage of a genetic algorithm in which individual genomes are chosen - * from a population for later breeding (using {@linlk crossover} operator). A generic {@link selection} - * procedure may be implemented as follows: - * - *
    - *
  1. - * The fitness function is evaluated for each individual, providing fitness values, which are then - * normalized. ization means dividing the fitness value of each individual by the sum of all fitness - * values, so that the sum of all resulting fitness values equals 1. - *
  2. - *
  3. The population is sorted by descending fitness values.
  4. - *
  5. - * Accumulated normalized fitness values are computed (the accumulated fitness value of an individual is the - * sum of its own fitness value plus the fitness values of all the previous individuals). The accumulated - * fitness of the last individual should be 1 (otherwise something went wrong in the normalization step). - *
  6. - *
  7. A random number R between 0 and 1 is chosen.
  8. - *
  9. The selected individual is the first one whose accumulated normalized value is greater than R.
  10. - *
- * - * @param population The target of tournament. - * @return The best genes derived by the tournament. - * - * @reference https://en.wikipedia.org/wiki/Selection_(genetic_algorithm) - */ - private selection(population); - /** - * Create a new GeneArray by crossing over two *GeneArray*(s). - * - * {@link crossover} is a genetic operator used to vary the programming of a chromosome or chromosomes from - * one generation to the next. It is analogous to reproduction and biological crossover, upon which genetic - * algorithms are based. - * - * {@link crossover Cross over} is a process of taking more than one parent solutions and producing a child - * solution from them. There are methods for selection of the chromosomes. - * - * @param parent1 A parent sequence listing - * @param parent2 A parent sequence listing - * - * @reference https://en.wikipedia.org/wiki/Crossover_(genetic_algorithm) - */ - private crossover(parent1, parent2); - /** - * Cause a mutation on the *GeneArray*. - * - * {@link mutate Mutation} is a genetic operator used to maintain genetic diversity from one generation of a - * population of genetic algorithm chromosomes to the next. It is analogous to biological mutation. - * - * {@link mutate Mutation} alters one or more gene values in a chromosome from its initial state. In - * {@link mutate mutation}, the solution may change entirely from the previous solution. Hence GA can come to - * better solution by using {@link mutate mutation}. - * - * {@link mutate Mutation} occurs during evolution according to a user-definable mutation probability. This - * probability should be set low. If it is set too high, the search will turn into a primitive random search. - * - *

Note

- * Muttion is pursuing diversity. Mutation is useful for avoiding the following problem. - * - * When initial set of genes(GeneArray) is far away from optimail, without mutation (only with selection and - * crossover), the genetic algorithm has a tend to wandering outside of the optimal. - * - * Genes in the GeneArray will be swapped following percentage of the {@link mutation_rate}. - * - * @param individual A container of genes to mutate - * - * @reference https://en.wikipedia.org/wiki/Mutation_(genetic_algorithm) - * @see {@link mutation_rate} - */ - private mutate(individual); - } - /** - * A population in a generation. - * - * {@link GAPopulation} is a class representing population of candidate genes (sequence listing) having an array - * of GeneArray as a member. {@link GAPopulation} also manages initial set of genes and handles fitting test direclty - * by the method {@link fitTest fitTest()}. - * - * The success of evolution of genetic algorithm is depend on the {@link GAPopulation}'s initial set and fitting - * test. (*GeneArray* and {@link compare}.) - * - *

Warning

- * Be careful for the mistakes of direction or position of the {@link compare}. - * Most of logical errors failed to access optimal solution are occured from those mistakes. - * - * @param Type of gene elements. - * @param An array containing genes as elments; sequnce listing. - * - * @author Jeongho Nam - */ - class GAPopulation> { - /** - * Genes representing the population. - */ - private children_; - /** - * A comparison function returns whether left gene is more optimal, greater. - * - * Default value of this {@link compare} is {@link std.greater}. It means to compare two array - * (GeneArray must be a type of {@link std.base.IArrayContainer}). Thus, you've to keep follwing rule. - * - *
    - *
  • GeneArray is implemented from {@link std.base.IArrayContainer}.
  • - *
      - *
    • {@link std.Vector}
    • - *
    • {@link std.Deque}
    • - *
    - *
  • GeneArray has custom public less(obj: T): boolean; function.
  • - *
- * - * If you don't want to follow the rule or want a custom comparison function, you have to realize a - * comparison function. - */ - private compare_; - /** - * Private constructor with population. - * - * Private constructor of GAPopulation does not create {@link children}. (candidate genes) but only assigns - * *null* repeatedly following the *population size*. - * - * This private constructor is designed only for {@link GeneticAlgorithm}. Don't create {@link GAPopulation} - * with this constructor, by yourself. - * - * @param size Size of the population. - */ - constructor(size: number); - /** - * Construct from a {@link GeneArray} and *size of the population*. - * - * This public constructor creates *GeneArray(s)* as population (size) having shuffled genes which are - * came from the initial set of genes (*geneArray*). It uses {@link std.greater} as default comparison function. - * - * - * @param geneArray An initial sequence listing. - * @param size The size of population to have as children. - */ - constructor(geneArray: GeneArray, size: number); - /** - * Constructor from a GeneArray, size of the poluation and custom comparison function. - * - * This public constructor creates *GeneArray(s)* as population (size) having shuffled genes which are - * came from the initial set of genes (*geneArray*). The *compare* is used for comparison function. - * - * - * @param geneArray An initial sequence listing. - * @param size The size of population to have as children. - * @param compare A comparison function returns whether left gene is more optimal. - */ - constructor(geneArray: GeneArray, size: number, compare: (left: GeneArray, right: GeneArray) => boolean); - children(): std.Vector; - /** - * Test fitness of each *GeneArray* in the {@link population}. - * - * @return The best *GeneArray* in the {@link population}. - */ - fitTest(): GeneArray; - /** - * @hidden - */ - private clone(obj); - } -} -declare namespace samchon.library { - /** - * A utility class supporting static methods of string. - * - * The {@link StringUtil} utility class is an all-static class with methods for working with string objects. - * You do not create instances of {@link StringUtil}; instead you call methods such as the - * ```StringUtil.substitute()``` method. - * - * @reference http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/utils/StringUtil.html - * @author Jeongho Nam - */ - class StringUtil { - /** - * Generate a substring. - * - * Extracts a substring consisting of the characters from specified start to end. - * It's same with str.substring( ? = (str.find(start) + start.size()), str.find(end, ?) ) - * - * ```typescript - * let str: string = StringUtil.between("ABCD(EFGH)IJK", "(", ")"); - * console.log(str); // PRINTS "EFGH" - * ``` - * - * - If start is not specified, extracts from begin of the string to end. - * - If end is not specified, extracts from start to end of the string. - * - If start and end are all omitted, returns str, itself. - * - * @param str Target string to be applied between. - * @param start A string for separating substring at the front. - * @param end A string for separating substring at the end. - * - * @return substring by specified terms. - */ - static between(str: string, start?: string, end?: string): string; - /** - * Fetch substrings. - * - * Splits a string into an array of substrings dividing by specified delimeters of start and end. - * It's the array of substrings adjusted the between. - * - *
    - *
  • If startStr is omitted, it's same with the split by endStr not having last item.
  • - *
  • If endStr is omitted, it's same with the split by startStr not having first item.
  • - *
  • If startStr and endStar are all omitted, returns *str*.
  • - *
- * - * @param str Target string to split by between. - * @param start A string for separating substring at the front. - * If omitted, it's same with split(end) not having last item. - * @param end A string for separating substring at the end. - * If omitted, it's same with split(start) not having first item. - * @return An array of substrings. - */ - static betweens(str: string, start?: string, end?: string): Array; - /** - * An array containing whitespaces. - */ - private static SPACE_ARRAY; - /** - * Remove all designated characters from the beginning and end of the specified string. - * - * @param str The string whose designated characters should be trimmed. - * @param args Designated character(s). - * - * @return Updated string where designated characters was removed from the beginning and end. - */ - static trim(str: string, ...args: string[]): string; - /** - * Remove all designated characters from the beginning of the specified string. - * - * @param str The string should be trimmed. - * @param delims Designated character(s). - * - * @return Updated string where designated characters was removed from the beginning - */ - static ltrim(str: string, ...args: string[]): string; - /** - * Remove all designated characters from the end of the specified string. - * - * @param str The string should be trimmed. - * @param delims Designated character(s). - * - * @return Updated string where designated characters was removed from the end. - */ - static rtrim(str: string, ...args: string[]): string; - /** - * Substitute {n} tokens within the specified string. - * - * @param format The string to make substitutions in. This string can contain special tokens of the form - * {n}, where n is a zero based index, that will be replaced with the - * additional parameters found at that index if specified. - * @param args Additional parameters that can be substituted in the *format* parameter at each - * {n} location, where n is an integer (zero based) index value into - * the array of values specified. - * - * @return New string with all of the {n} tokens replaced with the respective arguments specified. - */ - static substitute(format: string, ...args: any[]): string; - /** - * Returns a string specified word is replaced. - * - * @param str Target string to replace - * @param before Specific word you want to be replaced - * @param after Specific word you want to replace - * - * @return A string specified word is replaced - */ - static replaceAll(str: string, before: string, after: string): string; - /** - * Returns a string specified words are replaced. - * - * @param str Target string to replace - * @param pairs A specific word's pairs you want to replace and to be replaced - * - * @return A string specified words are replaced - */ - static replaceAll(str: string, ...pairs: std.Pair[]): string; - /** - * Replace all HTML spaces to a literal space. - * - * @param str Target string to replace. - */ - static removeHTMLSpaces(str: string): string; - /** - * Repeat a string. - * - * Returns a string consisting of a specified string concatenated with itself a specified number of times. - * - * @param str The string to be repeated. - * @param n The repeat count. - * - * @return The repeated string. - */ - static repeat(str: string, n: number): string; - /** - * Number to formatted string with "," sign. - * - * Returns a string converted from the number rounded off from specified precision with "," symbols. - * - * @param val A number wants to convert to string. - * @param precision Target precision of round off. - * - * @return A string who represents the number with roundoff and "," symbols. - */ - static numberFormat(val: number, precision?: number): string; - static percentFormat(val: number, precision?: number): string; - } -} -declare namespace samchon.library { - /** - * URLVariables class is for representing variables of HTTP. - * - * {@link URLVariables} class allows you to transfer variables between an application and server. - * - * When transfering, {@link URLVariables} will be converted to a *URI* string. - * - URI: Uniform Resource Identifier - * - * @reference http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLVariables.html - * @author Migrated by Jeongho Nam - */ - class URLVariables extends std.HashMap { - /** - * Default Constructor. - */ - constructor(); - /** - * Construct from a URL-encoded string. - * - * The {@link decode decode()} method is automatically called to convert the string to properties of the {@link URLVariables} object. - * - * @param str A URL-encoded string containing name/value pairs. - */ - constructor(str: string); - /** - * Converts the variable string to properties of the specified URLVariables object. - * - * @param str A URL-encoded query string containing name/value pairs. - */ - decode(str: string): void; - /** - * Returns a string containing all enumerable variables, in the MIME content encoding application/x-www-form-urlencoded. - */ - toString(): string; - } -} -declare namespace samchon.library { - /** - * A tree-structured XML object. - * - * The {@link XML| class contains methods and properties for working with XML objects. The {@link XML} class (along - * with the {@link XMLList}) implements the powerful XML-handling standards defined in ECMAScript for XML (E4X) - * specification (ECMA-357 edition 2). - * - * An XML object, it is composed with three members; {@link getTag tag}, {@link getProperty properties} and - * {@link getValue value}. As you know, XML is a tree structured data expression method. The tree-stucture; - * {@link XML} class realizes it by extending ```std.HashMap```. Child {@link XML} objects are - * contained in the matched {@link XMLList} object being grouped by their {@link getTag tag name}. The - * {@link XMLList} objects, they're stored in the {@link std.HashMap} ({@link XML} itself) with its **key**; common - * {@link getTag tag name} of children {@link XML} objects. - * - * ```typescript - * class XML extends std.HashMap - * { - * private tag_: string; - * private properties_: std.HashMap; - * private value_: string; - * } - * ``` - * - * ```xml - * - * - * - * {value} - * {value} - * {value} - * - * - * - * - * ``` - * - * Use the {@link toString toString()} method to return a string representation of the {@link XML} object regardless - * of whether the {@link XML} object has simple content or complex content. - * - * @reference http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XML.html - * @handbook https://github.com/samchon/framework/wiki/TypeScript-Library-XML - * @author Jeongho Nam - */ - class XML extends std.HashMap { - /** - * @hidden - */ - private tag_; - /** - * @hidden - */ - private value_; - /** - * @hidden - */ - private property_map_; - /** - * Default Constructor. - */ - constructor(); - /** - * Construct from string. - * - * Creates {@link XML} object by parsing a string who represents xml structure. - * - * @param str A string represents XML structure. - */ - constructor(str: string); - /** - * @hidden - */ - private parse(str); - /** - * @hidden - */ - private parse_tag(str); - /** - * @hidden - */ - private parse_properties(str); - /** - * @hidden - */ - private parse_value(str); - /** - * @hidden - */ - private parse_children(str); - /** - * Get tag. - * - * ```xml - * {value} - * ``` - * - * @return tag. - */ - getTag(): string; - /** - * Get value. - * - * ```xml - * {VALUE} - * ``` - * - * @return value. - */ - getValue(): string; - /** - * Get iterator to property element. - * - * Searches the {@link getPropertyMap properties} for an element with a identifier equivalent to key - * and returns an iterator to it if found, otherwise it returns an iterator to {@link HashMap.end end()}. - * - *

Two keys are considered equivalent if the properties' comparison object returns false reflexively - * (i.e., no matter the order in which the elements are passed as arguments).

- * - * Another member function, {@link hasProperty hasProperty()} can be used to just check whether a particular - * key exists. - * - * ```xml - * {value} - * ``` - * - * @param key Key to be searched for - * @return An iterator to the element, if an element with specified key is found, or - * {@link end HashMap.end()} otherwise. - */ - findProperty(key: string): std.MapIterator; - /** - * Test whether a property exists. - * - * ```xml - * {value} - * ``` - * - * @return Whether a property has the *key* exists or not. - */ - hasProperty(key: string): boolean; - /** - * Get property. - * - * Get property by its *key*, property name. If the matched *key* does not exist, then exception - * {@link std.OutOfRange} is thrown. Thus, it would better to test whether the *key* exits or not by calling the - * {@link hasProperty hasProperty()} method before calling this {@link getProperty getProperty()}. - * - * This method can be substituted by {@link getPropertyMap getPropertyMap()} such below: - * - ```getPropertyMap().get(key, value);``` - * - ```getPropertyMap().find(key).second;``` - * - * ```xml - * {value} - * ``` - * - * @return Value of the matched property. - */ - getProperty(key: string): string; - /** - * Get property map. - * - * ```xml - * {value} - * ``` - * - * @return {@link HashMap} containing properties' keys and values. - */ - getPropertyMap(): std.HashMap; - /** - * Set tag. - * - * Set tag name, identifier of this {@link XML} object. - * - * If this {@link XML} object is belonged to, a child of, an {@link XMLList} and its related {@link XML} objects, - * then calling this {@link setTag setTag()} method direclty is not recommended. Erase this {@link XML} object - * from parent objects and insert this object again. - * - * ```xml - * {value} - * ``` - * - * @param val To be new {@link getTag tag}. - */ - setTag(val: string): void; - /** - * Set value. - * - * ```xml - * {VALUE} - * ``` - * - * @param val To be new {@link getValue value}. - */ - setValue(val: string): void; - /** - * Set property. - * - * Set a property *value* with its *key*. If the *key* already exists, then the *value* will be overwritten to - * the property. Otherwise the *key* is not exist yet, then insert the *key* and *value* {@link Pair pair} to - * {@link getPropertyMao property map}. - * - * This method can be substituted by {@link getPropertyMap getPropertyMap()} such below: - * - ```getPropertyMap().set(key, value);``` - * - ```getPropertyMap().emplace(key, value);``` - * - ```getPropertyMap().insert([key, value]);``` - * - ```getPropertyMap().insert(std.make_pair(key, value));``` - * - * ```xml - * {value} - * ``` - * - * @param key Key, identifier of property to be newly inserted. - * @param value Value of new property to be newly inserted. - */ - setProperty(key: string, value: string): void; - /** - * Erase property. - * - * Erases a property by its *key*, property name. If the matched *key* does not exist, then exception - * {@link std.OutOfRange} is thrown. Thus, it would better to test whether the *key* exits or not by calling the - * {@link hasProperty hasProperty()} method before calling this {@link eraseProperty eraseProperty()}. - * - * This method can be substituted by ``getPropertyMap().erase(key)````. - * - * ```xml - * {value} - * ``` - * - * @param key Key of the property to erase - * @throw {@link std.OutOfRange} - */ - eraseProperty(key: string): void; - /** - * @hidden - */ - push(...args: std.Pair[]): number; - /** - * @hidden - */ - push(...args: [string, XMLList][]): number; - push(...xmls: XML[]): number; - push(...xmlLists: XMLList[]): number; - /** - * Add all properties from other {@link XML} object. - * - * All the properties in the *obj* are copied to this {@link XML} object. If this {@link XML} object has same - * property key in the *obj*, then value of the property will be replaced to *obj*'s own. If you don't want to - * overwrite properties with same key, then use {@link getPropertyMap getPropertyMap()} method. - * - * ```typescript - * let x: library.XML; - * let y: library.XML; - * - * x.addAllProperties(y); // duplicated key exists, then overwrites - * x.getPropertyMap().insert(y.getPropertyMap().begin(), y.getPropertyMap().end()); - * // ducpliated key, then ignores. only non-duplicateds are copied. - * ``` - * - * ```xml - * {value} - * ``` - * - * @param obj Target {@link XML} object to copy properties. - */ - insertAllProperties(obj: XML): void; - /** - * Clear properties. - * - * Remove all properties. It's same with calling ```getPropertyMap().clear()```. - * - * ```xml - * {value} - * ``` - */ - clearProperties(): void; - /** - * @hidden - */ - private compute_min_index(...args); - /** - * @hidden - */ - private decode_value(str); - /** - * @hidden - */ - private encode_value(str); - /** - * @hidden - */ - private decode_property(str); - /** - * @hidden - */ - private encode_property(str); - /** - * {@link XML} object to xml string. - * - * Returns a string representation of the {@link XML} object. - * - * @param tab Number of tabs to spacing. - * @return The string representation of the {@link XML} object. - */ - toString(tab?: number): string; - } -} -declare namespace samchon.library { - /** - * List of {@link XML} objects with same tag. - * - * @reference http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XMLList.html - * @handbook https://github.com/samchon/framework/wiki/TypeScript-Library-XML - * @author Jeongho Nam - */ - class XMLList extends std.Deque { - /** - * Get tag. - */ - getTag(): string; - /** - * {@link XMLList XML objects} to string. - * - * Returns a string representation of the {@link XMLList XML objects}. - * - * @param tab Number of tabs to spacing. - * @return The string representation of the {@link XMLList XML objects}. - */ - toString(level?: number): string; - } -} -declare namespace samchon.protocol { - /** - * An interface of entity. - * - * Entity is a class for standardization of expression method using on network I/O by XML. If - * Invoke is a standard message protocol of Samchon Framework which must be kept, Entity is a - * recommended semi-protocol of message for expressing a data class. Following the semi-protocol - * Entity is not imposed but encouraged. - * - * As we could get advantages from standardization of message for network I/O with Invoke, - * we can get additional advantage from standardizing expression method of data class with Entity. - * We do not need to know a part of network communication. Thus, with the Entity, we can only - * concentrate on entity's own logics and relationships between another entities. Entity does not - * need to how network communications are being done. - * - * I say repeatedly. Expression method of Entity is recommended, but not imposed. It's a semi - * protocol for network I/O but not a essential protocol must be kept. The expression method of - * Entity, using on network I/O, is expressed by XML string. - * - * If your own network system has a critical performance issue on communication data class, - * it would be better to using binary communication (with ByteArray). - * Don't worry about the problem! Invoke also provides methods for binary data (ByteArray). - * - * ![Class Diagram](http://samchon.github.io/framework/images/design/ts_class_diagram/protocol_message_protocol.png) - * - * @author Jeongho Nam - */ - interface IEntity { - /** - * Construct data of the Entity from a XML object. - * - * Overrides the construct() method and fetch data of member variables from the XML. - * - * By recommended guidance, data representing member variables are contained in properties - * of the put XML object. - * - * @param xml An xml used to contruct data of entity. - */ - construct(xml: library.XML): void; - /** - * Get a key that can identify the Entity uniquely. - * - * If identifier of the Entity is not atomic value, returns a paired or tuple object - * that can represents the composite identifier. - * - * - * class Point extends Entity - * { - * private x: number; - * private y: number; - * - * public key(): std.Pair - * { - * return std.make_pair(this.x, this.y); - * } - * } - * - */ - key(): any; - /** - * A tag name when represented by XML. - * - * - */ - TAG(): string; - /** - * Get a XML object represents the Entity. - * - * A member variable (not object, but atomic value like number, string or date) is categorized - * as a property within the framework of entity side. Thus, when overriding a toXML() method and - * archiving member variables to an XML object to return, puts each variable to be a property - * belongs to only a XML object. - * - * Don't archive the member variable of atomic value to XML::value causing enormouse creation - * of XML objects to number of member variables. An Entity must be represented by only a XML - * instance (tag). - * - *

Standard Usage.

- * - * - * - * - * - * - * - *

Non-standard usage abusing value.

- * - * - * jhnam88 - * Jeongho Nam - * 1988-03-11 - * - * - * master - * Administartor - * 2011-07-28 - * - * - * - * @return An XML object representing the Entity. - */ - toXML(): library.XML; - } - /** - * @hidden - */ - namespace IEntity { - function construct(entity: IEntity, xml: library.XML, ...prohibited_names: string[]): void; - function toXML(entity: IEntity, ...prohibited_names: string[]): library.XML; - } - /** - * An entity, a standard data class. - * - * Entity is a class for standardization of expression method using on network I/O by XML. If - * Invoke is a standard message protocol of Samchon Framework which must be kept, Entity is a - * recommended semi-protocol of message for expressing a data class. Following the semi-protocol - * Entity is not imposed but encouraged. - * - * As we could get advantages from standardization of message for network I/O with Invoke, - * we can get additional advantage from standardizing expression method of data class with Entity. - * We do not need to know a part of network communication. Thus, with the Entity, we can only - * concentrate on entity's own logics and relationships between another entities. Entity does not - * need to how network communications are being done. - * - * I say repeatedly. Expression method of Entity is recommended, but not imposed. It's a semi - * protocol for network I/O but not a essential protocol must be kept. The expression method of - * Entity, using on network I/O, is expressed by XML string. - * - * If your own network system has a critical performance issue on communication data class, - * it would be better to using binary communication (with ByteArray). - * Don't worry about the problem! Invoke also provides methods for binary data (ByteArray). - * - * ![Class Diagram](http://samchon.github.io/framework/images/design/ts_class_diagram/protocol_message_protocol.png) - * - * @author Jeongho Nam - */ - abstract class Entity implements IEntity { - /** - * Default Constructor. - */ - constructor(); - construct(xml: library.XML): void; - /** - * @inheritdoc - */ - key(): any; - /** - * @inheritdoc - */ - abstract TAG(): string; - /** - * @inheritdoc - */ - toXML(): library.XML; - } -} -declare namespace samchon.protocol { - /** - * @inheritdoc - */ - interface IEntityCollection extends IEntityGroup, collections.ICollection { - } -} -declare namespace samchon.protocol { - /** - * @inheritdoc - */ - abstract class EntityArrayCollection extends collections.ArrayCollection implements IEntityCollection { - /** - * @inheritdoc - */ - construct(xml: library.XML): void; - /** - * @inheritdoc - */ - abstract createChild(xml: library.XML): T; - /** - * @inheritdoc - */ - key(): any; - /** - * @inheritdoc - */ - has(key: any): boolean; - /** - * @inheritdoc - */ - count(key: any): number; - /** - * @inheritdoc - */ - get(key: any): T; - /** - * @inheritdoc - */ - abstract TAG(): string; - /** - * @inheritdoc - */ - abstract CHILD_TAG(): string; - /** - * @inheritdoc - */ - toXML(): library.XML; - } -} -declare namespace samchon.protocol { - /** - * @inheritdoc - */ - abstract class EntityListCollection extends collections.ListCollection implements IEntityCollection { - /** - * @inheritdoc - */ - construct(xml: library.XML): void; - /** - * @inheritdoc - */ - abstract createChild(xml: library.XML): T; - /** - * @inheritdoc - */ - key(): any; - /** - * @inheritdoc - */ - has(key: any): boolean; - /** - * @inheritdoc - */ - count(key: any): number; - /** - * @inheritdoc - */ - get(key: any): T; - /** - * @inheritdoc - */ - abstract TAG(): string; - /** - * @inheritdoc - */ - abstract CHILD_TAG(): string; - /** - * @inheritdoc - */ - toXML(): library.XML; - } -} -declare namespace samchon.protocol { - /** - * @inheritdoc - */ - abstract class EntityDequeCollection extends collections.DequeCollection implements IEntityCollection { - /** - * @inheritdoc - */ - construct(xml: library.XML): void; - /** - * @inheritdoc - */ - abstract createChild(xml: library.XML): T; - /** - * @inheritdoc - */ - key(): any; - /** - * @inheritdoc - */ - has(key: any): boolean; - /** - * @inheritdoc - */ - count(key: any): number; - /** - * @inheritdoc - */ - get(key: any): T; - /** - * @inheritdoc - */ - abstract TAG(): string; - /** - * @inheritdoc - */ - abstract CHILD_TAG(): string; - /** - * @inheritdoc - */ - toXML(): library.XML; - } -} -/** - * A template for External Systems Manager. - * - * @handbook [Templates - External System](https://github.com/samchon/framework/wiki/TypeScript-Templates-External_System) - * @author Jeongho Nam - */ -declare namespace samchon.templates.external { - /** - * An array and manager of {@link ExternalSystem external system drivers}. - * - * The {@link ExternalSystemArray} is an abstract class containing and managing external system drivers, - * {@link ExternalSystem} objects. Within framewokr of network, {@link ExternalSystemArray} represents your system - * and children {@link ExternalSystem} objects represent remote, external systems connected with your system. - * With this {@link ExternalSystemArray}, you can manage multiple external systems as a group. - * - * You can specify this {@link ExternalSystemArray} class to be *a server accepting external clients* or - * *a client connecting to external servers*. Even both of them is also possible. - * - * - {@link ExternalClientArray}: A server accepting {@link ExternalSystem external clients}. - * - {@link ExternalServerArray}: A client connecting to {@link ExternalServer external servers}. - * - {@link ExternalServerClientArray}: Both of them. Accepts {@link ExternalSystem external clients} and connects to - * {@link ExternalServer external servers} at the same time. - * - * - * - * - * - * #### Proxy Pattern - * The {@link ExternalSystemArray} class can use *Proxy Pattern*. In framework within user, which - * {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not - * important. Only interested in user's perspective is *which can be done*. - * - * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged - * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. - * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. - * - *
    - *
  • - * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring - * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. - *
  • - *
  • - * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call - * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the - * external system. - *
  • - *
  • Those strategy is called *Proxy Pattern*.
  • - *
- * - * @handbook [Templates - External System](https://github.com/samchon/framework/wiki/TypeScript-Templates-External_System) - * @author Jeongho Nam - */ - abstract class ExternalSystemArray extends protocol.EntityDequeCollection implements protocol.IProtocol { - /** - * Default Constructor. - */ - constructor(); - /** - * @hidden - */ - private handle_system_erase(event); - /** - * Test whether the role exists. - * - * @param name Name, identifier of target {@link ExternalSystemRole role}. - * - * @return Whether the role has or not. - */ - hasRole(name: string): boolean; - /** - * Get a role. - * - * @param name Name, identifier of target {@link ExternalSystemRole role}. - * - * @return The specified role. - */ - getRole(name: string): ExternalSystemRole; - /** - * Send an {@link Invoke} message. - * - * @param invoke An {@link Invoke} message to send. - */ - sendData(invoke: protocol.Invoke): void; - /** - * Handle an {@Invoke} message have received. - * - * @param invoke An {@link Invoke} message have received. - */ - replyData(invoke: protocol.Invoke): void; - /** - * Tag name of the {@link ExternalSytemArray} in {@link XML}. - * - * @return *systemArray*. - */ - TAG(): string; - /** - * Tag name of {@link ExternalSystem children elements} belonged to the {@link ExternalSytemArray} in {@link XML}. - * - * @return *system*. - */ - CHILD_TAG(): string; - } -} -/** - * A template for Parallel Processing System. - * - * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System) - * @author Jeongho Nam - */ -declare namespace samchon.templates.parallel { - /** - * Master of Parallel Processing System. - * - * The {@link ParallelSystemArray} is an abstract class containing and managing remote parallel **slave** system - * drivers, {@link ParallelSystem} objects. Within framework of network, {@link ParallelSystemArray} represents your - * system, a **Master** of *Parallel Processing System* that requesting *parallel process* to **slave** systems and the - * children {@link ParallelSystem} objects represent the remote **slave** systems, who is being requested the - * *parallel processes*. - * - * You can specify this {@link ParallelSystemArray} class to be *a server accepting parallel clients* or - * *a client connecting to parallel servers*. Even both of them is possible. Extends one of them below and overrides - * abstract factory method(s) creating the child {@link ParallelSystem} object. - * - * - {@link ParallelClientArray}: A server accepting {@link ParallelSystem parallel clients}. - * - {@link ParallelServerArray}: A client connecting to {@link ParallelServer parallel servers}. - * - {@link ParallelServerClientArray}: Both of them. Accepts {@link ParallelSystem parallel clients} and connects to - * {@link ParallelServer parallel servers} at the same time. - * - * When you need the **parallel process**, then call one of them: {@link sendSegmentData} or {@link sendPieceData}. - * When the **parallel process** has completed, {@link ParallelSystemArray} estimates each {@link ParallelSystem}'s - * {@link ParallelSystem.getPerformance performance index} basis on their execution time. Those performance indices - * will be reflected to the next **parallel process**, how much pieces to allocate to each {@link ParallelSystem}. - * - * - * - * - * - * #### Proxy Pattern - * This class {@link ParallelSystemArray} is derived from the {@link ExternalSystemArray} class. Thus, you can take - * advantage of the *Proxy Pattern* in the {@link ParallelSystemArray} class. If a process to request is not the - * *parallel process* (to be distrubted to all slaves), but the **exclusive process** handled in a system, then it - * may better to utilizing the *Proxy Pattern*: - * - * The {@link ExternalSystemArray} class can use *Proxy Pattern*. In framework within user, which - * {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not - * important. Only interested in user's perspective is *which can be done*. - * - * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged - * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. - * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. - * - *
    - *
  • - * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring - * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. - *
  • - *
  • - * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call - * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the - * external system. - *
  • - *
  • Those strategy is called *Proxy Pattern*.
  • - *
- * - * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System) - * @author Jeongho Nam - */ - abstract class ParallelSystemArray extends external.ExternalSystemArray { - /** - * @hidden - */ - private history_sequence_; - /** - * Default Constructor. - */ - constructor(); - /** - * Send an {@link Invoke} message with segment size. - * - * Sends an {@link Invoke} message requesting a **parallel process** with its *segment size*. The {@link Invoke} - * message will be delivered to children {@link ParallelSystem} objects with the *piece size*, which is divided - * from the *segment size*, basis on their {@link ParallelSystem.getPerformance performance indices}. - * - * - If segment size is 100, - * - The segment will be allocated such below: - * - * Name | Performance index | Number of pieces to be allocated | Formula - * --------|-------------------|----------------------------------|-------------- - * Snail | 1 | 10 | 100 / 10 * 1 - * Cheetah | 4 | 40 | 100 / 10 * 4 - * Rabbit | 3 | 30 | 100 / 10 * 3 - * Turtle | 2 | 20 | 100 / 10 * 2 - * - * When the **parallel process** has completed, then this {@link ParallelSystemArraY} will estimate - * {@link ParallelSystem.getPerformance performance indices} of {@link ParallelSystem} objects basis on their - * execution time. - * - * @param invoke An {@link Invoke} message requesting parallel process. - * @param size Number of pieces to segment. - * - * @return Number of {@link ParallelSystem slave systems} participating in the *Parallel Process*. - * - * @see {@link sendPieceData}, {@link ParallelSystem.getPerformacen} - */ - sendSegmentData(invoke: protocol.Invoke, size: number): number; - /** - * Send an {@link Invoke} message with range of pieces. - * - * Sends an {@link Invoke} message requesting a **parallel process** with its *range of pieces [first, last)*. - * The {@link Invoke} will be delivered to children {@link ParallelSystem} objects with the newly computed - * *range of sub-pieces*, which is divided from the *range of pieces (first to last)*, basis on their - * {@link ParallelSystem.getPerformance performance indices}. - * - * - If indices of pieces are 0 to 50, - * - The sub-pieces will be allocated such below: - * - * Name | Performance index | Range of sub-pieces to be allocated | Formula - * --------|-------------------|-------------------------------------|------------------------ - * Snail | 1 | ( 0, 5] | (50 - 0) / 10 * 1 - * Cheetah | 4 | ( 5, 25] | (50 - 0) / 10 * 4 + 5 - * Rabbit | 3 | (25, 40] | (50 - 0) / 10 * 3 + 25 - * Turtle | 2 | (40, 50] | (50 - 0) / 10 * 2 + 40 - * - * When the **parallel process** has completed, then this {@link ParallelSystemArraY} will estimate - * {@link ParallelSystem.getPerformance performance indices} of {@link ParallelSystem} objects basis on their - * execution time. - * - * @param invoke An {@link Invoke} message requesting parallel process. - * @param first Initial piece's index in a section. - * @param last Final piece's index in a section. The range used is [*first*, *last*), which contains - * all the pieces' indices between *first* and *last*, including the piece pointed by index - * *first*, but not the piece pointed by the index *last*. - * - * @return Number of {@link ParallelSystem slave systems} participating in the *Parallel Process*. - * - * @see {@link sendSegmentData}, {@link ParallelSystem.getPerformacen} - */ - sendPieceData(invoke: protocol.Invoke, first: number, last: number): number; - /** - * @hidden - */ - protected _Complete_history(history: protocol.InvokeHistory): boolean; - /** - * @hidden - */ - protected _Normalize_performance(): void; - } -} -/** - * A template for Distributed Processing System. - * - * @handbook [Templates - Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) - * @author Jeongho Nam - */ -declare namespace samchon.templates.distributed { - /** - * Master of Distributed Processing System. - * - * The {@link DistributedSystemArray} is an abstract class containing and managing remote distributed **slave** system - * drivers, {@link DistributedSystem} objects. Within framework of network, {@link DistributedSystemArray} represents - * your system, a **Master** of *Distributed Processing System* that requesting *distributed process* to **slave** - * systems and the children {@link DistributedSystem} objects represent the remote **slave** systems, who is being - * requested the *distributed processes*. - * - * You can specify this {@link DistributedSystemArray} class to be *a server accepting distributed clients* or - * *a client connecting to distributed servers*. Even both of them is possible. Extends one of them below and overrides - * abstract factory method(s) creating the child {@link DistributedSystem} object. - * - * - {@link DistributedClientArray}: A server accepting {@link DistributedSystem distributed clients}. - * - {@link DistributedServerArray}: A client connecting to {@link DistributedServer distributed servers}. - * - {@link DistributedServerClientArray}: Both of them. Accepts {@link DistributedSystem distributed clients} and - * connects to {@link DistributedServer distributed servers} at the same time. - * - * The {@link DistributedSystemArray} contains {@link DistributedProcess} objects directly. You can request a - * **distributed process** through the {@link DistributedProcess} object. You can access the - * {@link DistributedProcess} object(s) with those methods: - * - * - {@link hasProcess} - * - {@link getProcess} - * - {@link insertProcess} - * - {@link eraseProcess} - * - {@link getProcessMap} - * - * When you need the **distributed process**, call the {@link DistributedProcess.sendData} method. Then the - * {@link DistributedProcess} will find the most idle {@link DistributedSystem} object who represents a distributed - * **slave **system. The {@link Invoke} message will be sent to the most idle {@link DistributedSystem} object. When - * the **distributed process** has completed, then {@link DistributedSystem.getPerformance performance index} and - * {@link DistributedProcess.getResource resource index} of related objects will be revaluated. - * - * - * - * - * - * #### Parallel Process - * This {@link DistributedSystemArray} class is derived from the {@link ParallelSystemArray} class, so you can request - * a **parallel process**, too. - * - * When you need the **parallel process**, then call one of them: {@link sendSegmentData} or {@link sendPieceData}. - * When the **parallel process** has completed, {@link ParallelSystemArray} estimates each {@link ParallelSystem}'s - * {@link ParallelSystem.getPerformance performance index} basis on their execution time. Those performance indices will - * be reflected to the next **parallel process**, how much pieces to allocate to each {@link ParallelSystem}. - * - * #### Proxy Pattern - * This class {@link DistributedSystemArray} is derived from the {@link ExternalSystemArray} class. Thus, you can take - * advantage of the *Proxy Pattern* in the {@link DistributedSystemArray} class. If a process to request is not the - * *parallel process* (to be distrubted to all slaves), but the **exclusive process** handled in a system, then it - * may better to utilizing the *Proxy Pattern*: - * - * The {@link ExternalSystemArray} class can use *Proxy Pattern*. In framework within user, which - * {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not - * important. Only interested in user's perspective is *which can be done*. - * - * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged - * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. - * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. - * - *
    - *
  • - * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring - * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. - *
  • - *
  • - * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call - * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the - * external system. - *
  • - *
  • Those strategy is called *Proxy Pattern*.
  • - *
- * - * @handbook [Templates - Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) - * @author Jeongho Nam - */ - abstract class DistributedSystemArray extends parallel.ParallelSystemArray { - /** - * @hidden - */ - private process_map_; - /** - * Default Constructor. - */ - constructor(); - /** - * @inheritdoc - */ - construct(xml: library.XML): void; - /** - * Factory method creating a child {@link DistributedProcess process} object. - * - * @param xml {@link XML} represents the {@link DistributedProcess child} object. - * @return A new {@link DistributedProcess} object. - */ - protected abstract createProcess(xml: library.XML): DistributedProcess; - /** - * Get process map. - * - * Gets an {@link HashMap} containing {@link DistributedProcess} objects with their *key*. - * - * @return An {@link HasmMap> containing pairs of string and {@link DistributedProcess} object. - */ - getProcessMap(): std.HashMap; - /** - * Test whether the process exists. - * - * @param name Name, identifier of target {@link DistributedProcess process}. - * - * @return Whether the process has or not. - */ - hasProcess(name: string): boolean; - /** - * Get a process. - * - * @param name Name, identifier of target {@link DistributedProcess process}. - * - * @return The specified process. - */ - getProcess(name: string): DistributedProcess; - /** - * Insert a process. - * - * @param process A process to be inserted. - * @return Success flag. - */ - insertProcess(process: DistributedProcess): boolean; - /** - * Erase a process. - * - * @param name Name, identifier of target {@link DistributedProcess process}. - */ - eraseProcess(name: string): boolean; - /** - * @hidden - */ - protected _Complete_history(history: protocol.InvokeHistory): boolean; - /** - * @hidden - */ - private estimate_process_resource(history); - /** - * @hidden - */ - private estimate_system_performance(history); - /** - * @hidden - */ - protected _Normalize_performance(): void; - /** - * @inheritdoc - */ - toXML(): library.XML; - } -} -declare namespace samchon.templates.distributed { - /** - * Mediator of Distributed Processing System. - * - * The {@link DistributedSystemArrayMediator} class be a master for its slave systems, and be a slave to its master - * system at the same time. This {@link DistributedSystemArrayMediator} be a master system, containing and managing - * {@link DistributedSystem} objects, which represent distributed slave systems, by extending - * {@link DistributedSystemArray} class. Also, be a slave system through {@link getMediator mediator} object, which is - * derived from the {@link SlaveSystem} class. - * - * As a master, you can specify this {@link DistributedSystemArrayMediator} class to be a master server accepting - * slave clients or a master client to connecting slave servers. Even both of them is possible. Extends one - * of them below and overrides abstract factory method(s) creating the child {@link DistributedSystem} object. - * - * - {@link DistributedClientArrayMediator}: A server accepting {@link DistributedSystem distributed clients}. - * - {@link DistributedServerArrayMediator}: A client connecting to {@link DistributedServer distributed servers}. - * - {@link DistributedServerClientArrayMediator}: Both of them. Accepts {@link DistributedSystem distributed clients} and - * connects to {@link DistributedServer distributed servers} at the same time. - * - * As a slave, you can specify this {@link DistributedSystemArrayMediator} to be a client slave connecting to master - * server or a server slave accepting master client by overriding the {@link createMediator} method. - * Overrides the {@link createMediator createMediator()} method and return one of them: - * - * - A client slave connecting to master server: - * - {@link MediatorClient} - * - {@link MediatorWebClient} - * - {@link MediatorSharedWorkerClient} - * - A server slave accepting master client: - * - {@link MediatorServer} - * - {@link MediatorWebServer} - * - {@link MediatorDedicatedWorkerServer} - * - {@link MediatorSharedWorkerServer} - * - * #### [Inherited] {@link DistributedSystemArray} - * The {@link DistributedSystemArray} is an abstract class containing and managing remote distributed **slave** system - * drivers, {@link DistributedSystem} objects. Within framework of network, {@link DistributedSystemArray} represents - * your system, a **Master** of *Distributed Processing System* that requesting *distributed process* to **slave** - * systems and the children {@link DistributedSystem} objects represent the remote **slave** systems, who is being - * requested the *distributed processes*. - * - * The {@link DistributedSystemArray} contains {@link DistributedProcess} objects directly. You can request a - * **distributed process** through the {@link DistributedProcess} object. You can access the - * {@link DistributedProcess} object(s) with those methods: - * - * - {@link hasProcess} - * - {@link getProcess} - * - {@link insertProcess} - * - {@link eraseProcess} - * - {@link getProcessMap} - * - * When you need the **distributed process**, call the {@link DistributedProcess.sendData} method. Then the - * {@link DistributedProcess} will find the most idle {@link DistributedSystem} object who represents a distributed - * **slave **system. The {@link Invoke} message will be sent to the most idle {@link DistributedSystem} object. When - * the **distributed process** has completed, then {@link DistributedSystem.getPerformance performance index} and - * {@link DistributedProcess.getResource resource index} of related objects will be revaluated. - * - * - * - * - * - * #### Parallel Process - * This {@link DistributedSystemArray} class is derived from the {@link ParallelSystemArray} class, so you can request - * a **parallel process**, too. - * - * When you need the **parallel process**, then call one of them: {@link sendSegmentData} or {@link sendPieceData}. - * When the **parallel process** has completed, {@link ParallelSystemArray} estimates each {@link ParallelSystem}'s - * {@link ParallelSystem.getPerformance performance index} basis on their execution time. Those performance indices will - * be reflected to the next **parallel process**, how much pieces to allocate to each {@link ParallelSystem}. - * - * #### Proxy Pattern - * This class {@link DistributedSystemArray} is derived from the {@link ExternalSystemArray} class. Thus, you can take - * advantage of the *Proxy Pattern* in the {@link DistributedSystemArray} class. If a process to request is not the - * *parallel process* (to be distrubted to all slaves), but the **exclusive process** handled in a system, then it - * may better to utilizing the *Proxy Pattern*: - * - * The {@link ExternalSystemArray} class can use *Proxy Pattern*. In framework within user, which - * {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not - * important. Only interested in user's perspective is *which can be done*. - * - * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged - * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. - * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. - * - *
    - *
  • - * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring - * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. - *
  • - *
  • - * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call - * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the - * external system. - *
  • - *
  • Those strategy is called *Proxy Pattern*.
  • - *
- * - * @handbook [Templates - Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) - * @author Jeongho Nam - */ - abstract class DistributedSystemArrayMediator extends DistributedSystemArray { - /** - * @hidden - */ - private mediator_; - /** - * Default Constructor. - */ - constructor(); - /** - * Factory method creating a {@link MediatorSystem} object. - * - * The {@link createMediator createMediator()} is an abstract method creating the {@link MediatorSystem} object. - * - * You know what? this {@link DistributedSystemArrayMediator} class be a master for its slave systems, and be a - * slave to its master system at the same time. The {@link MediatorSystem} object makes it possible; be a slave - * system. This {@link createMediator} determines specific type of the {@link MediatorSystem}. - * - * Overrides the {@link createMediator createMediator()} method to create and return one of them following which - * protocol and which type of remote connection (server or client) will be used: - * - * - A client slave connecting to master server: - * - {@link MediatorClient} - * - {@link MediatorWebClient} - * - {@link MediatorSharedWorkerClient} - * - A server slave accepting master client: - * - {@link MediatorServer} - * - {@link MediatorWebServer} - * - {@link MediatorDedicatedWorkerServer} - * - {@link MediatorSharedWorkerServer} - * - * @return A newly created {@link MediatorSystem} object. - */ - protected abstract createMediator(): parallel.MediatorSystem; - /** - * Start mediator. - * - * If the {@link getMediator mediator} is a type of server, then opens the server accepting master client. - * Otherwise, the {@link getMediator mediator} is a type of client, then connects the master server. - */ - protected startMediator(): void; - /** - * Get {@link MediatorSystem} object. - * - * When you need to send an {@link Invoke} message to the master system of this - * {@link DistributedSystemArrayMediator}, then send to the {@link MediatorSystem} through this - * {@link getMediator}. - * - * ```typescript - * this.getMediator().sendData(...); - * ``` - * - * @return The {@link MediatorSystem} object. - */ - getMediator(): parallel.MediatorSystem; - /** - * @hidden - */ - protected _Complete_history(history: parallel.PRInvokeHistory): boolean; - } -} -declare namespace samchon.protocol { - /** - * An interface taking full charge of network communication. - * - * {@link ICommunicator} is an interface for communicator classes who take full charge of network communication with - * remote system, without reference to whether the remote system is a server or a client. Type of the - * {@link ICommunicator} is specified to {@link IServerConnector} and {@link IClientDriver} whether the remote system - * is a server (that I've to connect) or a client (a client connected to my server). - * - * Whenever a replied message comes from the remote system, the message will be converted to an {@link Invoke} class - * and the {@link Invoke} object will be shifted to the {@link IProtocol listener}'s - * {@link IProtocol.replyData IProtocol.replyData()} method. - * - * - * - * - * - * @see {@link IClientDriver}, {@link IServerConnector}, {@link IProtocol} - * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#icommunicator) - * @author Jeongho Nam - */ - interface ICommunicator extends IProtocol { - /** - * Callback function for connection closed. - */ - onClose: Function; - /** - * Close connection. - */ - close(): void; - /** - * Test connection. - * - * Test whether this {@link ICommunicator communicator} object is connected with the remote system. If the - * connection is alive, then returns ```true```. Otherwise, the connection is not alive or this - * {@link ICommunicator communicator has not connected with the remote system yet, then returns ```false```. - * - * @return true if connected, otherwise false. - */ - isConnected(): boolean; - /** - * Send message. - * - * Send {@link Invoke} message to remote system. - * - * @param invoke An {@link Invoke} message to send. - */ - sendData(invoke: protocol.Invoke): void; - /** - * Handle replied message. - * - * Handles replied {@link Invoke} message recived from remove system. The {@link Invoke} message will be shifted - * to the {@link IProtocol listener}'s {@link IProtocol.replyData IProtocol.replyData()} by this method. - * - * @param invoke An {@link Invoke} message received from remote system. - */ - replyData(invoke: protocol.Invoke): void; - } -} -declare namespace samchon.protocol { - /** - * An abstract, basic class for communicators. - * - * {@link CommunicatorBase} is an abstract class implemented from the {@link ICommunicator}. Mechanism of converting - * raw data to {@link Invoke} messag has realized in this abstract class. Type of this {@link CommunicatorBase} class - * is specified to as below following which protocol is used. - * - * - {@link Communicator}: Samchon Framework's own protocool. - * - {@link WebCommunicator}: Web-socket protocol - * - {@link SharedWorkerCommunicator}: SharedWorker's message protocol. - * - * #### [Inherited] {@link ICommunicator} - * {@link ICommunicator} is an interface for communicator classes who take full charge of network communication with - * remote system, without reference to whether the remote system is a server or a client. Type of the - * {@link ICommunicator} is specified to {@link IServerConnector} and {@link IClientDriver} whether the remote system - * is a server (that I've to connect) or a client (a client connected to my server). - * - * Whenever a replied message comes from the remote system, the message will be converted to an {@link Invoke} class - * and the {@link Invoke} object will be shifted to the {@link IProtocol listener}'s - * {@link IProtocol.replyData IProtocol.replyData()} method. - * - * - * - * - * - * @see {@link IClientDriver}, {@link IServerConnector}, {@link IProtocol} - * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#icommunicator) - * @author Jeongho Nam - */ - abstract class CommunicatorBase implements ICommunicator { - /** - * @hidden - */ - protected listener_: IProtocol; - /** - * @inheritdoc - */ - onClose: Function; - /** - * @hidden - */ - protected connected_: boolean; - /** - * @hidden - */ - private binary_invoke_; - /** - * @hidden - */ - private binary_parameters_; - /** - * @hidden - */ - private unhandled_invokes; - /** - * Default Constructor. - */ - constructor(); - /** - * Construct from *listener*. - * - * @param listener An {@link IProtocol} object to listen {@link Invoke} messages. - */ - constructor(listener: IProtocol); - /** - * @inheritdoc - */ - abstract close(): void; - /** - * @inheritdoc - */ - isConnected(): boolean; - /** - * @hidden - */ - protected is_binary_invoke(): boolean; - /** - * @inheritdoc - */ - abstract sendData(invoke: Invoke): void; - /** - * @inheritdoc - */ - replyData(invoke: Invoke): void; - /** - * @hidden - */ - protected handle_string(str: string): void; - /** - * @hidden - */ - protected handle_binary(binary: Uint8Array): void; - } -} -declare namespace samchon.protocol { - /** - * A communicator following Samchon Framework's own protocol. - * - * {@link Communicator} is an abstract class following Samchon Framework's own protocol. This {@link Communicator} - * class is specified to {@link ServerConnector} and {@link ClientDriver} whether the remote system is a server (that - * my system is connecting to) or a client (a client conneting to to my server). - * - * Note that, if one of this or remote system is web-browser based, then you don't have to use this - * {@link Communicator} class who follows Samchon Framework's own protocol. Web-browser supports only Web-socket - * protocol. Thus in that case, you have to use {@link WebCommunicator} instead. - * - * #### [Inherited] {@link ICommunicator} - * {@link ICommunicator} is an interface for communicator classes who take full charge of network communication with - * remote system, without reference to whether the remote system is a server or a client. Type of the - * {@link ICommunicator} is specified to {@link IServerConnector} and {@link IClientDriver} whether the remote system - * is a server (that I've to connect) or a client (a client connected to my server). - * - * Whenever a replied message comes from the remote system, the message will be converted to an {@link Invoke} class - * and the {@link Invoke} object will be shifted to the {@link IProtocol listener}'s - * {@link IProtocol.replyData IProtocol.replyData()} method. - * - * - * - * - * - * @see {@link ClientDriver}, {@link ServerConnector}, {@link IProtocol} - * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#icommunicator) - * @author Jeongho Nam - */ - abstract class Communicator extends CommunicatorBase { - /** - * @hidden - */ - protected socket_: socket.socket; - /** - * @hidden - */ - private header_bytes_; - /** - * @hidden - */ - private data_; - /** - * @hidden - */ - private data_index_; - /** - * @hidden - */ - private listening_; - /** - * @inheritdoc - */ - close(): void; - /** - * @hidden - */ - protected start_listen(): void; - /** - * @hidden - */ - private handle_error(); - /** - * @hidden - */ - private handle_close(); - /** - * @inheritdoc - */ - sendData(invoke: Invoke): void; - /** - * @hidden - */ - private listen_piece(piece); - /** - * @hidden - */ - private listen_header(piece, piece_index); - /** - * @hidden - */ - private listen_data(piece, piece_index); - } -} -declare namespace samchon.protocol { - /** - * A communicator following Web-socket protocol. - * - * {@link WebCommunicator} is an abstract class following Web-socket protocol. This {@link WebCommunicator} class is - * specified to {@link WebServerConnector} and {@link WebClientDriver} whether the remote system is a server (that my - * system is connecting to) or a client (a client conneting to to my server). - * - * Note that, one of this or remote system is web-browser based, then there's not any alternative choice. Web browser - * supports only Web-socket protocol. In that case, you've use this {@link WebCommunicator} class. - * - * #### [Inherited] {@link ICommunicator} - * {@link ICommunicator} is an interface for communicator classes who take full charge of network communication with - * remote system, without reference to whether the remote system is a server or a client. Type of the - * {@link ICommunicator} is specified to {@link IServerConnector} and {@link IClientDriver} whether the remote system - * is a server (that I've to connect) or a client (a client connected to my server). - * - * Whenever a replied message comes from the remote system, the message will be converted to an {@link Invoke} class - * and the {@link Invoke} object will be shifted to the {@link IProtocol listener}'s - * {@link IProtocol.replyData IProtocol.replyData()} method. - * - * - * - * - * - * @see {@link WebClientDriver}, {@link WebServerConnector}, {@link IProtocol} - * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#icommunicator) - * @author Jeongho Nam - */ - abstract class WebCommunicator extends CommunicatorBase { - /** - * @hidden - */ - protected connection_: websocket.connection; - /** - * @inheritdoc - */ - close(): void; - /** - * @inheritdoc - */ - sendData(invoke: Invoke): void; - /** - * @hidden - */ - protected handle_message(message: websocket.IMessage): void; - /** - * @hidden - */ - protected handle_close(): void; - } -} -declare namespace samchon.protocol { - /** - * A communicator for shared worker. - * - * {@link DedicatedWorkerCommunicator} is an abstract class for communication between DedicatedWorker and Web-browser. - * This {@link DedicatedWorkerCommunicator} is specified to {@link DedicatedWorkerServerConnector} and - * {@link DedicatedWorkerClientDriver} whether the remote system is a server (that my system is connecting to) or a - * client (a client conneting to to my server). - * - * #### Why DedicatedWorker be a server? - * In JavaScript environment, there's no way to implement multi-threading function. Instead, JavaScript supports the - * **Worker**, creating a new process. However, the **Worker** does not shares memory addresses. To integrate the - * **Worker** with its master, only communication with string or binary data is allowed. Doesn't it seem like a network - * communication? Furthermore, there's not any difference between the worker communication and network communication. - * It's the reason why Samchon Framework considers the **Worker** as a network node. - * - * The class {@link DedicatedWorkerCommunicator} is designed make such relationship. From now on, DedicatedWorker is a - * {@link DedicatedWorkerServer server} and {@link DedicatedWorkerServerConnector browser} is a client. Integrate the - * server and clients with this {@link DedicatedWorkerCommunicator}. - * - * #### [Inherited] {@link ICommunicator} - * {@link ICommunicator} is an interface for communicator classes who take full charge of network communication with - * remote system, without reference to whether the remote system is a server or a client. Type of the - * {@link ICommunicator} is specified to {@link IServerConnector} and {@link IClientDriver} whether the remote system - * is a server (that I've to connect) or a client (a client connected to my server). - * - * Whenever a replied message comes from the remote system, the message will be converted to an {@link Invoke} class - * and the {@link Invoke} object will be shifted to the {@link IProtocol listener}'s - * {@link IProtocol.replyData IProtocol.replyData()} method. - * - * - * - * - * - * @see {@link DedicatedWorkerClientDriver}, {@link DedicatedWorkerServerConnector}, {@link IProtocol} - * @reference https://developer.mozilla.org/en-US/docs/Web/API/DedicatedWorker - * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#icommunicator) - * @author Jeongho Nam - */ - abstract class DedicatedWorkerCommunicator extends CommunicatorBase { - /** - * @hidden - */ - protected handle_message(event: MessageEvent): void; - } -} -declare namespace samchon.protocol { - /** - * A communicator for shared worker. - * - * {@link SharedWorkerCommunicator} is an abstract class for communication between SharedWorker and Web-browser. This - * {@link SharedWorkerCommunicator} is specified to {@link SharedWorkerServerConnector} and - * {@link SharedWorkerClientDriver} whether the remote system is a server (that my system is connecting to) or a client - * (a client conneting to to my server). - * - * Note that, SharedWorker is a conception only existed in web-browser. This {@link SharedWorkerCommunicator} is not - * supported in NodeJS. Only web-browser environment can utilize this {@link SharedWorkerCommunicator}. - * - * #### Why SharedWorker be a server? - * SharedWorker, it allows only an instance (process) to be created whether the SharedWorker is declared in a browser - * or multiple browsers. To integrate them, messages are being sent and received. Doesn't it seem like a relationship - * between a server and clients? Thus, Samchon Framework consider the SharedWorker as a server and browsers as - * clients. - * - * The class {@link SharedWorkerCommunicator} is designed make such relationship. From now on, SharedWorker is a - * {@link SharedWorkerServer server} and {@link SharedWorkerServerConnector browsers} are clients. Integrate the - * server and clients with this {@link SharedWorkerCommunicator}. - * - * #### [Inherited] {@link ICommunicator} - * {@link ICommunicator} is an interface for communicator classes who take full charge of network communication with - * remote system, without reference to whether the remote system is a server or a client. Type of the - * {@link ICommunicator} is specified to {@link IServerConnector} and {@link IClientDriver} whether the remote system - * is a server (that I've to connect) or a client (a client connected to my server). - * - * Whenever a replied message comes from the remote system, the message will be converted to an {@link Invoke} class - * and the {@link Invoke} object will be shifted to the {@link IProtocol listener}'s - * {@link IProtocol.replyData IProtocol.replyData()} method. - * - * - * - * - * - * @see {@link SharedWorkerClientDriver}, {@link SharedWorkerServerConnector}, {@link IProtocol} - * @reference https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker - * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#icommunicator) - * @author Jeongho Nam - */ - abstract class SharedWorkerCommunicator extends CommunicatorBase { - /** - * @hidden - */ - protected port_: MessagePort; - /** - * @inheritdoc - */ - close(): void; - /** - * @inheritdoc - */ - sendData(invoke: Invoke): void; - /** - * @hidden - */ - protected handle_message(event: MessageEvent): void; - } -} -declare namespace samchon.protocol { - /** - * An interface for communicator with remote client. - * - * {@link IClientDriver} is a type of {@link ICommunicator}, specified for communication with remote client who has - * connected in a {@link IServer server}. It takes full charge of network communication with the remote client. - * - * The {@link IClientDriver} object is created and delivered from {@link IServer} and - * {@link IServer.addClient IServer.addClient()}. Those are derived types from this {@link IClientDriver}, being - * created by the matched {@link IServer} object. - * - * Protocol | Derived Type | Created By - * ------------------------|-------------------------------------|---------------------------- - * Samchon Framework's own | {@link ClientDriver} | {@link Server} - * Web-socket protocol | {@link WebClientDriver} | {@link WebServer} - * DedicatedWorker | {@link DedicatedWorkerClinetDriver} | {@link DedicatedWorkerServer} - * SharedWorker | {@link SharedWorkerClientDriver} | {@link SharedWorkerServer} - * - * When you've got an {@link IClientDriver} object from the {@link IServer.addClient IServer.addClient()}, then - * specify {@link IProtocol listener} with {@link IClient.listen IClient.listen()}. Whenever a replied message comes - * from the remote system, the message will be converted to an {@link Invoke} class and the {@link Invoke} object - * will be shifted to the {@link IProtocol listener}'s {@link IProtocol.replyData IProtocol.replyData()} method. - * Below code is an example specifying and managing the {@link IProtocol listener} objects. - * - * - https://github.com/samchon/framework/blob/master/ts/examples/calculator/calculator-server.ts - * - * - * - * - * - * @see {@link IServer}, {@link IProtocol} - * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#iclientdriver) - * @author Jeongho Nam - */ - interface IClientDriver extends ICommunicator { - /** - * Listen message from the newly connected client. - * - * Starts listening message from the newly connected client. Replied message from the connected client will be - * converted to {@link Invoke} classes and shifted to the *listener*'s {@link IProtocol.replyData replyData()} - * method. - * - * @param listener A listener object to listen replied message from newly connected client in - * {@link IProtocol.replyData replyData()} as an {@link Invoke} object. - */ - listen(listener: IProtocol): void; - } -} -declare namespace samchon.protocol { - /** - * Communicator with remote client. - * - * {@link ClientDriver} is a class taking full charge of network communication with remote client who follows Samchon - * Framework's own protocol. This {@link ClientDriver} object is always created by {@link Server} class. When you got - * this {@link ClientDriver} object from the {@link Server.addClient Server.addClient()}, then specify - * {@link IProtocol listener} with the {@link ClientDriver.listen ClientDriver.listen()} method. - * - * #### [Inherited] {@link IClientDriver} - * {@link IClientDriver} is a type of {@link ICommunicator}, specified for communication with remote client who has - * connected in a {@link IServer server}. It takes full charge of network communication with the remote client. - * - * The {@link IClientDriver} object is created and delivered from {@link IServer} and - * {@link IServer.addClient IServer.addClient()}. Those are derived types from this {@link IClientDriver}, being - * created by the matched {@link IServer} object. - * - * Protocol | Derived Type | Created By - * ------------------------|-------------------------------------|---------------------------- - * Samchon Framework's own | {@link ClientDriver} | {@link Server} - * Web-socket protocol | {@link WebClientDriver} | {@link WebServer} - * DedicatedWorker | {@link DedicatedWorkerClinetDriver} | {@link DedicatedWorkerServer} - * SharedWorker | {@link SharedWorkerClientDriver} | {@link SharedWorkerServer} - * - * When you've got an {@link IClientDriver} object from the {@link IServer.addClient IServer.addClient()}, then - * specify {@link IProtocol listener} with {@link IClient.listen IClient.listen()}. Whenever a replied message comes - * from the remote system, the message will be converted to an {@link Invoke} class and the {@link Invoke} object - * will be shifted to the {@link IProtocol listener}'s {@link IProtocol.replyData IProtocol.replyData()} method. - * Below code is an example specifying and managing the {@link IProtocol listener} objects. - * - * - https://github.com/samchon/framework/blob/master/ts/examples/calculator/calculator-server.ts - * - * - * - * - * - * @see {@link Server}, {@link IProtocol} - * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#iclientdriver) - * @author Jeongho Nam - */ - class ClientDriver extends Communicator implements IClientDriver { - /** - * Construct from a socket. - */ - constructor(socket: socket.socket); - /** - * @inheritdoc - */ - listen(listener: IProtocol): void; - } -} -declare namespace samchon.protocol { - /** - * Communicator with remote web-client. - * - * {@link WebClientDriver} is a class taking full charge of network communication with remote client who follows - * Web-socket protocol. This {@link WebClientDriver} object is always created by {@link WebServer} class. When you - * got this {@link WebClientDriver} object from the {@link WebServer.addClient WebServer.addClient()}, then specify - * {@link IProtocol listener} with the {@link WebClientDriver.listen WebClientDriver.listen()} method. - * - * Unlike other protocol, Web-socket protocol's clients notify two parameters on their connection; - * {@link getSessionID session-id} and {@link getPath path}. The {@link getSessionID session-id} can be used to - * identify *user* of each client, and the {@link getPath path} can be used which type of *service* that client wants. - * In {@link service} module, you can see the best utilization case of them. - * - {@link service.User}: utlization of the {@link getSessionID session-id}. - * - {@link service.Service}: utilization of the {@link getPath path}. - * - * #### [Inherited] {@link IClientDriver} - * {@link IClientDriver} is a type of {@link ICommunicator}, specified for communication with remote client who has - * connected in a {@link IServer server}. It takes full charge of network communication with the remote client. - * - * The {@link IClientDriver} object is created and delivered from {@link IServer} and - * {@link IServer.addClient IServer.addClient()}. Those are derived types from this {@link IClientDriver}, being - * created by the matched {@link IServer} object. - * - * Protocol | Derived Type | Created By - * ------------------------|-------------------------------------|---------------------------- - * Samchon Framework's own | {@link ClientDriver} | {@link Server} - * Web-socket protocol | {@link WebClientDriver} | {@link WebServer} - * DedicatedWorker | {@link DedicatedWorkerClinetDriver} | {@link DedicatedWorkerServer} - * SharedWorker | {@link SharedWorkerClientDriver} | {@link SharedWorkerServer} - * - * When you've got an {@link IClientDriver} object from the {@link IServer.addClient IServer.addClient()}, then - * specify {@link IProtocol listener} with {@link IClient.listen IClient.listen()}. Whenever a replied message comes - * from the remote system, the message will be converted to an {@link Invoke} class and the {@link Invoke} object - * will be shifted to the {@link IProtocol listener}'s {@link IProtocol.replyData IProtocol.replyData()} method. - * Below code is an example specifying and managing the {@link IProtocol listener} objects. - * - * - https://github.com/samchon/framework/blob/master/ts/examples/calculator/calculator-server.ts - * - * - * - * - * - * @see {@link WebServer}, {@link IProtocol} - * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#iclientdriver) - * @author Jeongho Nam - */ - class WebClientDriver extends WebCommunicator implements IClientDriver { - /** - * @hidden - */ - private path_; - /** - * @hidden - */ - private session_id_; - /** - * @hidden - */ - private listening_; - /** - * Initialization Constructor. - * - * @param connection Connection driver, a socket for web-socket. - * @param path Requested path. - * @param session_id Session ID, an identifier of the remote client. - */ - constructor(connection: websocket.connection, path: string, session_id: string); - /** - * @inheritdoc - */ - listen(listener: IProtocol): void; - /** - * Get requested path. - */ - getPath(): string; - /** - * Get session ID, an identifier of the remote client. - */ - getSessionID(): string; - } -} -declare namespace samchon.protocol { - /** - * Communicator with master web-browser. - * - * {@link DedicatedWorkerClientDriver} is a class taking full charge of network communication with web browsers. This - * {@link DedicatedWorkerClientDriver} object is always created by {@link DedicatedWorkerServer} class. When you got - * this {@link DedicatedWorkerClientDriver} object from - * {@link DedicatedWorkerServer.addClient DedicatedWorkerServer.addClient()}, then specify {@link IProtocol listener} - * with the {@link DedicatedWorkerClientDriver.listen DedicatedWorkerClientDriver.listen()} method. - * - * #### Why DedicatedWorker be a server? - * In JavaScript environment, there's no way to implement multi-threading function. Instead, JavaScript supports the - * **Worker**, creating a new process. However, the **Worker** does not shares memory addresses. To integrate the - * **Worker** with its master, only communication with string or binary data is allowed. Doesn't it seem like a network - * communication? Furthermore, there's not any difference between the worker communication and network communication. - * It's the reason why Samchon Framework considers the **Worker** as a network node. - * - * The class {@link DedicatedWorkerCommunicator} is designed make such relationship. From now on, DedicatedWorker is a - * {@link DedicatedWorkerServer server} and {@link DedicatedWorkerServerConnector browser} is a client. Integrate the - * server and clients with this {@link DedicatedWorkerCommunicator}. - * - * #### [Inherited] {@link IClientDriver} - * {@link IClientDriver} is a type of {@link ICommunicator}, specified for communication with remote client who has - * connected in a {@link IServer server}. It takes full charge of network communication with the remote client. - * - * The {@link IClientDriver} object is created and delivered from {@link IServer} and - * {@link IServer.addClient IServer.addClient()}. Those are derived types from this {@link IClientDriver}, being - * created by the matched {@link IServer} object. - * - * Protocol | Derived Type | Created By - * ------------------------|-------------------------------------|---------------------------- - * Samchon Framework's own | {@link ClientDriver} | {@link Server} - * Web-socket protocol | {@link WebClientDriver} | {@link WebServer} - * DedicatedWorker | {@link DedicatedWorkerClinetDriver} | {@link DedicatedWorkerServer} - * SharedWorker | {@link SharedWorkerClientDriver} | {@link SharedWorkerServer} - * - * When you've got an {@link IClientDriver} object from the {@link IServer.addClient IServer.addClient()}, then - * specify {@link IProtocol listener} with {@link IClient.listen IClient.listen()}. Whenever a replied message comes - * from the remote system, the message will be converted to an {@link Invoke} class and the {@link Invoke} object - * will be shifted to the {@link IProtocol listener}'s {@link IProtocol.replyData IProtocol.replyData()} method. - * Below code is an example specifying and managing the {@link IProtocol listener} objects. - * - * - https://github.com/samchon/framework/blob/master/ts/examples/calculator/calculator-server.ts - * - * - * - * - * - * @see {@link DedicatedWorkerServer}, {@link IProtocol} - * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#iclientdriver) - * @author Jeongho Nam - */ - class DedicatedWorkerClientDriver extends DedicatedWorkerCommunicator implements IClientDriver { - /** - * Default Constructor. - */ - constructor(); - /** - * @inheritdoc - */ - listen(listener: IProtocol): void; - /** - * @inheritdoc - */ - close(): void; - /** - * @inheritdoc - */ - sendData(invoke: Invoke): void; - } -} -declare namespace samchon.protocol { - /** - * Communicator with remote web-browser. - * - * {@link SharedWorkerClientDriver} is a class taking full charge of network communication with web browsers. This - * {@link SharedWorkerClientDriver} object is always created by {@link SharedWorkerServer} class. When you got this - * {@link SharedWorkerClientDriver} object from {@link SharedWorkerServer.addClient SharedWorkerServer.addClient()}, - * then specify {@link IProtocol listener} with the - * {@link SharedWorkerClientDriver.listen SharedWorkerClientDriver.listen()} method. - * - * #### Why SharedWorker be a server? - * SharedWorker, it allows only an instance (process) to be created whether the SharedWorker is declared in a browser - * or multiple browsers. To integrate them, messages are being sent and received. Doesn't it seem like a relationship - * between a server and clients? Thus, Samchon Framework consider the SharedWorker as a server and browsers as - * clients. - * - * The class {@link SharedWorkerCommunicator} is designed make such relationship. From now on, SharedWorker is a - * {@link SharedWorkerServer server} and {@link SharedWorkerServerConnector browsers} are clients. Integrate the - * server and clients with this {@link SharedWorkerCommunicator}. - * - * #### [Inherited] {@link IClientDriver} - * {@link IClientDriver} is a type of {@link ICommunicator}, specified for communication with remote client who has - * connected in a {@link IServer server}. It takes full charge of network communication with the remote client. - * - * The {@link IClientDriver} object is created and delivered from {@link IServer} and - * {@link IServer.addClient IServer.addClient()}. Those are derived types from this {@link IClientDriver}, being - * created by the matched {@link IServer} object. - * - * Protocol | Derived Type | Created By - * ------------------------|-------------------------------------|---------------------------- - * Samchon Framework's own | {@link ClientDriver} | {@link Server} - * Web-socket protocol | {@link WebClientDriver} | {@link WebServer} - * DedicatedWorker | {@link DedicatedWorkerClinetDriver} | {@link DedicatedWorkerServer} - * SharedWorker | {@link SharedWorkerClientDriver} | {@link SharedWorkerServer} - * - * When you've got an {@link IClientDriver} object from the {@link IServer.addClient IServer.addClient()}, then - * specify {@link IProtocol listener} with {@link IClient.listen IClient.listen()}. Whenever a replied message comes - * from the remote system, the message will be converted to an {@link Invoke} class and the {@link Invoke} object - * will be shifted to the {@link IProtocol listener}'s {@link IProtocol.replyData IProtocol.replyData()} method. - * Below code is an example specifying and managing the {@link IProtocol listener} objects. - * - * - https://github.com/samchon/framework/blob/master/ts/examples/calculator/calculator-server.ts - * - * - * - * - * - * @see {@link SharedWorkerServer}, {@link IProtocol} - * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#iclientdriver) - * @author Jeongho Nam - */ - class SharedWorkerClientDriver extends SharedWorkerCommunicator implements IClientDriver { - private listening_; - /** - * Construct from a MessagePort object. - */ - constructor(port: MessagePort); - /** - * @inheritdoc - */ - listen(listener: IProtocol): void; - } -} -declare namespace samchon.protocol { - /** - * A container of entity, and it's a type of entity, too. - * - * ![Class Diagram](http://samchon.github.io/framework/images/design/ts_class_diagram/protocol_message_protocol.png) - * - * @handbook [Protocol - Standard Message](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Standard_Message) - * @author Jeongho Nam - */ - interface IEntityGroup extends IEntity, std.base.IContainer { - /** - * Construct data of the Entity from an XML object. - * - * Constructs the EntityArray's own member variables only from the input XML object. - * - * Do not consider about constructing children Entity objects' data in EntityArray::construct(). - * Those children Entity objects' data will constructed by their own construct() method. Even insertion - * of XML objects representing children are done by abstract method of EntityArray::toXML(). - * - * Constructs only data of EntityArray's own. - */ - construct(xml: library.XML): void; - /** - * Factory method of a child Entity. - * - * EntityArray::createChild() is a factory method creating a new child Entity which is belonged - * to the EntityArray. This method is called by EntityArray::construct(). The children construction - * methods Entity::construct() will be called by abstract method of the EntityArray::construct(). - * - * @return A new child Entity belongs to EntityArray. - */ - createChild(xml: library.XML): T; - /** - * Get iterator to element. - * - * Searches the container for an element with a identifier equivalent to *key* and returns an - * iterator to it if found, otherwise it returns an iterator to {@link end end()}. - * - * Two keys are considered equivalent if the container's comparison object returns false reflexively - * (i.e., no matter the order in which the elements are passed as arguments). - * - * Another member functions, {@link has has()} and {@link count count()}, can be used to just check - * whether a particular *key* exists. - * - * @param key Key to be searched for - * @return An iterator to the element, if an element with specified *key* is found, or - * {@link end end()} otherwise. - */ - /** - * Whether have the item or not. - * - * Indicates whether a map has an item having the specified identifier. - * - * @param key Key value of the element whose mapped value is accessed. - * - * @return Whether the map has an item having the specified identifier. - */ - has(key: any): boolean; - /** - * Count elements with a specific key. - * - * Searches the container for elements whose key is *key* and returns the number of elements found. - * - * @param key Key value to be searched for. - * - * @return The number of elements in the container with a *key*. - */ - count(key: any): number; - /** - * Get an element - * - * Returns a reference to the mapped value of the element identified with *key*. - * - * @param key Key value of the element whose mapped value is accessed. - * - * @throw exception out of range - * - * @return A reference object of the mapped value (_Ty) - */ - get(key: any): T; - /** - * A tag name of children objects. - */ - CHILD_TAG(): string; - /** - * Get an XML object represents the EntityArray. - * - * Archives the EntityArray's own member variables only to the returned XML object. - * - * Do not consider about archiving children Entity objects' data in EntityArray::toXML(). - * Those children Entity objects will converted to XML object by their own toXML() method. The - * insertion of XML objects representing children are done by abstract method of - * EntityArray::toXML(). - * - * Archives only data of EntityArray's own. - */ - toXML(): library.XML; - } - /** - * @hidden - */ - namespace IEntityGroup { - /** - * @hidden - */ - function construct(entityGroup: IEntityGroup, xml: library.XML, ...prohibited_names: string[]): void; - /** - * @hidden - */ - function toXML(entityGroup: IEntityGroup, ...prohibited_names: string[]): library.XML; - function has(entityGroup: IEntityGroup, key: any): boolean; - function count(entityGroup: IEntityGroup, key: any): number; - function get(entityGroup: IEntityGroup, key: any): T; - } -} -declare namespace samchon.protocol { - /** - * @inheritdoc - */ - abstract class EntityArray extends std.Vector implements IEntityGroup { - /** - * @inheritdoc - */ - construct(xml: library.XML): void; - /** - * @inheritdoc - */ - abstract createChild(xml: library.XML): T; - /** - * @inheritdoc - */ - key(): any; - /** - * @inheritdoc - */ - has(key: any): boolean; - /** - * @inheritdoc - */ - count(key: any): number; - /** - * @inheritdoc - */ - get(key: any): T; - /** - * @inheritdoc - */ - abstract TAG(): string; - /** - * @inheritdoc - */ - abstract CHILD_TAG(): string; - /** - * @inheritdoc - */ - toXML(): library.XML; - } -} -declare namespace samchon.protocol { - /** - * @inheritdoc - */ - abstract class EntityList extends std.List implements IEntityGroup { - /** - * @inheritdoc - */ - construct(xml: library.XML): void; - /** - * @inheritdoc - */ - abstract createChild(xml: library.XML): T; - /** - * @inheritdoc - */ - key(): any; - /** - * @inheritdoc - */ - has(key: any): boolean; - /** - * @inheritdoc - */ - count(key: any): number; - /** - * @inheritdoc - */ - get(key: any): T; - /** - * @inheritdoc - */ - abstract TAG(): string; - /** - * @inheritdoc - */ - abstract CHILD_TAG(): string; - /** - * @inheritdoc - */ - toXML(): library.XML; - } -} -declare namespace samchon.protocol { - /** - * @inheritdoc - */ - abstract class EntityDeque extends std.Deque implements IEntityGroup { - /** - * @inheritdoc - */ - construct(xml: library.XML): void; - /** - * @inheritdoc - */ - abstract createChild(xml: library.XML): T; - /** - * @inheritdoc - */ - key(): any; - /** - * @inheritdoc - */ - has(key: any): boolean; - /** - * @inheritdoc - */ - count(key: any): number; - /** - * @inheritdoc - */ - get(key: any): T; - /** - * @inheritdoc - */ - abstract TAG(): string; - /** - * @inheritdoc - */ - abstract CHILD_TAG(): string; - /** - * @inheritdoc - */ - toXML(): library.XML; - } -} -declare namespace samchon.protocol { - /** - * Standard message of network I/O. - * - * {@link Invoke} is a class used in network I/O in protocol package of Samchon Framework. - * - * The Invoke message has an XML structure like the result screen of provided example in below. - * We can enjoy lots of benefits by the normalized and standardized message structure used in - * network I/O. - * - * The greatest advantage is that we can make any type of network system, even how the system - * is enourmously complicated. As network communication message is standardized, we only need to - * concentrate on logical relationships between network systems. We can handle each network system - * like a object (class) in OOD. And those relationships can be easily designed by using design - * pattern. - * - * In Samchon Framework, you can make any type of network system with basic componenets - * (IProtocol, IServer and ICommunicator) by implemens or inherits them, like designing - * classes of S/W architecture. - * - * ![Class Diagram](http://samchon.github.io/framework/images/design/ts_class_diagram/protocol_message_protocol.png) - * - * @see {@link IProtocol} - * @author Jeongho Nam - */ - class Invoke extends EntityArray { - /** - * Listener, represent function's name. - */ - private listener; - /** - * Default Constructor. - */ - constructor(); - constructor(listener: string); - /** - * Copy Constructor. - * - * @param invoke - */ - constructor(invoke: Invoke); - /** - * Construct from listener and parametric values. - * - * @param listener - * @param parameters - */ - constructor(listener: string, ...parameters: Array); - /** - * @inheritdoc - */ - createChild(xml: library.XML): InvokeParameter; - /** - * Get listener. - */ - getListener(): string; - /** - * Get arguments for Function.apply(). - * - * @return An array containing values of the contained parameters. - */ - getArguments(): Array; - /** - * Apply to a matched function. - * - * @param obj Target {@link IProtocol} object to find matched function. - * @return Whether succeded to find matched function. - */ - apply(obj: IProtocol): boolean; - /** - * Apply to a function. - * - * @param thisArg Owner of the function. - * @param func Function to call. - */ - apply(thisArg: IProtocol, func: Function): void; - /** - * @inheritdoc - */ - TAG(): string; - /** - * @inheritdoc - */ - CHILD_TAG(): string; - } -} -declare namespace samchon.protocol { - /** - * A parameter belongs to an Invoke. - * - * ![Class Diagram](http://samchon.github.io/framework/images/design/ts_class_diagram/protocol_message_protocol.png) - * - * @author Jeongho Nam - */ - class InvokeParameter extends Entity { - /** - * Name of the parameter. - * - * @details Optional property, can be omitted. - */ - protected name: string; - /** - * Type of the parameter. - */ - protected type: string; - /** - * Value of the parameter. - */ - protected value: string | number | library.XML | Uint8Array; - /** - * Default Constructor. - */ - constructor(); - constructor(val: number); - constructor(val: string); - constructor(val: library.XML); - constructor(val: Uint8Array); - /** - * Construct from variable name and number value. - * - * @param name - * @param val - */ - constructor(name: string, val: number); - constructor(name: string, val: string); - constructor(name: string, val: library.XML); - constructor(name: string, val: Uint8Array); - /** - * @inheritdoc - */ - construct(xml: library.XML): void; - setValue(value: number): void; - setValue(value: string): void; - setValue(value: library.XML): void; - setValue(value: Uint8Array): void; - /** - * @inheritdoc - */ - key(): any; - /** - * Get name. - */ - getName(): string; - /** - * Get type. - */ - getType(): string; - /** - * Get value. - */ - getValue(): any; - /** - * @inheritdoc - */ - TAG(): string; - /** - * @inheritdoc - */ - toXML(): library.XML; - } -} -declare namespace samchon.protocol { - /** - * History of an {@link Invoke} message. - * - * The {@link InvokeHistory} is a class archiving history log of an {@link Invoke} message with elapsed time. This - * {@link InvokeHistory} class is used to report elapsed time of handling a requested process from **slave** to - * **master** system. - * - * The **master** system utilizes derived {@link InvokeHistory} objects to compute performance indices. - * - {@link ParallelSytem.getPerformance} - * - {@link DistributedProcess.getResource} - * - * @author Jeongho Nam - */ - class InvokeHistory extends protocol.Entity { - /** - * @hidden - */ - private uid; - /** - * @hidden - */ - private listener; - /** - * @hidden - */ - private start_time_; - /** - * @hidden - */ - private end_time_; - /** - * Default Constructor. - */ - constructor(); - /** - * Construct from an {@link Invoke} message. - * - * @param invoke An {@link Invoke} message requesting a *parallel or distributed process*. - */ - constructor(invoke: protocol.Invoke); - /** - * @inheritdoc - */ - construct(xml: library.XML): void; - /** - * Complete the history. - * - * Completes the history and determines the {@link getEndTime end time}. - */ - complete(): void; - key(): number; - /** - * Get unique ID. - */ - getUID(): number; - /** - * Get {@link Invoke.getListener listener} of the {@link Invoke} message. - */ - getListener(): string; - /** - * Get start time. - */ - getStartTime(): Date; - /** - * Get end time. - */ - getEndTime(): Date; - /** - * Compute elapsed time. - * - * @return nanoseconds. - */ - computeElapsedTime(): number; - /** - * @inheritdoc - */ - TAG(): string; - /** - * @inheritdoc - */ - toXML(): library.XML; - /** - * Convert to an {@link Invoke} message. - * - * Creates and returns an {@link Invoke} message that is used to reporting to the **master**. - */ - toInvoke(): protocol.Invoke; - } -} -declare namespace samchon.protocol { - /** - * An interface for {@link Invoke} message chain. - * - * {@link IProtocol} is an interface for {@link Invoke} message, which is standard message of network I/O in - * *Samchon Framework*, chain. The {@link IProtocol} interface is used to network drivers and some classes which are - * in a relationship of *Chain of Responsibility Pattern* with those network drivers. - * - * Implements {@link IProtocol} if the class sends and handles {@link Invoke} messages. Looking around source codes of - * the *Samchon Framework*, especially *Templates*, you can find out that all the classes and modules handling - * {@link Invoke} messages are always implementing this {@link IProtocol}. - * - * - * - * - * - * @see {@link Invoke} - * @handbook https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#iprotocol - * @author Jeongho Nam - */ - interface IProtocol { - /** - * Sending message. - * - * Sends message to related system or shifts the responsibility to chain. - * - * @param invoke Invoke message to send - */ - replyData(invoke: Invoke): void; - /** - * Handling replied message. - * - * Handles replied message or shifts the responsibility to chain. - * - * @param invoke An {@link Invoke} message has received. - */ - sendData(invoke: Invoke): void; - } -} -declare namespace samchon.protocol { - /** - * An interface for a server. - * - * {@link IServer} is an interfaec for server classes who are providing methods for {@link open opening a server} and - * {@link IClientDriver accepting clients}. - * - * To open a server, extends one of derived class under below considedring which protocol to follow first. At next, - * overrides {@link addClient addClient()} method who accepts a newly connected client as an {@link IClientDriver} - * object. Then at last, call {@link open open()} method with specified port number. - * - * Protocol | Derived Type | Related {@link IClientDriver} - * ------------------------|-------------------------------|------------------------------------- - * Samchon Framework's own | {@link Server} | {@link ClientDriver} - * Web-socket protocol | {@link WebServer} | {@link WebClientDriver} - * DedicatedWorker | {@link DedicatedWorkerServer} | {@link DedicatedWorkerClientDriver} - * SharedWorker | {@link SharedWorkerServer} | {@link SharedWorkerClientDriver} - * - * Below codes and classes will be good examples for comprehending how to open a server and handle remote clients. - * - https://github.com/samchon/framework/blob/master/ts/examples/calculator/calculator-server.ts - * - https://github.com/samchon/framework/blob/master/ts/examples/chat-server/server.ts - * - {@link service.Server} - * - {@link external.ExternalClientArray} - * - {@link slave.SlaveServer} - * - * If you're embarrased because your class already extended another one, then use {@link IServerBase}. - * - * - * - * - * - * @see {@link IClientDriver}, {@link IServerBase} - * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#iserver) - * @author Jeongho Nam - */ - interface IServer { - /** - * Open server. - * - * @param port Port number to open. - */ - open(port: number): void; - /** - * Close server. - * - * Close opened server. All remote clients, have connected with this server, are also closed and their call back - * functions, for closed connection, {@link IClientDriver.onClose} are also called. - */ - close(): void; - /** - * Add a newly connected remote client. - * - * The {@link addClient addClient()} is an abstract method being called when a remote client is newly connected - * with {@link IClientDriver} object who communicates with the remote system. Overrides this method and defines - * what to do with the *driver*, a newly connected remote client. - * - * Below methods and example codes may be good for comprehending how to utilize this {@link addClient} method. - * - * - https://github.com/samchon/framework/blob/master/ts/examples/calculator/calculator-server.ts - * - https://github.com/samchon/framework/blob/master/ts/examples/chat-server/server.ts - * - {@link service.Server.addClient} - * - {@link external.ExternalClientArray.addClient} - * - {@link slave.SlaveServer.addClient} - * - * @param driver A {@link ICommunicator communicator} with (newly connected) remote client. - */ - addClient(driver: IClientDriver): void; - } -} -declare namespace samchon.protocol { - /** - * A server. - * - * The {@link Server} is an abstract class designed to open a server and accept clients who are following Samchon - * Framework's own protocol. Extends this {@link Server} class and overrides {@link addClient addClient()} method to - * define what to do with newly connected {@link ClientDriver remote clients}. - * - * #### [Inherited] {@link IServer} - * {@link IServer} is an interfaec for server classes who are providing methods for {@link open opening a server} and - * {@link IClientDriver accepting clients}. - * - * To open a server, extends one of derived class under below considedring which protocol to follow first. At next, - * overrides {@link addClient addClient()} method who accepts a newly connected client as an {@link IClientDriver} - * object. Then at last, call {@link open open()} method with specified port number. - * - * Protocol | Derived Type | Related {@link IClientDriver} - * ------------------------|-------------------------------|------------------------------------- - * Samchon Framework's own | {@link Server} | {@link ClientDriver} - * Web-socket protocol | {@link WebServer} | {@link WebClientDriver} - * DedicatedWorker | {@link DedicatedWorkerServer} | {@link DedicatedWorkerClientDriver} - * SharedWorker | {@link SharedWorkerServer} | {@link SharedWorkerClientDriver} - * - * Below codes and classes will be good examples for comprehending how to open a server and handle remote clients. - * - https://github.com/samchon/framework/blob/master/ts/examples/calculator/calculator-server.ts - * - https://github.com/samchon/framework/blob/master/ts/examples/chat-server/server.ts - * - {@link service.Server} - * - {@link external.ExternalClientArray} - * - {@link slave.SlaveServer} - * - * If you're embarrased because your class already extended another one, then use {@link IServerBase}. - * - * - * - * - * - * @see {@link ClientDriver}, {@link ServerBase} - * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#iserver) - * @author Jeongho Nam - */ - abstract class Server implements IServer { - /** - * @hidden - */ - private server; - /** - * @inheritdoc - */ - abstract addClient(driver: ClientDriver): void; - /** - * @inheritdoc - */ - open(port: number): void; - /** - * @inheritdoc - */ - close(): void; - /** - * @hidden - */ - private handle_connect(socket); - } -} -declare namespace samchon.protocol { - /** - * A web server. - * - * The {@link WebServer} is an abstract class designed to open a server and accept clients who are following - * web-socket protocol. Extends this {@link WebServer} class and overrides {@link addClient addClient()} method to - * define what to do with newly connected {@link WebClientDriver remote clients}. - * - * #### [Inherited] {@link IServer} - * {@link IServer} is an interfaec for server classes who are providing methods for {@link open opening a server} and - * {@link IClientDriver accepting clients}. - * - * To open a server, extends one of derived class under below considedring which protocol to follow first. At next, - * overrides {@link addClient addClient()} method who accepts a newly connected client as an {@link IClientDriver} - * object. Then at last, call {@link open open()} method with specified port number. - * - * Protocol | Derived Type | Related {@link IClientDriver} - * ------------------------|-------------------------------|------------------------------------- - * Samchon Framework's own | {@link Server} | {@link ClientDriver} - * Web-socket protocol | {@link WebServer} | {@link WebClientDriver} - * DedicatedWorker | {@link DedicatedWorkerServer} | {@link DedicatedWorkerClientDriver} - * SharedWorker | {@link SharedWorkerServer} | {@link SharedWorkerClientDriver} - * - * Below codes and classes will be good examples for comprehending how to open a server and handle remote clients. - * - https://github.com/samchon/framework/blob/master/ts/examples/calculator/calculator-server.ts - * - https://github.com/samchon/framework/blob/master/ts/examples/chat-server/server.ts - * - {@link service.Server} - * - {@link external.ExternalClientArray} - * - {@link slave.SlaveServer} - * - * If you're embarrased because your class already extended another one, then use {@link IServerBase}. - * - * - * - * - * - * @see {@link WebClientDriver}, {@link WebServerBase} - * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#iserver) - * @author Jeongho Nam - */ - abstract class WebServer implements IServer { - /** - * @hidden - */ - private http_server_; - /** - * @hidden - */ - private sequence_; - /** - * @hidden - */ - private my_port_; - /** - * Default Constructor. - */ - constructor(); - /** - * @inheritdoc - */ - open(port: number): void; - /** - * @inheritdoc - */ - close(): void; - /** - * @inheritdoc - */ - abstract addClient(driver: WebClientDriver): void; - /** - * @hidden - */ - private handle_request(request); - /** - * @hidden - */ - private get_session_id(cookies); - /** - * @hidden - */ - private issue_session_id(); - } -} -declare namespace samchon.protocol { - /** - * A SharedWorker server. - * - * The {@link DedicatedWorkerServer} is an abstract class is realized to open a DedicatedWorker server and accept - * web-browser client (master). Extends this {@link DedicatedWorkerServer} class and overrides - * {@link addClient addClient()} method to define what to do with a newly connected - * {@link DedicatedWorkerClientDriver remote client}. - * - * #### Why DedicatedWorker be a server? - * In JavaScript environment, there's no way to implement multi-threading function. Instead, JavaScript supports the - * **Worker**, creating a new process. However, the **Worker** does not shares memory addresses. To integrate the - * **Worker** with its master, only communication with string or binary data is allowed. Doesn't it seem like a network - * communication? Furthermore, there's not any difference between the worker communication and network communication. - * It's the reason why Samchon Framework considers the **Worker** as a network node. - * - * The class {@link DedicatedWorkerCommunicator} is designed make such relationship. From now on, DedicatedWorker is a - * {@link DedicatedWorkerServer server} and {@link DedicatedWorkerServerConnector browser} is a client. Integrate the - * server and clients with this {@link DedicatedWorkerCommunicator}. - * - * #### [Inherited] {@link IServer} - * {@link IServer} is an interfaec for server classes who are providing methods for {@link open opening a server} and - * {@link IClientDriver accepting clients}. - * - * To open a server, extends one of derived class under below considedring which protocol to follow first. At next, - * overrides {@link addClient addClient()} method who accepts a newly connected client as an {@link IClientDriver} - * object. Then at last, call {@link open open()} method with specified port number. - * - * Protocol | Derived Type | Related {@link IClientDriver} - * ------------------------|-------------------------------|------------------------------------- - * Samchon Framework's own | {@link Server} | {@link ClientDriver} - * Web-socket protocol | {@link WebServer} | {@link WebClientDriver} - * DedicatedWorker | {@link DedicatedWorkerServer} | {@link DedicatedWorkerClientDriver} - * SharedWorker | {@link SharedWorkerServer} | {@link SharedWorkerClientDriver} - * - * Below codes and classes will be good examples for comprehending how to open a server and handle remote clients. - * - https://github.com/samchon/framework/blob/master/ts/examples/calculator/calculator-server.ts - * - https://github.com/samchon/framework/blob/master/ts/examples/chat-server/server.ts - * - {@link service.Server} - * - {@link external.ExternalClientArray} - * - {@link slave.SlaveServer} - * - * If you're embarrased because your class already extended another one, then use {@link IServerBase}. - * - * - * - * - * - * @see {@link DedicatedWorkerClientDriver}, {@link DedicatedWorkerServerBase} - * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#iserver) - * @author Jeongho Nam - */ - abstract class DedicatedWorkerServer implements IServer { - /** - * @inheritdoc - */ - open(): void; - /** - * @inheritdoc - */ - close(): void; - /** - * @inheritdoc - */ - abstract addClient(driver: DedicatedWorkerClientDriver): void; - } -} -declare namespace samchon.protocol { - /** - * A SharedWorker server. - * - * The {@link SharedWorker} is an abstract class is realized to open a SharedWorker server and accept web-browser - * clients. Extends this {@link SharedWorkerServer} class and overrides {@link addClient addClient()} method to - * define what to do with newly connected {@link SharedWorkerClientDriver remote clients}. - * - * #### Why SharedWorker be a server? - * SharedWorker, it allows only an instance (process) to be created whether the SharedWorker is declared in a browser - * or multiple browsers. To integrate them, messages are being sent and received. Doesn't it seem like a relationship - * between a server and clients? Thus, Samchon Framework consider the SharedWorker as a server and browsers as - * clients. - * - * The class {@link SharedWorkerCommunicator} is designed make such relationship. From now on, SharedWorker is a - * {@link SharedWorkerServer server} and {@link SharedWorkerServerConnector browsers} are clients. Integrate the - * server and clients with this {@link SharedWorkerCommunicator}. - * - * #### [Inherited] {@link IServer} - * {@link IServer} is an interfaec for server classes who are providing methods for {@link open opening a server} and - * {@link IClientDriver accepting clients}. - * - * To open a server, extends one of derived class under below considedring which protocol to follow first. At next, - * overrides {@link addClient addClient()} method who accepts a newly connected client as an {@link IClientDriver} - * object. Then at last, call {@link open open()} method with specified port number. - * - * Protocol | Derived Type | Related {@link IClientDriver} - * ------------------------|-------------------------------|------------------------------------- - * Samchon Framework's own | {@link Server} | {@link ClientDriver} - * Web-socket protocol | {@link WebServer} | {@link WebClientDriver} - * DedicatedWorker | {@link DedicatedWorkerServer} | {@link DedicatedWorkerClientDriver} - * SharedWorker | {@link SharedWorkerServer} | {@link SharedWorkerClientDriver} - * - * Below codes and classes will be good examples for comprehending how to open a server and handle remote clients. - * - https://github.com/samchon/framework/blob/master/ts/examples/calculator/calculator-server.ts - * - https://github.com/samchon/framework/blob/master/ts/examples/chat-server/server.ts - * - {@link service.Server} - * - {@link external.ExternalClientArray} - * - {@link slave.SlaveServer} - * - * If you're embarrased because your class already extended another one, then use {@link IServerBase}. - * - * - * - * - * - * @see {@link SharedWorkerClientDriver}, {@link SharedWorkerServerBase} - * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#iserver) - * @author Jeongho Nam - */ - abstract class SharedWorkerServer implements IServer { - /** - * @inheritdoc - */ - abstract addClient(driver: SharedWorkerClientDriver): void; - /** - * @inheritdoc - */ - open(): void; - /** - * @inheritdoc - */ - close(): void; - /** - * @hidden - */ - private handle_connect(event); - } -} -declare namespace samchon.protocol { - /** - * An interface for substitute server classes. - * - * {@link IServerBase} is an interface for substitue server classes who subrogate server's role. - * - * The easiest way to defining a server class is to extending one of them below, who implemented the {@link IServer}. - * However, it is impossible (that is, if the class is already extending another class), you can instead implement - * the {@link IServer} interface, create an {@link IServerBase} member, and write simple hooks to route calls into - * the aggregated {@link IServerBase}. - * - * Protocol | {@link IServer} | {@link IServerBase} | {@link IClientDriver} - * ------------------------|-------------------------------|-----------------------------------|------------------------------------- - * Samchon Framework's own | {@link Server} | {@link ServerBase} | {@link ClientDriver} - * Web-socket protocol | {@link WebServer} | {@link WebServerBase} | {@link WebClientDriver} - * DedicatedWorker | {@link DedicatedWorkerServer} | {@link DedicatedWorkerServerBase} | {@link DedicatedWorkerClientDriver} - * SharedWorker | {@link SharedWorkerServer} | {@link SharedWorkerServerBase} | {@link SharedWorkerClientDriver} - * - * After the hooking to aggregated {@link IServerBase} object, overrides {@link addClient addClient()} method who - * accepts a newly connected client as an {@link IClientDriver} object. At last, call {@link open open()} method with - * specified port number. - * - * ```typescript - * class MyServer extends Something implements IServer - * { - * private server_base_: IServerBase = new WebServerBase(this); - * - * public addClient(driver: IClientDriver): void - * { - * // WHAT TO DO WHEN A CLIENT HAS CONNECTED - * } - * - * public open(port: number): void - * { - * this.server_base_.open(); - * } - * public close(): void - * { - * this.server_base_.close(); - * } - * } - * ``` - * - * - * - * - * - * @see {@link IServer}, {@link IClientDriver} - * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#iserverbase) - * @author Jeongho Nam - */ - interface IServerBase extends IServer { - } -} -declare namespace samchon.protocol { - /** - * A substitute {@link Server}. - * - * The {@link ServerBase} is a substitute class who subrogates {@link Server}'s responsibility. - * - * #### [Inherited] {@link IServerBase} - * {@link IServerBase} is an interface for substitue server classes who subrogate server's role. - * - * The easiest way to defining a server class is to extending one of them below, who implemented the {@link IServer}. - * However, it is impossible (that is, if the class is already extending another class), you can instead implement - * the {@link IServer} interface, create an {@link IServerBase} member, and write simple hooks to route calls into - * the aggregated {@link IServerBase}. - * - * Protocol | {@link IServer} | {@link IServerBase} | {@link IClientDriver} - * ------------------------|-------------------------------|-----------------------------------|------------------------------------- - * Samchon Framework's own | {@link Server} | {@link ServerBase} | {@link ClientDriver} - * Web-socket protocol | {@link WebServer} | {@link WebServerBase} | {@link WebClientDriver} - * DedicatedWorker | {@link DedicatedWorkerServer} | {@link DedicatedWorkerServerBase} | {@link DedicatedWorkerClientDriver} - * SharedWorker | {@link SharedWorkerServer} | {@link SharedWorkerServerBase} | {@link SharedWorkerClientDriver} - * - * After the hooking to aggregated {@link IServerBase} object, overrides {@link addClient addClient()} method who - * accepts a newly connected client as an {@link IClientDriver} object. At last, call {@link open open()} method with - * specified port number. - * - * ```typescript - * class MyServer extends Something implements IServer - * { - * private server_base_: IServerBase = new WebServerBase(this); - * - * public addClient(driver: IClientDriver): void - * { - * // WHAT TO DO WHEN A CLIENT HAS CONNECTED - * } - * - * public open(port: number): void - * { - * this.server_base_.open(); - * } - * public close(): void - * { - * this.server_base_.close(); - * } - * } - * ``` - * - * - * - * - * - * - * @see {@link Server}, {@link ClientDriver} - * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#iserverbase) - * @author Jeongho Nam - */ - class ServerBase extends Server implements IServerBase { - /** - * @hidden - */ - private hooker_; - /** - * Construct from a *hooker*. - * - * @param hooker A hooker throwing responsibility of server's role. - */ - constructor(hooker: IServer); - /** - * @inheritdoc - */ - addClient(driver: IClientDriver): void; - } -} -declare namespace samchon.protocol { - /** - * A substitute {@link WebServer}. - * - * The {@link WebServerBase} is a substitute class who subrogates {@link WebServer}'s responsibility. - * - * #### [Inherited] {@link IServerBase} - * {@link IServerBase} is an interface for substitue server classes who subrogate server's role. - * - * The easiest way to defining a server class is to extending one of them below, who implemented the {@link IServer}. - * However, it is impossible (that is, if the class is already extending another class), you can instead implement - * the {@link IServer} interface, create an {@link IServerBase} member, and write simple hooks to route calls into - * the aggregated {@link IServerBase}. - * - * Protocol | {@link IServer} | {@link IServerBase} | {@link IClientDriver} - * ------------------------|-------------------------------|-----------------------------------|------------------------------------- - * Samchon Framework's own | {@link Server} | {@link ServerBase} | {@link ClientDriver} - * Web-socket protocol | {@link WebServer} | {@link WebServerBase} | {@link WebClientDriver} - * DedicatedWorker | {@link DedicatedWorkerServer} | {@link DedicatedWorkerServerBase} | {@link DedicatedWorkerClientDriver} - * SharedWorker | {@link SharedWorkerServer} | {@link SharedWorkerServerBase} | {@link SharedWorkerClientDriver} - * - * After the hooking to aggregated {@link IServerBase} object, overrides {@link addClient addClient()} method who - * accepts a newly connected client as an {@link IClientDriver} object. At last, call {@link open open()} method with - * specified port number. - * - * ```typescript - * class MyServer extends Something implements IServer - * { - * private server_base_: IServerBase = new WebServerBase(this); - * - * public addClient(driver: IClientDriver): void - * { - * // WHAT TO DO WHEN A CLIENT HAS CONNECTED - * } - * - * public open(port: number): void - * { - * this.server_base_.open(); - * } - * public close(): void - * { - * this.server_base_.close(); - * } - * } - * ``` - * - * - * - * - * - * @see {@link WebServer}, {@link WebClientDriver} - * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#iserverbase) - * @author Jeongho Nam - */ - class WebServerBase extends WebServer implements IServerBase { - /** - * @hidden - */ - private hooker_; - /** - * Construct from a *hooker*. - * - * @param hooker A hooker throwing responsibility of server's role. - */ - constructor(hooker: IServer); - /** - * @inheritdoc - */ - addClient(driver: IClientDriver): void; - } -} -declare namespace samchon.protocol { - /** - * A substitute {@link DedicatedWorkerServer}. - * - * The {@link DedicatedWorkerServerBase} is a substitute class who subrogates {@link DedicatedWorkerServer}'s - * responsibility. - * - * #### [Inherited] {@link IServerBase} - * {@link IServerBase} is an interface for substitue server classes who subrogate server's role. - * - * The easiest way to defining a server class is to extending one of them below, who implemented the {@link IServer}. - * However, it is impossible (that is, if the class is already extending another class), you can instead implement - * the {@link IServer} interface, create an {@link IServerBase} member, and write simple hooks to route calls into - * the aggregated {@link IServerBase}. - * - * Protocol | {@link IServer} | {@link IServerBase} | {@link IClientDriver} - * ------------------------|-------------------------------|-----------------------------------|------------------------------------- - * Samchon Framework's own | {@link Server} | {@link ServerBase} | {@link ClientDriver} - * Web-socket protocol | {@link WebServer} | {@link WebServerBase} | {@link WebClientDriver} - * DedicatedWorker | {@link DedicatedWorkerServer} | {@link DedicatedWorkerServerBase} | {@link DedicatedWorkerClientDriver} - * SharedWorker | {@link SharedWorkerServer} | {@link SharedWorkerServerBase} | {@link SharedWorkerClientDriver} - * - * After the hooking to aggregated {@link IServerBase} object, overrides {@link addClient addClient()} method who - * accepts a newly connected client as an {@link IClientDriver} object. At last, call {@link open open()} method with - * specified port number. - * - * ```typescript - * class MyServer extends Something implements IServer - * { - * private server_base_: IServerBase = new WebServerBase(this); - * - * public addClient(driver: IClientDriver): void - * { - * // WHAT TO DO WHEN A CLIENT HAS CONNECTED - * } - * - * public open(port: number): void - * { - * this.server_base_.open(); - * } - * public close(): void - * { - * this.server_base_.close(); - * } - * } - * ``` - * - * - * - * - * - * @see {@link DedicatedWorkerServer}, {@link DedicatedWorkerClientDriver} - * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#iserverbase) - * @author Jeongho Nam - */ - class DedicatedWorkerServerBase extends DedicatedWorkerServer implements IServerBase { - /** - * @hidden - */ - private hooker_; - /** - * Construct from a *hooker*. - * - * @param hooker A hooker throwing responsibility of server's role. - */ - constructor(hooker: IServer); - /** - * @inheritdoc - */ - addClient(driver: IClientDriver): void; - } -} -declare namespace samchon.protocol { - /** - * A substitute {@link SharedWorkerServer}. - * - * The {@link SharedWorkerServerBase} is a substitute class who subrogates {@link SharedWorkerServer}'s - * responsibility. - * - * #### [Inherited] {@link IServerBase} - * {@link IServerBase} is an interface for substitue server classes who subrogate server's role. - * - * The easiest way to defining a server class is to extending one of them below, who implemented the {@link IServer}. - * However, it is impossible (that is, if the class is already extending another class), you can instead implement - * the {@link IServer} interface, create an {@link IServerBase} member, and write simple hooks to route calls into - * the aggregated {@link IServerBase}. - * - * Protocol | {@link IServer} | {@link IServerBase} | {@link IClientDriver} - * ------------------------|-------------------------------|-----------------------------------|------------------------------------- - * Samchon Framework's own | {@link Server} | {@link ServerBase} | {@link ClientDriver} - * Web-socket protocol | {@link WebServer} | {@link WebServerBase} | {@link WebClientDriver} - * DedicatedWorker | {@link DedicatedWorkerServer} | {@link DedicatedWorkerServerBase} | {@link DedicatedWorkerClientDriver} - * SharedWorker | {@link SharedWorkerServer} | {@link SharedWorkerServerBase} | {@link SharedWorkerClientDriver} - * - * After the hooking to aggregated {@link IServerBase} object, overrides {@link addClient addClient()} method who - * accepts a newly connected client as an {@link IClientDriver} object. At last, call {@link open open()} method with - * specified port number. - * - * ```typescript - * class MyServer extends Something implements IServer - * { - * private server_base_: IServerBase = new WebServerBase(this); - * - * public addClient(driver: IClientDriver): void - * { - * // WHAT TO DO WHEN A CLIENT HAS CONNECTED - * } - * - * public open(port: number): void - * { - * this.server_base_.open(); - * } - * public close(): void - * { - * this.server_base_.close(); - * } - * } - * ``` - * - * - * - * - * - * @see {@link SharedWorkerServer}, {@link SharedWorkerClientDriver} - * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#iserverbase) - * @author Jeongho Nam - */ - class SharedWorkerServerBase extends SharedWorkerServer implements IServerBase { - /** - * @hidden - */ - private hooker_; - /** - * Construct from a *hooker*. - * - * @param hooker A hooker throwing responsibility of server's role. - */ - constructor(hooker: IServer); - /** - * @inheritdoc - */ - addClient(driver: IClientDriver): void; - } -} -declare namespace samchon.protocol { - /** - * An interface for server connector. - * - * {@link IServerConnector} is a type of {@link ICommunicator}, specified for server connector classes who connect to - * the remote server as a client. {@link IServerConnector} provides {@link connect connection method} and takes full - * charge of network communication with the remote server. - * - * Declare specific type of {@link IServerConnector} from {@link IProtocol listener} and call the - * {@link connect connect()} method. Then whenever a replied message comes from the remote system, the message will - * be converted to an {@link Invoke} object and the {@link Invoke} object will be shifted to the - * {@link IProtocol listener}'s {@link IProtocol.replyData IProtocol.replyData()} method. Below code is an example - * connecting to remote server and interacting with it. - * - * - https://github.com/samchon/framework/blob/master/ts/examples/calculator/calculator-application.ts - * - * Note that, protocol of this client and remote server must be matched. Thus, before determining specific type of - * this {@link IServerConnector}, you've to consider which protocol and type the remote server follows. - * - * Protocol | Derived Type | Connect to - * ------------------------|----------------------------------------|------------------------------- - * Samchon Framework's own | {@link ServerConnector} | {@link Server} - * Web-socket protocol | {@link WebServerConnector} | {@link WebServer} - * DedicatedWorker | {@link DedicatedWorkerServerConnector} | {@link DedicatedWorkerServer} - * SharedWorker | {@link SharedWorkerServerConnector} | {@link SharedWorkerServer} - * - * ![Class Diagram](http://samchon.github.io/framework/images/design/ts_class_diagram/protocol_basic_components.png) - * - * @see {@link IServer}, {@link IProtocol} - * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#iserverconnector) - * @author Jeongho Nam - */ - interface IServerConnector extends ICommunicator { - /** - * Callback function for connection completed. - * - * When you call {@link connect connect()} and the connection has completed, then this call back function - * {@link onConnect} will be called. Note that, if the listener of this {@link onConnect} is a member method of - * some class, then you've use the ```bind```. - */ - onConnect: Function; - /** - * Connect to a server. - * - * Connects to a server with specified *host* address and *port* number. After the connection has - * succeeded, callback function {@link onConnect} is called. Listening data from the connected server also begins. - * Replied messages from the connected server will be converted to {@link Invoke} classes and will be shifted to - * the {@link WebCommunicator.listener listener}'s {@link IProtocol.replyData replyData()} method. - * - * If the connection fails immediately, either an event is dispatched or an exception is thrown: an error - * event is dispatched if a host was specified, and an exception is thrown if no host was specified. Otherwise, - * the status of the connection is reported by an event. If the socket is already connected, the existing - * connection is closed first. - * - * @param ip The name or IP address of the host to connect to. - * If no host is specified, the host that is contacted is the host where the calling file resides. - * If you do not specify a host, use an event listener to determine whether the connection was - * successful. - * @param port The port number to connect to. - */ - connect(ip: string, port: number): void; - } -} -declare namespace samchon.protocol { - /** - * Server connnector. - * - * {@link ServerConnector} is a class connecting to remote server who follows Samchon Framework's own protocol and - * taking full charge of network communication with the remote server. Create a {@link ServerConnector} instance from - * the {@IProtocol listener} and call the {@link connect connect()} method. - * - * #### [Inherited] {@link IServerConnector} - * {@link IServerConnector} is a type of {@link ICommunicator}, specified for server connector classes who connect to - * the remote server as a client. {@link IServerConnector} provides {@link connect connection method} and takes full - * charge of network communication with the remote server. - * - * Declare specific type of {@link IServerConnector} from {@link IProtocol listener} and call the - * {@link connect connect()} method. Then whenever a replied message comes from the remote system, the message will - * be converted to an {@link Invoke} object and the {@link Invoke} object will be shifted to the - * {@link IProtocol listener}'s {@link IProtocol.replyData IProtocol.replyData()} method. - * - * Note that, protocol of this client and remote server must be matched. Thus, before determining specific type of - * this {@link IServerConnector}, you've to consider which protocol and type the remote server follows. - * - * Protocol | Derived Type | Connect to - * ------------------------|----------------------------------------|------------------------------- - * Samchon Framework's own | {@link ServerConnector} | {@link Server} - * Web-socket protocol | {@link WebServerConnector} | {@link WebServer} - * DedicatedWorker | {@link DedicatedWorkerServerConnector} | {@link DedicatedWorkerServer} - * SharedWorker | {@link SharedWorkerServerConnector} | {@link SharedWorkerServer} - * - * ![Class Diagram](http://samchon.github.io/framework/images/design/ts_class_diagram/protocol_basic_components.png) - * - * @see {@link Server}, {@link IProtocol} - * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#iserverconnector) - * @author Jeongho Nam - */ - class ServerConnector extends Communicator implements IServerConnector { - /** - * @inheritdoc - */ - onConnect: Function; - /** - * Construct from *listener*. - * - * @param listener A listener object to listen replied message from newly connected client in - * {@link IProtocol.replyData replyData()} as an {@link Invoke} object. - */ - constructor(listener: IProtocol); - /** - * @inheritdoc - */ - connect(ip: string, port: number): void; - /** - * @hidden - */ - private handle_connect(...arg); - } -} -declare namespace samchon.protocol { - /** - * A server connector for web-socket protocol. - * - * {@link WebServerConnector} is a class connecting to remote server who follows Web-socket protocol and taking full - * charge of network communication with the remote server. Create an {@link WebServerConnector} instance from the - * {@IProtocol listener} and call the {@link connect connect()} method. - * - * #### [Inherited] {@link IServerConnector} - * {@link IServerConnector} is a type of {@link ICommunicator}, specified for server connector classes who connect to - * the remote server as a client. {@link IServerConnector} provides {@link connect connection method} and takes full - * charge of network communication with the remote server. - * - * Declare specific type of {@link IServerConnector} from {@link IProtocol listener} and call the - * {@link connect connect()} method. Then whenever a replied message comes from the remote system, the message will - * be converted to an {@link Invoke} class and the {@link Invoke} object will be shifted to the - * {@link IProtocol listener}'s {@link IProtocol.replyData IProtocol.replyData()} method. - * - * Note that, protocol of this client and remote server must be matched. Thus, before determining specific type of - * this {@link IServerConnector}, you've to consider which protocol and type the remote server follows. - * - * Protocol | Derived Type | Connect to - * ------------------------|----------------------------------------|------------------------------- - * Samchon Framework's own | {@link ServerConnector} | {@link Server} - * Web-socket protocol | {@link WebServerConnector} | {@link WebServer} - * DedicatedWorker | {@link DedicatedWorkerServerConnector} | {@link DedicatedWorkerServer} - * SharedWorker | {@link SharedWorkerServerConnector} | {@link SharedWorkerServer} - * - * ![Class Diagram](http://samchon.github.io/framework/images/design/ts_class_diagram/protocol_basic_components.png) - * - * @see {@link WebServer}, {@link IProtocol} - * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#iserverconnector) - * @author Jeongho Nam - */ - class WebServerConnector extends WebCommunicator implements IServerConnector { - /** - * @hidden - */ - private browser_socket_; - /** - * @hidden - */ - private node_client_; - /** - * @inheritdoc - */ - onConnect: Function; - /** - * Construct from *listener*. - * - * @param listener A listener object to listen replied message from newly connected client in - * {@link IProtocol.replyData replyData()} as an {@link Invoke} object. - */ - constructor(listener: IProtocol); - /** - * Connect to a web server. - * - * Connects to a server with specified *host* address, *port* number and *path*. After the connection has - * succeeded, callback function {@link onConnect} is called. Listening data from the connected server also begins. - * Replied messages from the connected server will be converted to {@link Invoke} classes and will be shifted to - * the {@link WebCommunicator.listener listener}'s {@link IProtocol.replyData replyData()} method. - * - * If the connection fails immediately, either an event is dispatched or an exception is thrown: an error - * event is dispatched if a host was specified, and an exception is thrown if no host was specified. Otherwise, - * the status of the connection is reported by an event. If the socket is already connected, the existing - * connection is closed first. - * - * @param ip The name or IP address of the host to connect to. - * If no host is specified, the host that is contacted is the host where the calling file resides. - * If you do not specify a host, use an event listener to determine whether the connection was - * successful. - * @param port The port number to connect to. - * @param path Path of service which you want. - */ - connect(ip: string, port: number, path?: string): void; - /** - * @inheritdoc - */ - close(): void; - /** - * @inheritdoc - */ - sendData(invoke: Invoke): void; - /** - * @hidden - */ - private handle_browser_connect(event); - /** - * @hidden - */ - private handle_browser_message(event); - /** - * @hidden - */ - private handle_node_connect(connection); - } -} -declare namespace samchon.protocol { - /** - * A server connector for DedicatedWorker. - * - * {@link DedicatedWorkerServerConnector} is a class connecting to SharedWorker and taking full charge of network - * communication with the SharedWorker. Create an {@link DedicatedWorkerServer} instance from the - * {@IProtocol listener} and call the {@link connect connect()} method. - * - * #### Why DedicatedWorker be a server? - * In JavaScript environment, there's no way to implement multi-threading function. Instead, JavaScript supports the - * **Worker**, creating a new process. However, the **Worker** does not shares memory addresses. To integrate the - * **Worker** with its master, only communication with string or binary data is allowed. Doesn't it seem like a network - * communication? Furthermore, there's not any difference between the worker communication and network communication. - * It's the reason why Samchon Framework considers the **Worker** as a network node. - * - * The class {@link DedicatedWorkerCommunicator} is designed make such relationship. From now on, DedicatedWorker is a - * {@link DedicatedWorkerServer server} and {@link DedicatedWorkerServerConnector browser} is a client. Integrate the - * server and clients with this {@link DedicatedWorkerCommunicator}. - * - * #### [Inherited] {@link IServerConnector} - * {@link IServerConnector} is a type of {@link ICommunicator}, specified for server connector classes who connect to - * the remote server as a client. {@link IServerConnector} provides {@link connect connection method} and takes full - * charge of network communication with the remote server. - * - * Declare specific type of {@link IServerConnector} from {@link IProtocol listener} and call the - * {@link connect connect()} method. Then whenever a replied message comes from the remote system, the message will - * be converted to an {@link Invoke} class and the {@link Invoke} object will be shifted to the - * {@link IProtocol listener}'s {@link IProtocol.replyData IProtocol.replyData()} method. - * - * Note that, protocol of this client and remote server must be matched. Thus, before determining specific type of - * this {@link IServerConnector}, you've to consider which protocol and type the remote server follows. - * - * Protocol | Derived Type | Connect to - * ------------------------|----------------------------------------|------------------------------- - * Samchon Framework's own | {@link ServerConnector} | {@link Server} - * Web-socket protocol | {@link WebServerConnector} | {@link WebServer} - * DedicatedWorker | {@link DedicatedWorkerServerConnector} | {@link DedicatedWorkerServer} - * SharedWorker | {@link SharedWorkerServerConnector} | {@link SharedWorkerServer} - * - * ![Class Diagram](http://samchon.github.io/framework/images/design/ts_class_diagram/protocol_basic_components.png) - * - * @see {@link DedicatedWorkerServer}, {@link IProtocol} - * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#iserverconnector) - * @author Jeongho Nam - */ - class DedicatedWorkerServerConnector extends DedicatedWorkerCommunicator implements IServerConnector { - /** - * @hidden - */ - private worker; - /** - * @inheritdoc - */ - onConnect: Function; - /** - * Construct from *listener*. - * - * @param listener A listener object to listen replied message from newly connected client in - * {@link IProtocol.replyData replyData()} as an {@link Invoke} object. - */ - constructor(listener: IProtocol); - /** - * @inheritdoc - */ - connect(jsFile: string): void; - /** - * @inheritdoc - */ - close(): void; - /** - * @inheritdoc - */ - sendData(invoke: Invoke): void; - } -} -declare namespace samchon.protocol { - /** - * A server connector for SharedWorker. - * - * {@link SharedWorkerServerConnector} is a class connecting to SharedWorker and taking full charge of network - * communication with the SharedWorker. Create an {@link SharedWorkerServerConnector} instance from the - * {@IProtocol listener} and call the {@link connect connect()} method. - * - * #### Why SharedWorker be a server? - * SharedWorker, it allows only an instance (process) to be created whether the SharedWorker is declared in a browser - * or multiple browsers. To integrate them, messages are being sent and received. Doesn't it seem like a relationship - * between a server and clients? Thus, Samchon Framework consider the SharedWorker as a server and browsers as - * clients. - * - * The class {@link SharedWorkerCommunicator} is designed make such relationship. From now on, SharedWorker is a - * {@link SharedWorkerServer server} and {@link SharedWorkerServerConnector browsers} are clients. Integrate the - * server and clients with this {@link SharedWorkerCommunicator}. - * - * #### [Inherited] {@link IServerConnector} - * {@link IServerConnector} is a type of {@link ICommunicator}, specified for server connector classes who connect to - * the remote server as a client. {@link IServerConnector} provides {@link connect connection method} and takes full - * charge of network communication with the remote server. - * - * Declare specific type of {@link IServerConnector} from {@link IProtocol listener} and call the - * {@link connect connect()} method. Then whenever a replied message comes from the remote system, the message will - * be converted to an {@link Invoke} class and the {@link Invoke} object will be shifted to the - * {@link IProtocol listener}'s {@link IProtocol.replyData IProtocol.replyData()} method. - * - * Note that, protocol of this client and remote server must be matched. Thus, before determining specific type of - * this {@link IServerConnector}, you've to consider which protocol and type the remote server follows. - * - * Protocol | Derived Type | Connect to - * ------------------------|----------------------------------------|------------------------------- - * Samchon Framework's own | {@link ServerConnector} | {@link Server} - * Web-socket protocol | {@link WebServerConnector} | {@link WebServer} - * DedicatedWorker | {@link DedicatedWorkerServerConnector} | {@link DedicatedWorkerServer} - * SharedWorker | {@link SharedWorkerServerConnector} | {@link SharedWorkerServer} - * - * ![Class Diagram](http://samchon.github.io/framework/images/design/ts_class_diagram/protocol_basic_components.png) - * - * @see {@link SharedWorkerServer}, {@link IProtocol} - * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#iserverconnector) - * @author Jeongho Nam - */ - class SharedWorkerServerConnector extends SharedWorkerCommunicator implements IServerConnector { - /** - * @inheritdoc - */ - onConnect: Function; - /** - * Construct from *listener*. - * - * @param listener A listener object to listen replied message from newly connected client in - * {@link IProtocol.replyData replyData()} as an {@link Invoke} object. - */ - constructor(listener: IProtocol); - /** - * Connect to a SharedWorker. - * - * Connects to a server with specified *jstFile* path. If a SharedWorker instance of the *jsFile* is not - * constructed yet, then the SharedWorker will be newly constructed. Otherwise the SharedWorker already exists, - * then connect to the SharedWorker. After those processes, callback function {@link onConnect} is called. - * Listening data from the connected server also begins. Replied messages from the connected server will be - * converted to {@link Invoke} classes and will be shifted to the {@link WebCommunicator.listener listener}'s - * {@link IProtocol.replyData replyData()} method. - * - * If the connection fails immediately, either an event is dispatched or an exception is thrown: an error - * event is dispatched if a host was specified, and an exception is thrown if no host was specified. Otherwise, - * the status of the connection is reported by an event. If the socket is already connected, the existing - * connection is closed first. - * - * @param jsFile Path of JavaScript file to execute who defines SharedWorker. - */ - connect(jsFile: string): void; - } -} -declare namespace samchon.protocol { - /** - * @hidden - */ - namespace socket { - type socket = any; - type server = any; - type http_server = any; - } - /** - * @hidden - */ - namespace websocket { - type connection = any; - type request = any; - type IMessage = any; - type ICookie = any; - type client = any; - } -} -declare namespace samchon.templates.distributed { - /** - * Master of Distributed Processing System, a server accepting slave clients. - * - * The {@link DistributedClientArray} is an abstract class, derived from the {@link DistributedSystemArray} class, - * opening a server accepting {@link DistributedSystem distributed clients}. - * - * Extends this {@link DistributedClientArray}, overrides {@link createServerBase createServerBase()} to determine - * which protocol to follow and {@link createExternalClient createExternalClient()} creating child - * {@link DistributedSystem} object. After the extending and overridings, open this server using the - * {@link open open()} method. - * - * #### [Inherited] {@link DistributedSystemArray} - * The {@link DistributedSystemArray} is an abstract class containing and managing remote distributed **slave** system - * drivers, {@link DistributedSystem} objects. Within framework of network, {@link DistributedSystemArray} represents - * your system, a **Master** of *Distributed Processing System* that requesting *distributed process* to **slave** - * systems and the children {@link DistributedSystem} objects represent the remote **slave** systems, who is being - * requested the *distributed processes*. - * - * The {@link DistributedSystemArray} contains {@link DistributedProcess} objects directly. You can request a - * **distributed process** through the {@link DistributedProcess} object. You can access the - * {@link DistributedProcess} object(s) with those methods: - * - * - {@link hasProcess} - * - {@link getProcess} - * - {@link insertProcess} - * - {@link eraseProcess} - * - {@link getProcessMap} - * - * When you need the **distributed process**, call the {@link DistributedProcess.sendData} method. Then the - * {@link DistributedProcess} will find the most idle {@link DistributedSystem} object who represents a distributed - * **slave **system. The {@link Invoke} message will be sent to the most idle {@link DistributedSystem} object. When - * the **distributed process** has completed, then {@link DistributedSystem.getPerformance performance index} and - * {@link DistributedProcess.getResource resource index} of related objects will be revaluated. - * - * - * - * - * - * #### Parallel Process - * This {@link DistributedSystemArray} class is derived from the {@link ParallelSystemArray} class, so you can request - * a **parallel process**, too. - * - * When you need the **parallel process**, then call one of them: {@link sendSegmentData} or {@link sendPieceData}. - * When the **parallel process** has completed, {@link ParallelSystemArray} estimates each {@link ParallelSystem}'s - * {@link ParallelSystem.getPerformance performance index} basis on their execution time. Those performance indices will - * be reflected to the next **parallel process**, how much pieces to allocate to each {@link ParallelSystem}. - * - * #### Proxy Pattern - * This class {@link DistributedSystemArray} is derived from the {@link ExternalSystemArray} class. Thus, you can take - * advantage of the *Proxy Pattern* in the {@link DistributedSystemArray} class. If a process to request is not the - * *parallel process* (to be distrubted to all slaves), but the **exclusive process** handled in a system, then it - * may better to utilizing the *Proxy Pattern*: - * - * The {@link ExternalSystemArray} class can use *Proxy Pattern*. In framework within user, which - * {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not - * important. Only interested in user's perspective is *which can be done*. - * - * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged - * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. - * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. - * - *
    - *
  • - * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring - * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. - *
  • - *
  • - * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call - * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the - * external system. - *
  • - *
  • Those strategy is called *Proxy Pattern*.
  • - *
- * - * @handbook [Templates - Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) - * @author Jeongho Nam - */ - abstract class DistributedClientArray extends DistributedSystemArray implements external.IExternalClientArray { - /** - * @hidden - */ - private server_base_; - /** - * Default Constructor. - */ - constructor(); - /** - * Factory method creating {@link IServerBase} object. - * - * This method {@link createServerBase createServerBase()} determines which protocol is used in this server, - * {@link ExternalClientArray}. If the protocol is determined, then {@link ExternalSystem external clients} who - * may connect to {@link ExternalClientArray this server} must follow the specified protocol. - * - * Overrides the {@link createServerBase createServerBase()} method to create and return one of them: - * - * - {@link ServerBase} - * - {@link WebServerBase} - * - {@link SharedWorkerServerBase} - * - * @return A new {@link IServerBase} object. - */ - protected abstract createServerBase(): protocol.IServerBase; - /** - * Add a newly connected remote client. - * - * When a {@link IClientDriver remote client} connects to this *master server of parallel processing system*, - * then this {@link ParallelClientArray} creates a child {@link ParallelSystem parallel client} object through - * the {@link createExternalClient createExternalClient()} method and {@link insert inserts} it. - * - * @param driver A communicator for external client. - */ - addClient(driver: protocol.IClientDriver): void; - /** - * (Deprecated) Factory method creating child object. - * - * The method {@link createChild createChild()} is deprecated. Don't use and override this. - * - * Note that, the {@link ParallelClientArray} is a server accepting {@link ParallelSystem parallel clients}. - * There's no way to creating the {@link ParallelSystem parallel clients} in advance before opening the server. - * - * @param xml An {@link XML} object represents the child {@link ParallelSystem} object. - * @return ```null``` - */ - createChild(xml: library.XML): System; - /** - * Factory method creating {@link DistributedSystem} object. - * - * The method {@link createExternalClient createExternalClient()} is a factory method creating a child - * {@link ParallelSystem} object, that is called whenever a parallel client has connected, by - * {@link addClient addClient()}. - * - * Overrides this {@link createExternalClient} method and creates a type of {@link DistributedSystem} object with - * the *driver* that communicates with the parallel client. After the creation, returns the object. Then whenever - * a parallel client has connected, matched {@link DistributedSystem} object will be constructed and - * {@link insert inserted} into this {@link DistributedSystemArray} object. - * - * @param driver A communicator with the parallel client. - * @return A newly created {@link ParallelSystem} object. - */ - protected abstract createExternalClient(driver: protocol.IClientDriver): System; - /** - * @inheritdoc - */ - open(port: number): void; - /** - * @inheritdoc - */ - close(): void; - } -} -declare namespace samchon.templates.distributed { - /** - * Mediator of Distributed Processing System, a server accepting slave clients. - * - * The {@link DistributedClientArrayMediator} is an abstract class, derived from {@link DistributedSystemArrayMediator} - * class, opening a server accepting {@link DistributedSystem distributed clients} as a **master**. - * - * Extends this {@link DistributedClientArrayMediator}, overrides {@link createServerBase createServerBase()} to - * determine which protocol to follow and {@link createExternalClient createExternalClient()} creating child - * {@link DistributedSystem} object. After the extending and overridings, open this server using the - * {@link open open()} method. - * - * #### [Inherited] {@link DistributedSystemArrayMediator} - * The {@link DistributedSystemArrayMediator} class be a master for its slave systems, and be a slave to its master - * system at the same time. This {@link DistributedSystemArrayMediator} be a master system, containing and managing - * {@link DistributedSystem} objects, which represent distributed slave systems, by extending - * {@link DistributedSystemArray} class. Also, be a slave system through {@link getMediator mediator} object, which is - * derived from the {@link SlaveSystem} class. - * - * As a slave, you can specify this {@link DistributedSystemArrayMediator} to be a client slave connecting to master - * server or a server slave accepting master client by overriding the {@link createMediator} method. - * Overrides the {@link createMediator createMediator()} method and return one of them: - * - * - A client slave connecting to master server: - * - {@link MediatorClient} - * - {@link MediatorWebClient} - * - {@link MediatorSharedWorkerClient} - * - A server slave accepting master client: - * - {@link MediatorServer} - * - {@link MediatorWebServer} - * - {@link MediatorDedicatedWorkerServer} - * - {@link MediatorSharedWorkerServer} - * - * #### [Inherited] {@link DistributedSystemArray} - * The {@link DistributedSystemArray} is an abstract class containing and managing remote distributed **slave** system - * drivers, {@link DistributedSystem} objects. Within framework of network, {@link DistributedSystemArray} represents - * your system, a **Master** of *Distributed Processing System* that requesting *distributed process* to **slave** - * systems and the children {@link DistributedSystem} objects represent the remote **slave** systems, who is being - * requested the *distributed processes*. - * - * The {@link DistributedSystemArray} contains {@link DistributedProcess} objects directly. You can request a - * **distributed process** through the {@link DistributedProcess} object. You can access the - * {@link DistributedProcess} object(s) with those methods: - * - * - {@link hasProcess} - * - {@link getProcess} - * - {@link insertProcess} - * - {@link eraseProcess} - * - {@link getProcessMap} - * - * When you need the **distributed process**, call the {@link DistributedProcess.sendData} method. Then the - * {@link DistributedProcess} will find the most idle {@link DistributedSystem} object who represents a distributed - * **slave **system. The {@link Invoke} message will be sent to the most idle {@link DistributedSystem} object. When - * the **distributed process** has completed, then {@link DistributedSystem.getPerformance performance index} and - * {@link DistributedProcess.getResource resource index} of related objects will be revaluated. - * - * - * - * - * - * #### Parallel Process - * This {@link DistributedSystemArray} class is derived from the {@link ParallelSystemArray} class, so you can request - * a **parallel process**, too. - * - * When you need the **parallel process**, then call one of them: {@link sendSegmentData} or {@link sendPieceData}. - * When the **parallel process** has completed, {@link ParallelSystemArray} estimates each {@link ParallelSystem}'s - * {@link ParallelSystem.getPerformance performance index} basis on their execution time. Those performance indices will - * be reflected to the next **parallel process**, how much pieces to allocate to each {@link ParallelSystem}. - * - * #### Proxy Pattern - * This class {@link DistributedSystemArray} is derived from the {@link ExternalSystemArray} class. Thus, you can take - * advantage of the *Proxy Pattern* in the {@link DistributedSystemArray} class. If a process to request is not the - * *parallel process* (to be distrubted to all slaves), but the **exclusive process** handled in a system, then it - * may better to utilizing the *Proxy Pattern*: - * - * The {@link ExternalSystemArray} class can use *Proxy Pattern*. In framework within user, which - * {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not - * important. Only interested in user's perspective is *which can be done*. - * - * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged - * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. - * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. - * - *
    - *
  • - * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring - * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. - *
  • - *
  • - * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call - * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the - * external system. - *
  • - *
  • Those strategy is called *Proxy Pattern*.
  • - *
- * - * @handbook [Templates - Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) - * @author Jeongho Nam - */ - abstract class DistributedClientArrayMediator extends DistributedSystemArrayMediator implements external.IExternalClientArray { - /** - * A subrogator of {@link IServer server}'s role instead of this {@link ExternalClientArray}. - */ - private server_base_; - /** - * Default Constructor. - */ - constructor(); - /** - * Factory method creating {@link IServerBase} object. - * - * This method {@link createServerBase createServerBase()} determines which protocol is used in this - * {@link DistributedClientArrayMediator} object as a **master**. If the protocol is determined, then - * {@link DistributedSystem distributed clients} who may connect to {@link DistributedClientArrayMediator this - * server} must follow the specified protocol. - * - * Overrides the {@link createServerBase createServerBase()} method to create and return one of them: - * - * - {@link ServerBase} - * - {@link WebServerBase} - * - {@link SharedWorkerServerBase} - * - * @return A new {@link IServerBase} object. - */ - protected abstract createServerBase(): protocol.IServerBase; - /** - * Add a newly connected remote client. - * - * When a {@link IClientDriver remote client} connects to this *master server of distributed processing system*, - * then this {@link DistributedClientArrayMediator} creates a child {@link Distributed distributed client} object - * through the {@link createExternalClient createExternalClient()} method. - * - * @param driver A communicator for external client. - */ - addClient(driver: protocol.IClientDriver): void; - /** - * (Deprecated) Factory method creating child object. - * - * The method {@link createChild createChild()} is deprecated. Don't use and override this. - * - * Note that, the {@link DistributedClientArrayMediator} is a server accepting {@link DistributedSystem distributed - * clients} as a master. There's no way to creating the {@link DistributedSystem distributed clients} in advance - * before opening the server. - * - * @param xml An {@link XML} object represents the child {@link DistributedSystem} object. - * @return null - */ - createChild(xml: library.XML): System; - /** - * Factory method creating {@link DistributedSystem} object. - * - * The method {@link createExternalClient createExternalClient()} is a factory method creating a child - * {@link DistributedSystem} object, that is called whenever a distributed client has connected, by - * {@link addClient addClient()}. - * - * Overrides this {@link createExternalClient} method and creates a type of {@link DistributedSystem} object with - * the *driver* that communicates with the distributed client. After the creation, returns the object. Then whenever - * a distributed client has connected, matched {@link DistributedSystem} object will be constructed and - * {@link insert inserted} into this {@link DistributedClientArrayMediator} object. - * - * @param driver A communicator with the distributed client. - * @return A newly created {@link DistributedSystem} object. - */ - protected abstract createExternalClient(driver: protocol.IClientDriver): System; - /** - * @inheritdoc - */ - open(port: number): void; - /** - * @inheritdoc - */ - close(): void; - } -} -declare namespace samchon.templates.distributed { - /** - * A process of Distributed Processing System. - * - * The {@link DistributedProcess} is an abstract class who represents a **process**, *SOMETHING TO DISTRIBUTE* in a Distributed - * Processing System. Overrides the {@link DistributedProcess} and defines the *SOMETHING TO DISTRIBUTE*. - * - * Relationship between {@link DistributedSystem} and {@link DistributedProcess} objects are **M: N Associative**. - * Unlike {@link ExternalSystemRole}, the {@link DistributedProcess} objects are not belonged to a specific - * {@link DistributedSystem} object. The {@link DistributedProcess} objects are belonged to the - * {@link DistributedSystemArrayMediator} directly. - * - * When you need the **distributed process**, then call {@link sendData sendData()}. The {@link sendData} will find - * the most idle {@link DistributedSystem slave system} considering not only number of processes on progress, but also - * {@link DistributedSystem.getPerformance performance index} of each {@link DistributedSystem} object and - * {@link getResource resource index} of this {@link DistributedProcess} object. The {@link Invoke} message - * requesting the **distributed process** will be sent to the most idle {@link DistributedSystem slave system}. - * - * Those {@link DistributedSystem.getPerformance performance index} and {@link getResource resource index} are - * revaluated whenever the **distributed process** has completed basis on the execution time. - * - * - * - * - * - * @handbook [Templates - Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) - * @author Jeongho Nam - */ - abstract class DistributedProcess extends protocol.Entity implements protocol.IProtocol { - /** - * @hidden - */ - private system_array_; - /** - * A name, represents and identifies this {@link DistributedProcess process}. - * - * This {@link name} is an identifier represents this {@link DistributedProcess process}. This {@link name} is - * used in {@link DistributedSystemArray.getProcess} and {@link DistributedSystemArray.getProcess}, as a key elements. - * Thus, this {@link name} should be unique in its parent {@link DistributedSystemArray} object. - */ - protected name: string; - /** - * @hidden - */ - private progress_list_; - /** - * @hidden - */ - private history_list_; - /** - * @hidden - */ - private resource; - /** - * @hidden - */ - private enforced_; - /** - * Constrct from parent {@link DistributedSystemArray} object. - * - * @param systemArray The parent {@link DistributedSystemArray} object. - */ - constructor(systemArray: DistributedSystemArray); - /** - * Identifier of {@link ParallelProcess} is its {@link name}. - */ - key(): string; - /** - * Get parent {@link DistributedSystemArray} object. - * - * @return The parent {@link DistributedSystemArray} object. - */ - getSystemArray(): DistributedSystemArray; - /** - * Get parent {@link DistributedSystemArray} object. - * - * @return The parent {@link DistributedSystemArray} object. - */ - getSystemArray>(): SystemArray; - /** - * Get name, who represents and identifies this process. - */ - getName(): string; - /** - * Get resource index. - * - * Get *resource index* that indicates how much this {@link DistributedProcess process} is heavy. - * - * If this {@link DistributedProcess process} does not have any {@link Invoke} message had handled, then the - * *resource index* will be ```1.0```, which means default and average value between all - * {@link DistributedProcess} instances (that are belonged to a same {@link DistributedSystemArray} object). - * - * You can specify the *resource index* by yourself, but notice that, if the *resource index* is higher than - * other {@link DistributedProcess} objects, then this {@link DistributedProcess process} will be ordered to - * handle less processes than other {@link DistributedProcess} objects. Otherwise, the *resource index* is - * lower than others, of course, much processes will be requested. - * - * - {@link setResource setResource()} - * - {@link enforceResource enforceResource()} - * - * Unless {@link enforceResource enforceResource()} is called, This *resource index* is **revaluated** whenever - * {@link sendData sendData()} is called. - * - * @return Resource index. - */ - getResource(): number; - /** - * Set resource index. - * - * Set *resource index* that indicates how much this {@link DistributedProcess process} is heavy. This - * *resource index* can be **revaulated**. - * - * Note that, initial and average *resource index* of {@link DistributedProcess} objects are ```1.0```. If the - * *resource index* is higher than other {@link DistributedProcess} objects, then this - * {@link DistributedProcess} will be ordered to handle more processes than other {@link DistributedProcess} - * objects. Otherwise, the *resource index* is lower than others, of course, less processes will be requested. - * - * Unlike {@link enforceResource}, configuring *resource index* by this {@link setResource} allows the - * **revaluation**. This **revaluation** prevents wrong valuation from user. For example, you *mis-valuated* the - * *resource index*. The {@link DistributedProcess process} is much heavier than any other, but you estimated it - * to the lightest one. It looks like a terrible case that causes - * {@link DistributedSystemArray entire distributed processing system} to be slower, however, don't mind. The - * {@link DistributedProcess process} will the direct to the *propriate resource index* eventually with the - * **revaluation**. - * - * - The **revaluation** is caused by the {@link sendData sendData()} method. - * - * @param val New resource index, but can be revaluated. - */ - setResource(val: number): void; - /** - * Enforce resource index. - * - * Enforce *resource index* that indicates how much heavy the {@link DistributedProcess process is}. The - * *resource index* will be fixed, never be **revaluated**. - * - * Note that, initial and average *resource index* of {@link DistributedProcess} objects are ```1.0```. If the - * *resource index* is higher than other {@link DistributedProcess} objects, then this - * {@link DistributedProcess} will be ordered to handle more processes than other {@link DistributedProcess} - * objects. Otherwise, the *resource index* is lower than others, of course, less processes will be requested. - * - * The difference between {@link setResource} and this {@link enforceResource} is allowing **revaluation** or not. - * This {@link enforceResource} does not allow the **revaluation**. The *resource index* is clearly fixed and - * never be changed by the **revaluation**. But you've to keep in mind that, you can't avoid the **mis-valuation** - * with this {@link enforceResource}. - * - * For example, there's a {@link DistributedProcess process} much heavier than any other, but you - * **mis-estimated** it to the lightest. In that case, there's no way. The - * {@link DistributedSystemArray entire distributed processing system} will be slower by the **mis-valuation**. - * By the reason, using {@link enforceResource}, it's recommended only when you can clearly certain the - * *resource index*. If you can't certain the *resource index* but want to recommend, then use {@link setResource} - * instead. - * - * @param val New resource index to be fixed. - */ - enforceResource(val: number): void; - /** - * @hidden - */ - private compute_average_elapsed_time(); - /** - * @inheritdoc - */ - abstract replyData(invoke: protocol.Invoke): void; - /** - * Send an {@link Invoke} message. - * - * Sends an {@link Invoke} message requesting a **distributed process**. The {@link Invoke} message will be sent - * to the most idle {@link DistributedSystem} object, which represents a slave system, and the most idle - * {@link DistributedSystem} object will be returned. - * - * When the **distributed process** has completed, then the {@link DistributedSystemArray} object will revaluate - * {@link getResource resource index} and {@link DistributedSystem.getPerformance performance index} of this - * {@link DistributedSystem} and the most idle {@link DistributedSystem} objects basis on the execution time. - * - * @param invoke An {@link Invoke} message requesting distributed process. - * @return The most idle {@link DistributedSystem} object who may send the {@link Invoke} message. - */ - sendData(invoke: protocol.Invoke): DistributedSystem; - /** - * Send an {@link Invoke} message. - * - * Sends an {@link Invoke} message requesting a **distributed process**. The {@link Invoke} message will be sent - * to the most idle {@link DistributedSystem} object, which represents a slave system, and the most idle - * {@link DistributedSystem} object will be returned. - * - * When the **distributed process** has completed, then the {@link DistributedSystemArray} object will revaluate - * {@link getResource resource index} and {@link DistributedSystem.getPerformance performance index} of this - * {@link DistributedSystem} and the most idle {@link DistributedSystem} objects basis on the execution time. - * - * @param invoke An {@link Invoke} message requesting distributed process. - * @param weight Weight of resource which indicates how heavy this {@link Invoke} message is. Default is 1. - * - * @return The most idle {@link DistributedSystem} object who may send the {@link Invoke} message. - */ - sendData(invoke: protocol.Invoke, weight: number): DistributedSystem; - /** - * @hidden - */ - private complete_history(history); - /** - * @inheritdoc - */ - TAG(): string; - } -} -declare namespace samchon.templates.external { - /** - * An external system driver. - * - * The {@link ExternalSystem} class represents an external system, connected and interact with this system. - * {@link ExternalSystem} takes full charge of network communication with the remote, external system have connected. - * Replied {@link Invoke} messages from the external system is shifted to and processed in, children elements of this - * class, {@link ExternalSystemRole} objects. - * - * - * - * - * - * #### Bridge & Proxy Pattern - * The {@link ExternalSystem} class can be a *bridge* for *logical proxy*. In framework within user, - * which {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not - * important. Only interested in user's perspective is *which can be done*. - * - * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged - * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. - * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. - * - *
    - *
  • - * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring - * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. - *
  • - *
  • - * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call - * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the - * external system. - *
  • - *
  • Those strategy is called *Bridge Pattern* and *Proxy Pattern*.
  • - *
- * - * @handbook [Templates - External System](https://github.com/samchon/framework/wiki/TypeScript-Templates-External_System) - * @author Jeongho Nam - */ - abstract class ExternalSystem extends protocol.EntityDequeCollection implements protocol.IProtocol { - /** - * The name represents external system have connected. - */ - protected name: string; - /** - * @hidden - */ - private system_array_; - /** - * @hidden - */ - private communicator_; - /** - * Construct from parent {@link ExternalSystemArray}. - * - * @param systemArray The parent {@link ExternalSystemArray} object. - */ - constructor(systemArray: ExternalSystemArray); - /** - * Constrct from parent {@link ExternalSystemArray} and communicator. - * - * @param systemArray The parent {@link ExternalSystemArray} object. - * @param communicator Communicator with the remote, external system. - */ - constructor(systemArray: ExternalSystemArray, communicator: protocol.IClientDriver); - /** - * Default Destructor. - * - * This {@link destructor destructor()} method is called when the {@link ExternalSystem} object is destructed and - * the {@link ExternalSystem} object is destructed when connection with the remote system is closed or this - * {@link ExternalSystem} object is {@link ExternalSystemArray.erase erased} from its parent - * {@link ExternalSystemArray} object. - * - * Note that, don't call this {@link destructor destructor()} method by yourself. It must be called automatically - * by those *destruction* cases. Also, if your derived {@link ExternalSystem} class has something to do on the - * *destruction*, then overrides this {@link destructor destructor()} method and defines the something to do. - * Overriding this {@link destructor destructor()}, don't forget to calling ```super.destructor();``` on tail. - * - * ```typescript - * class SomeSystem extends templates.external.ExternalSystem - * { - * protected destructor(): void - * { - * // DO SOMETHING - * this.do_something(); - * - * // CALL SUPER.DESTRUCTOR() ON TAIL. DON'T FORGET THIS - * super.destructor(); - * } - * } - * ``` - */ - protected destructor(): void; - /** - * @hidden - */ - private handle_close(); - /** - * Get parent {@link ExternalSystemArray} object. - */ - getSystemArray(): ExternalSystemArray; - /** - * Get parent {@link ExternalSystemArray} object. - */ - getSystemArray>(): SystemArray; - /** - * Identifier of {@link ExternalSystem} is its {@link name}. - * - * @return name. - */ - key(): string; - /** - * Get {@link name}. - */ - getName(): string; - /** - * @hidden - */ - /** - * @hidden - */ - protected communicator: protocol.ICommunicator; - /** - * Close connection. - */ - close(): void; - /** - * Send {@link Invoke} message to external system. - * - * @param invoke An {@link Invoke} message to send. - */ - sendData(invoke: protocol.Invoke): void; - /** - * Handle an {@Invoke} message has received. - * - * @param invoke An {@link Invoke} message have received. - */ - replyData(invoke: protocol.Invoke): void; - /** - * Tag name of the {@link ExternalSystem} in {@link XML}. - * - * @return *system*. - */ - TAG(): string; - /** - * Tag name of {@link ExternalSystemRole children elements} belonged to the {@link ExternalSystem} in {@link XML}. - * - * @return *role*. - */ - CHILD_TAG(): string; - } -} -declare namespace samchon.templates.parallel { - /** - * A driver for a parallel slave system. - * - * The {@link ParallelSystem} is an abstract class represents a **slave** system in *Parallel Processing System*, - * connected with this **master** system. This {@link ParallelSystem} takes full charge of network communication with - * the remote, parallel **slave** system has connected. - * - * When a *parallel process* is requested (by {@link ParallelSystemArray.sendSegmentData} or - * {@link ParallelSystemArray.sendPieceData}), the number of pieces to be allocated to a {@link ParallelSystem} is - * turn on its {@link getPerformance performance index}. Higher {@link getPerformance performance index}, then - * more pieces are requested. The {@link getPerformance performance index} is revaluated whenever a *parallel process* - * has completed, basic on the execution time and number of pieces. You can sugguest or enforce the - * {@link getPerformance performance index} with {@link setPerformance} or {@link enforcePerformance}. - * - * - * - * - * - * #### Bridge & Proxy Pattern - * This class {@link ParallelSystem} is derived from the {@link ExternalSystem} class. Thus, you can take advantage - * of the *Bridge & Proxy Pattern* in this {@link ParallelSystem} class. If a process to request is not the - * *parallel process* (to be distrubted to all slaves), but the **exclusive process** handled in a system, then it - * may better to utilizing the *Bridge & Proxy Pattern*: - * - * The {@link ExternalSystem} class can be a *bridge* for *logical proxy*. In framework within user, - * which {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not - * important. Only interested in user's perspective is *which can be done*. - * - * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged - * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. - * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. - * - *
    - *
  • - * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring - * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. - *
  • - *
  • - * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call - * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the - * external system. - *
  • - *
  • Those strategy is called *Bridge Pattern* and *Proxy Pattern*.
  • - *
- * - * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System) - * @author Jeongho Nam - */ - abstract class ParallelSystem extends external.ExternalSystem { - /** - * @hidden - */ - private progress_list_; - /** - * @hidden - */ - private history_list_; - /** - * @hidden - */ - private exclude_; - /** - * @hidden - */ - private performance; - /** - * @hidden - */ - private enforced_; - /** - * Construct from parent {@link ParallelSystemArray}. - * - * @param systemArray The parent {@link ParallelSystemArray} object. - */ - constructor(systemArray: ParallelSystemArray); - /** - * Construct from parent {@link ParallelSystemArray} and communicator. - * - * @param systemArray The parent {@link ParallelSystemArray} object. - * @param communicator A communicator communicates with remote, the external system. - */ - constructor(systemArray: ParallelSystemArray, communicator: protocol.IClientDriver); - /** - * Default Destructor. - * - * This {@link destructor destructor()} method is called when the {@link ParallelSystem} object is destructed and - * the {@link ParallelSystem} object is destructed when connection with the remote system is closed or this - * {@link ParallelSystem} object is {@link ParallelSystemArray.erase erased} from its parent - * {@link ParallelSystemArray} object. - * - * You may think if there're some *parallel processes* have requested but not completed yet, then it would be a - * critical problem because the *parallel processes* will not complete forever. Do not worry. The critical problem - * does not happen. After the destruction, the remained *parallel processes* will be shifted to and proceeded in - * other {@link ParallelSystem} objects. - * - * Note that, don't call this {@link destructor destructor()} method by yourself. It must be called automatically - * by those *destruction* cases. Also, if your derived {@link ParallelSystem} class has something to do on the - * *destruction*, then overrides this {@link destructor destructor()} method and defines the something to do. - * Overriding this {@link destructor destructor()}, don't forget to calling ```super.destructor();``` on tail. - * - * ```typescript - * class SomeSystem extends protocol.external.ExternalSystem - * { - * protected destructor(): void - * { - * // DO SOMETHING - * this.do_something(); - * - * // CALL SUPER.DESTRUCTOR() ON TAIL. DON'T FORGET THIS - * super.destructor(); - * } - * } - * ``` - */ - protected destructor(): void; - /** - * Get manager of this object. - * - * @return The parent {@link ParallelSystemArray} object. - */ - getSystemArray(): ParallelSystemArray; - /** - * Get manager of this object. - * - * @return The parent {@link ParallelSystemArray} object. - */ - getSystemArray>(): SystemArray; - /** - * Get performance index. - * - * Get *performance index* that indicates how much fast the remote system is. - * - * If this {@link ParallelSystem parallel system} does not have any {@link Invoke} message had handled, then the - * *performance index* will be ```1.0```, which means default and average value between all {@link ParallelSystem} - * instances (that are belonged to a same {@link ParallelSystemArray} object). - * - * You can specify this *performance index* by yourself but notice that, if the *performance index* is higher - * than other {@link ParallelSystem} objects, then this {@link ParallelSystem parallel system} will be ordered to - * handle more processes than other {@link ParallelSystem} objects. Otherwise, the *performance index* is lower - * than others, of course, less processes will be delivered. - * - * - {@link setPerformance setPerformance()} - * - {@link enforcePerformance enforcePerformance()} - * - * Unless {@link enforcePerformance enforcePerformance()} is called, This *performance index* is **revaluated** - * whenever user calls one of them below. - * - * - {@link ParallelSystemArray.sendSegmentData ParallelSystemArray.sendSegmentData()} - * - {@link ParallelSystemArray.sendPieceData ParallelSystemArray.sendPieceData()} - * - {@link DistributedProcess.sendData DistributedProcess.sendData()}. - * - * @return Performance index. - */ - getPerformance(): number; - /** - * Set performance index. - * - * Set *performance index* that indicates how much fast the remote system is. This *performance index* can be - * **revaulated**. - * - * Note that, initial and average *performance index* of {@link ParallelSystem} objects are ```1.0```. If the - * *performance index* is higher than other {@link ParallelSystem} objects, then this {@link ParallelSystem} will - * be ordered to handle more processes than other {@link ParallelSystem} objects. Otherwise, the - * *performance index* is lower than others, of course, less processes will be delivered. - * - * Unlike {@link enforcePerformance}, configuring *performance index* by this {@link setPerformance} allows - * **revaluation**. This **revaluation** prevents wrong valuation from user. For example, you *mis-valuated* the - * *performance index*. The remote system is much faster than any other, but you estimated it to the slowest one. - * It looks like a terrible case that causes {@link ParallelSystemArray entire parallel systems} to be slower, - * however, don't mind. The system will direct to the *propriate performance index* eventually with the - * **revaluation** by following methods. - * - * - {@link ParallelSystemArray.sendSegmentData ParallelSystemArray.sendSegmentData()} - * - {@link ParallelSystemArray.sendPieceData ParallelSystemArray.sendPieceData()} - * - {@link DistributedProcess.sendData DistributedProcess.sendData()}. - * - * @param val New performance index, but can be revaluated. - */ - setPerformance(val: number): void; - /** - * Enforce performance index. - * - * Enforce *performance index* that indicates how much fast the remote system is. The *performance index* will be - * fixed, never be **revaluated**. - * - * Note that, initial and average *performance index* of {@link ParallelSystem} objects are ```1.0```. If the - * *performance index* is higher than other {@link ParallelSystem} objects, then this {@link ParallelSystem} will - * be ordered to handle more processes than other {@link ParallelSystem} objects. Otherwise, the - * *performance index* is lower than others, of course, less processes will be delivered. - * - * The difference between {@link setPerformance} and this {@link enforcePerformance} is allowing **revaluation** - * or not. This {@link enforcePerformance} does not allow the **revaluation**. The *performance index* is clearly - * fixed and never be changed by the **revaluation**. But you've to keep in mind that, you can't avoid the - * **mis-valuation** with this {@link enforcePerformance}. - * - * For example, there's a remote system much faster than any other, but you **mis-estimated** it to the slowest. - * In that case, there's no way. The {@link ParallelSystemArray entire parallel systems} will be slower by the - * **mis-valuation**. By the reason, using {@link enforcePerformance}, it's recommended only when you can clearly - * certain the *performance index*. If you can't certain the *performance index* but want to recommend, then use - * {@link setPerformance} instead. - * - * @param val New performance index to be fixed. - */ - enforcePerformance(val: number): void; - /** - * @hidden - */ - private send_piece_data(invoke, first, last); - /** - * @hidden - */ - private _replyData(invoke); - /** - * @hidden - */ - protected _Report_history(xml: library.XML): void; - /** - * @hidden - */ - protected _Send_back_history(invoke: protocol.Invoke, history: protocol.InvokeHistory): void; - } -} -declare namespace samchon.templates.distributed { - /** - * A driver for a distributed slave system. - * - * The {@link DistributedSystem} is an abstract class represents a **slave** system in *Distributed Processing System*, - * connected with this **master** system. This {@link DistributedSystem} takes full charge of network communication - * with the remote, distributed **slave** system has connected. - * - * This {@link DistributedSystem} has a {@link getPerformance performance index} that indicates how much the **slave** - * system is fast. The {@link getPerformance performance index} is referenced and revaluated whenever those methods - * are called: - * - * - Requesting a *parallel process* - * - {@link DistributedSystemArray.sendSegmentData} - * - {@link DistributedSystemArray.sendPieceData} - * - Requesting a *distributed process*: {@link DistributedProcess.sendData} - * - * Note that, this {@link DistributedSystem} class derived from the {@link ExternalSystem} class. Thus, this - * {@link DistributedSystem} can also have children {@link ExternalSystemRole} objects exclusively. However, the - * children {@link ExternalSystemRole roles} objects are different with the {@link DistributedProcess}. The - * domestic {@link ExternalSystemRole roles} are belonged to only a specific {@link DistributedSystem} object. - * Otherwise, the {@link DistributedProcess} objects are belonged to a {@link DistributedSystemArray} object. - * Furthermore, the relationship between this {@link DistributedSystem} and {@link DistributedProcess} classes are - * **M: N Associative**. - * - * Articles | {@link DistributedProcess} | {@link ExternalSystemRole} - * -------------|--------------------------------|---------------------------- - * Belonged to | {@link DistributedSystemArray} | {@link DistributedSystem} - * Relationship | M: N Associative | 1: N Composite - * Ownership | References | Exclusive possession - * - * - * - * - * - * @handbook [Templates - Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) - * @author Jeongho Nam - */ - abstract class DistributedSystem extends parallel.ParallelSystem { - /** - * Construct from parent {@link DistributedSystemArray}. - * - * @param systemArray The parent {@link DistributedSystemArray} object. - */ - constructor(systemArray: DistributedSystemArray); - /** - * Constrct from parent {@link DistributedSystemArray} and communicator. - * - * @param systemArray The parent {@link DistributedSystemArray} object. - * @param communicator A communicator communicates with remote, the external system. - */ - constructor(systemArray: DistributedSystemArray, communicator: protocol.IClientDriver); - /** - * Factory method creating a {@link ExternalSystemRole child} object. - * - * In {@link distributed} module, the process class {@link DistributedProcess} is not belonged to a specific - * {@link DistributedSystem} object. It only belongs to a {@link DistributedSystemArray} object and has a - * **M: N Associative Relationship** between this {@link DistributedSystem} class. - * - * By that reason, it's the normal case that the {@link DistributedSystem} object does not have any children - * {@link ExternalSystemRole} object. Thus, default {@link createChild} returns ```null```. - * - * However, if you want a {@link DistributedSystem} to have its own domestic {@link ExternalSystemRole} objects - * without reference to the {@link DistributedProcess} objects, it is possible. Creates and returns the - * domestic {@link ExternalSystemRole} object. - * - * @param xml {@link XML} represents the {@link ExternalSystemRole child} object. - * @return A newly created {@link ExternalSystemRole} object or ```null```. - */ - createChild(xml: library.XML): external.ExternalSystemRole; - /** - * Get manager of this object. - * - * @return The parent {@link DistributedSystemArray} object. - */ - getSystemArray(): DistributedSystemArray; - /** - * Get manager of this object. - * - * @return The parent {@link DistributedSystemArray} object. - */ - getSystemArray>(): SystemArray; - /** - * @hidden - */ - private compute_average_elapsed_time(); - /** - * @inheritdoc - */ - replyData(invoke: protocol.Invoke): void; - /** - * @hidden - */ - protected _Report_history(xml: library.XML): void; - /** - * @hidden - */ - protected _Send_back_history(invoke: protocol.Invoke, history: protocol.InvokeHistory): void; - } -} -declare namespace samchon.templates.distributed { - /** - * An interface for a distributed slave server driver. - * - * The easiest way to defining a driver for distributed **slave** server is extending {@link DistributedServer} class. - * However, if you've to interact with a prallel **slave** system who can be both server and client, them make a class - * (let's name it **BaseSystem**) extending the {@link DistributedServer} class. At next, make a new class (now, I name - * it **BaseServer**) extending the **BaseSystem** and implements this interface {@link IParallelServer}. Define the - * **BaseServer** following those codes on below: - * - * - * - * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System) - * @author Jeongho Nam - */ - interface IDistributedServer extends DistributedSystem { - /** - * Connect to external server. - */ - connect(): void; - } - /** - * A driver for distributed slave server. - * - * The {@link DistributedServer} is an abstract class, derived from the {@link DistributedSystem} class, connecting to - * remote, distributed **slave** server. Extends this {@link DistributedServer} class and overrides the - * {@link createServerConnector createServerConnector()} method following which protocol the **slave** server uses. - * - * #### [Inheritdoc] {@link DistributedSystem} - * The {@link DistributedSystem} is an abstract class represents a **slave** system in *Distributed Processing System*, - * connected with this **master** system. This {@link DistributedSystem} takes full charge of network communication - * with the remote, distributed **slave** system has connected. - * - * This {@link DistributedSystem} has a {@link getPerformance performance index} that indicates how much the **slave** - * system is fast. The {@link getPerformance performance index} is referenced and revaluated whenever those methods - * are called: - * - * - Requesting a *parallel process* - * - {@link DistributedSystemArray.sendSegmentData} - * - {@link DistributedSystemArray.sendPieceData} - * - Requesting a *distributed process*: {@link DistributedProcess.sendData} - * - * Note that, this {@link DistributedSystem} class derived from the {@link ExternalSystem} class. Thus, this - * {@link DistributedSystem} can also have children {@link ExternalSystemRole} objects exclusively. However, the - * children {@link ExternalSystemRole roles} objects are different with the {@link DistributedProcess}. The - * domestic {@link ExternalSystemRole roles} are belonged to only a specific {@link DistributedSystem} object. - * Otherwise, the {@link DistributedProcess} objects are belonged to a {@link DistributedSystemArray} object. - * Furthermore, the relationship between this {@link DistributedSystem} and {@link DistributedProcess} classes are - * **M: N Associative**. - * - * Articles | {@link DistributedProcess} | {@link ExternalSystemRole} - * -------------|--------------------------------|---------------------------- - * Belonged to | {@link DistributedSystemArray} | {@link DistributedSystem} - * Relationship | M: N Associative | 1: N Composite - * Ownership | References | Exclusive possession - * - * - * - * - * - * @handbook [Templates - Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) - * @author Jeongho Nam - */ - abstract class DistributedServer extends DistributedSystem implements external.IExternalServer { - /** - * IP address of target external system to connect. - */ - protected ip: string; - /** - * Port number of target external system to connect. - */ - protected port: number; - /** - * Construct from parent {@link DistributedSystemArray}. - * - * @param systemArray The parent {@link DistributedSystemArray} object. - */ - constructor(systemArray: DistributedSystemArray); - /** - * Factory method creating {@link IServerConnector} object. - * - * The {@link createServerConnector createServerConnector()} is an abstract method creating - * {@link IServerConnector} object. Overrides and returns one of them, considering which protocol the slave server - * follows: - * - * - {@link ServerConnector} - * - {@link WebServerConnector} - * - {@link DedicatedWorkerServerConnector} - * - {@link SharedWorkerServerConnector} - * - * @return A newly created {@link IServerConnector} object. - */ - protected abstract createServerConnector(): protocol.IServerConnector; - /** - * @inheritdoc - */ - connect(): void; - } -} -declare namespace samchon.templates.distributed { - /** - * Master of Distributed Processing System, a client connecting to slave servers. - * - * The {@link DistributedServerArray} is an abstract class, derived from the {@link DistributedSystemArray} class, - * connecting to {@link IDistributedServer distributed servers}. - * - * Extends this {@link DistributedServerArray} and overrides {@link createChild createChild()} method creating child - * {@link IDistributedServer} object. After the extending and overriding, construct children {@link IDistributedServer} - * objects and call the {@link connect connect()} method. - * - * #### [Inherited] {@link DistributedSystemArray} - * The {@link DistributedSystemArray} is an abstract class containing and managing remote distributed **slave** system - * drivers, {@link DistributedSystem} objects. Within framework of network, {@link DistributedSystemArray} represents - * your system, a **Master** of *Distributed Processing System* that requesting *distributed process* to **slave** - * systems and the children {@link DistributedSystem} objects represent the remote **slave** systems, who is being - * requested the *distributed processes*. - * - * The {@link DistributedSystemArray} contains {@link DistributedProcess} objects directly. You can request a - * **distributed process** through the {@link DistributedProcess} object. You can access the - * {@link DistributedProcess} object(s) with those methods: - * - * - {@link hasProcess} - * - {@link getProcess} - * - {@link insertProcess} - * - {@link eraseProcess} - * - {@link getProcessMap} - * - * When you need the **distributed process**, call the {@link DistributedProcess.sendData} method. Then the - * {@link DistributedProcess} will find the most idle {@link DistributedSystem} object who represents a distributed - * **slave **system. The {@link Invoke} message will be sent to the most idle {@link DistributedSystem} object. When - * the **distributed process** has completed, then {@link DistributedSystem.getPerformance performance index} and - * {@link DistributedProcess.getResource resource index} of related objects will be revaluated. - * - * - * - * - * - * #### Parallel Process - * This {@link DistributedSystemArray} class is derived from the {@link ParallelSystemArray} class, so you can request - * a **parallel process**, too. - * - * When you need the **parallel process**, then call one of them: {@link sendSegmentData} or {@link sendPieceData}. - * When the **parallel process** has completed, {@link ParallelSystemArray} estimates each {@link ParallelSystem}'s - * {@link ParallelSystem.getPerformance performance index} basis on their execution time. Those performance indices will - * be reflected to the next **parallel process**, how much pieces to allocate to each {@link ParallelSystem}. - * - * #### Proxy Pattern - * This class {@link DistributedSystemArray} is derived from the {@link ExternalSystemArray} class. Thus, you can take - * advantage of the *Proxy Pattern* in the {@link DistributedSystemArray} class. If a process to request is not the - * *parallel process* (to be distrubted to all slaves), but the **exclusive process** handled in a system, then it - * may better to utilizing the *Proxy Pattern*: - * - * The {@link ExternalSystemArray} class can use *Proxy Pattern*. In framework within user, which - * {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not - * important. Only interested in user's perspective is *which can be done*. - * - * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged - * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. - * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. - * - *
    - *
  • - * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring - * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. - *
  • - *
  • - * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call - * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the - * external system. - *
  • - *
  • Those strategy is called *Proxy Pattern*.
  • - *
- * - * @handbook [Templates - Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) - * @author Jeongho Nam - */ - abstract class DistributedServerArray extends DistributedSystemArray implements external.IExternalServerArray { - /** - * Default Constructor. - */ - constructor(); - /** - * @inheritdoc - */ - connect(): void; - } -} -declare namespace samchon.templates.distributed { - /** - * Mediator of Distributed Processing System, a client connecting to slave servers. - * - * The {@link DistributedServerArrayMediator} is an abstract class, derived from {@link DistributedSystemArrayMediator} - * class, connecting to {@link IDistributedServer distributed servers}. - * - * Extends this {@link DistributedServerArrayMediator} and overrides {@link createChild createChild()} method creating - * child {@link IDistributedServer} object. After the extending and overriding, construct children - * {@link IDistributedServer} objects and call the {@link connect connect()} method. - * - * #### [Inherited] {@link DistributedSystemArrayMediator} - * The {@link DistributedSystemArrayMediator} class be a master for its slave systems, and be a slave to its master - * system at the same time. This {@link DistributedSystemArrayMediator} be a master system, containing and managing - * {@link DistributedSystem} objects, which represent distributed slave systems, by extending - * {@link DistributedSystemArray} class. Also, be a slave system through {@link getMediator mediator} object, which is - * derived from the {@link SlaveSystem} class. - * - * As a slave, you can specify this {@link DistributedSystemArrayMediator} to be a client slave connecting to master - * server or a server slave accepting master client by overriding the {@link createMediator} method. - * Overrides the {@link createMediator createMediator()} method and return one of them: - * - * - A client slave connecting to master server: - * - {@link MediatorClient} - * - {@link MediatorWebClient} - * - {@link MediatorSharedWorkerClient} - * - A server slave accepting master client: - * - {@link MediatorServer} - * - {@link MediatorWebServer} - * - {@link MediatorDedicatedWorkerServer} - * - {@link MediatorSharedWorkerServer} - * - * #### [Inherited] {@link DistributedSystemArray} - * The {@link DistributedSystemArray} is an abstract class containing and managing remote distributed **slave** system - * drivers, {@link DistributedSystem} objects. Within framework of network, {@link DistributedSystemArray} represents - * your system, a **Master** of *Distributed Processing System* that requesting *distributed process* to **slave** - * systems and the children {@link DistributedSystem} objects represent the remote **slave** systems, who is being - * requested the *distributed processes*. - * - * The {@link DistributedSystemArray} contains {@link DistributedProcess} objects directly. You can request a - * **distributed process** through the {@link DistributedProcess} object. You can access the - * {@link DistributedProcess} object(s) with those methods: - * - * - {@link hasProcess} - * - {@link getProcess} - * - {@link insertProcess} - * - {@link eraseProcess} - * - {@link getProcessMap} - * - * When you need the **distributed process**, call the {@link DistributedProcess.sendData} method. Then the - * {@link DistributedProcess} will find the most idle {@link DistributedSystem} object who represents a distributed - * **slave **system. The {@link Invoke} message will be sent to the most idle {@link DistributedSystem} object. When - * the **distributed process** has completed, then {@link DistributedSystem.getPerformance performance index} and - * {@link DistributedProcess.getResource resource index} of related objects will be revaluated. - * - * - * - * - * - * #### Parallel Process - * This {@link DistributedSystemArray} class is derived from the {@link ParallelSystemArray} class, so you can request - * a **parallel process**, too. - * - * When you need the **parallel process**, then call one of them: {@link sendSegmentData} or {@link sendPieceData}. - * When the **parallel process** has completed, {@link ParallelSystemArray} estimates each {@link ParallelSystem}'s - * {@link ParallelSystem.getPerformance performance index} basis on their execution time. Those performance indices will - * be reflected to the next **parallel process**, how much pieces to allocate to each {@link ParallelSystem}. - * - * #### Proxy Pattern - * This class {@link DistributedSystemArray} is derived from the {@link ExternalSystemArray} class. Thus, you can take - * advantage of the *Proxy Pattern* in the {@link DistributedSystemArray} class. If a process to request is not the - * *parallel process* (to be distrubted to all slaves), but the **exclusive process** handled in a system, then it - * may better to utilizing the *Proxy Pattern*: - * - * The {@link ExternalSystemArray} class can use *Proxy Pattern*. In framework within user, which - * {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not - * important. Only interested in user's perspective is *which can be done*. - * - * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged - * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. - * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. - * - *
    - *
  • - * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring - * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. - *
  • - *
  • - * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call - * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the - * external system. - *
  • - *
  • Those strategy is called *Proxy Pattern*.
  • - *
- * - * @handbook [Templates - Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) - * @author Jeongho Nam - */ - abstract class DistributedServerArrayMediator extends DistributedSystemArrayMediator implements external.IExternalServerArray { - /** - * Default Constructor. - */ - constructor(); - /** - * @inheritdoc - */ - connect(): void; - } -} -declare namespace samchon.templates.distributed { - /** - * Master of Distributed Processing System, be a server and client at the same time. - * - * The {@link DistributedServerClientArray} is an abstract class, derived from the {@link DistributedSystemArray} - * class, opening a server accepting {@link Distributed distributed clients} and being a client connecting to - * {@link IDistributedServer distributed servers} at the same time. - * - * Extends this {@link DistributedServerClientArray} and overrides below methods. After the overridings, open server - * with {@link open open()} method and connect to {@link IDistributedServer distributed servers} through the - * {@link connect connect()} method. - * - * - {@link createServerBase createServerBase()} - * - {@link createExternalClient createExternalClient()} - * - {@link createExternalServer createExternalServer()} - * - * #### [Inherited] {@link DistributedSystemArray} - * The {@link DistributedSystemArray} is an abstract class containing and managing remote distributed **slave** system - * drivers, {@link DistributedSystem} objects. Within framework of network, {@link DistributedSystemArray} represents - * your system, a **Master** of *Distributed Processing System* that requesting *distributed process* to **slave** - * systems and the children {@link DistributedSystem} objects represent the remote **slave** systems, who is being - * requested the *distributed processes*. - * - * The {@link DistributedSystemArray} contains {@link DistributedProcess} objects directly. You can request a - * **distributed process** through the {@link DistributedProcess} object. You can access the - * {@link DistributedProcess} object(s) with those methods: - * - * - {@link hasProcess} - * - {@link getProcess} - * - {@link insertProcess} - * - {@link eraseProcess} - * - {@link getProcessMap} - * - * When you need the **distributed process**, call the {@link DistributedProcess.sendData} method. Then the - * {@link DistributedProcess} will find the most idle {@link DistributedSystem} object who represents a distributed - * **slave **system. The {@link Invoke} message will be sent to the most idle {@link DistributedSystem} object. When - * the **distributed process** has completed, then {@link DistributedSystem.getPerformance performance index} and - * {@link DistributedProcess.getResource resource index} of related objects will be revaluated. - * - * - * - * - * - * #### Parallel Process - * This {@link DistributedSystemArray} class is derived from the {@link ParallelSystemArray} class, so you can request - * a **parallel process**, too. - * - * When you need the **parallel process**, then call one of them: {@link sendSegmentData} or {@link sendPieceData}. - * When the **parallel process** has completed, {@link ParallelSystemArray} estimates each {@link ParallelSystem}'s - * {@link ParallelSystem.getPerformance performance index} basis on their execution time. Those performance indices will - * be reflected to the next **parallel process**, how much pieces to allocate to each {@link ParallelSystem}. - * - * #### Proxy Pattern - * This class {@link DistributedSystemArray} is derived from the {@link ExternalSystemArray} class. Thus, you can take - * advantage of the *Proxy Pattern* in the {@link DistributedSystemArray} class. If a process to request is not the - * *parallel process* (to be distrubted to all slaves), but the **exclusive process** handled in a system, then it - * may better to utilizing the *Proxy Pattern*: - * - * The {@link ExternalSystemArray} class can use *Proxy Pattern*. In framework within user, which - * {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not - * important. Only interested in user's perspective is *which can be done*. - * - * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged - * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. - * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. - * - *
    - *
  • - * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring - * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. - *
  • - *
  • - * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call - * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the - * external system. - *
  • - *
  • Those strategy is called *Proxy Pattern*.
  • - *
- * - * @handbook [Templates - Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) - * @author Jeongho Nam - */ - abstract class DistributedServerClientArray extends DistributedClientArray implements external.IExternalServerClientArray { - /** - * Default Constructor. - */ - constructor(); - /** - * Factory method of a child Entity. - * - * This method is migrated to {@link createExternalServer}. Override the {@link createExternalServer} method. - * - * @param xml An {@link XML} object represents child element, so that can identify the type of child to create. - * @return A new child Entity via {@link createExternalServer createExternalServer()}. - */ - createChild(xml: library.XML): System; - /** - * Factory method creating an {@link IDistributedServer} object. - * - * @param xml An {@link XML} object represents child element, so that can identify the type of child to create. - * @return A newly created {@link IDistributedServer} object. - */ - protected abstract createExternalServer(xml: library.XML): System; - /** - * @inheritdoc - */ - connect(): void; - } -} -declare namespace samchon.templates.distributed { - /** - * Mediator of Distributed Processing System, be a server and client at the same time as a **master**. - * - * The {@link DistributedServerClientArrayMediator} is an abstract class, derived from the - * {@link DistributedSystemArrayMediator} class, opening a server accepting {@link DistributedSystem distributed - * clients} and being a client connecting to {@link IDistributedServer distributed servers} at the same time. - * - * Extends this {@link DistributedServerClientArrayMediator} and overrides below methods. After the overridings, open - * server with {@link open open()} method and connect to {@link IDistributedServer distributed servers} through the - * {@link connect connect()} method. - * - * - {@link createServerBase createServerBase()} - * - {@link createExternalClient createExternalClient()} - * - {@link createExternalServer createExternalServer()} - * - * #### [Inherited] {@link DistributedSystemArrayMediator} - * The {@link DistributedSystemArrayMediator} class be a master for its slave systems, and be a slave to its master - * system at the same time. This {@link DistributedSystemArrayMediator} be a master system, containing and managing - * {@link DistributedSystem} objects, which represent distributed slave systems, by extending - * {@link DistributedSystemArray} class. Also, be a slave system through {@link getMediator mediator} object, which is - * derived from the {@link SlaveSystem} class. - * - * As a slave, you can specify this {@link DistributedSystemArrayMediator} to be a client slave connecting to master - * server or a server slave accepting master client by overriding the {@link createMediator} method. - * Overrides the {@link createMediator createMediator()} method and return one of them: - * - * - A client slave connecting to master server: - * - {@link MediatorClient} - * - {@link MediatorWebClient} - * - {@link MediatorSharedWorkerClient} - * - A server slave accepting master client: - * - {@link MediatorServer} - * - {@link MediatorWebServer} - * - {@link MediatorDedicatedWorkerServer} - * - {@link MediatorSharedWorkerServer} - * - * #### [Inherited] {@link DistributedSystemArray} - * The {@link DistributedSystemArray} is an abstract class containing and managing remote distributed **slave** system - * drivers, {@link DistributedSystem} objects. Within framework of network, {@link DistributedSystemArray} represents - * your system, a **Master** of *Distributed Processing System* that requesting *distributed process* to **slave** - * systems and the children {@link DistributedSystem} objects represent the remote **slave** systems, who is being - * requested the *distributed processes*. - * - * The {@link DistributedSystemArray} contains {@link DistributedProcess} objects directly. You can request a - * **distributed process** through the {@link DistributedProcess} object. You can access the - * {@link DistributedProcess} object(s) with those methods: - * - * - {@link hasProcess} - * - {@link getProcess} - * - {@link insertProcess} - * - {@link eraseProcess} - * - {@link getProcessMap} - * - * When you need the **distributed process**, call the {@link DistributedProcess.sendData} method. Then the - * {@link DistributedProcess} will find the most idle {@link DistributedSystem} object who represents a distributed - * **slave **system. The {@link Invoke} message will be sent to the most idle {@link DistributedSystem} object. When - * the **distributed process** has completed, then {@link DistributedSystem.getPerformance performance index} and - * {@link DistributedProcess.getResource resource index} of related objects will be revaluated. - * - * - * - * - * - * #### Parallel Process - * This {@link DistributedSystemArray} class is derived from the {@link ParallelSystemArray} class, so you can request - * a **parallel process**, too. - * - * When you need the **parallel process**, then call one of them: {@link sendSegmentData} or {@link sendPieceData}. - * When the **parallel process** has completed, {@link ParallelSystemArray} estimates each {@link ParallelSystem}'s - * {@link ParallelSystem.getPerformance performance index} basis on their execution time. Those performance indices will - * be reflected to the next **parallel process**, how much pieces to allocate to each {@link ParallelSystem}. - * - * #### Proxy Pattern - * This class {@link DistributedSystemArray} is derived from the {@link ExternalSystemArray} class. Thus, you can take - * advantage of the *Proxy Pattern* in the {@link DistributedSystemArray} class. If a process to request is not the - * *parallel process* (to be distrubted to all slaves), but the **exclusive process** handled in a system, then it - * may better to utilizing the *Proxy Pattern*: - * - * The {@link ExternalSystemArray} class can use *Proxy Pattern*. In framework within user, which - * {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not - * important. Only interested in user's perspective is *which can be done*. - * - * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged - * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. - * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. - * - *
    - *
  • - * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring - * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. - *
  • - *
  • - * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call - * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the - * external system. - *
  • - *
  • Those strategy is called *Proxy Pattern*.
  • - *
- * - * @handbook [Templates - Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) - * @author Jeongho Nam - */ - abstract class DistributedServerClientArrayMediator extends DistributedClientArrayMediator implements external.IExternalServerClientArray { - /** - * Default Constructor. - */ - constructor(); - /** - * Factory method of a child Entity. - * - * This method is migrated to {@link createExternalServer}. Override the {@link createExternalServer} method. - * - * @param xml An {@link XML} object represents child element, so that can identify the type of child to create. - * @return A new child Entity via {@link createExternalServer createExternalServer()}. - */ - createChild(xml: library.XML): System; - /** - * Factory method creating an {@link IDistributedServer} object. - * - * @param xml An {@link XML} object represents child element, so that can identify the type of child to create. - * @return A newly created {@link IDistributedServer} object. - */ - protected abstract createExternalServer(xml: library.XML): System; - /** - * @inheritdoc - */ - connect(): void; - } -} -declare namespace samchon.templates.distributed { - /** - * History of an {@link Invoke} message. - * - * The {@link PRInvokeHistory} is a class archiving history log of an {@link Invoke} message which requests the - * *distributed process*, created whenever {@link DistributedProcess.sendData} is called. - * - * When the *distributed process* has completed, then {@link complete complete()} is called and the *elapsed time* is - * determined. The elapsed time is utilized for computation of {@link DistributedSystem.getPerformance performance index} - * and {@link DistributedProcess.getResource resource index} of related objects. - * - * - * - * - * - * @handbook [Templates - Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) - * @author Jeongho Nam - */ - class DSInvokeHistory extends protocol.InvokeHistory { - /** - * @hidden - */ - private system_; - /** - * @hidden - */ - private process_; - /** - * @hidden - */ - private weight_; - /** - * Construct from a DistributedSystem. - * - * @param system The {@link DistributedSystem} object who sent the {@link Invoke} message. - */ - constructor(system: DistributedSystem); - /** - * Initilizer Constructor. - * - * @param system The {@link DistributedSystem} object who sent the {@link Invoke} message. - * @param process The {@link DistributedProcess} object who sent the {@link Invoke} message. - * @param invoke An {@link Invoke} message requesting the *distributed process*. - * @param weight Weight of resource which indicates how heavy this {@link Invoke} message is. - */ - constructor(system: DistributedSystem, process: DistributedProcess, invoke: protocol.Invoke, weight: number); - /** - * @inheritdoc - */ - construct(xml: library.XML): void; - /** - * Get the related {@link DistributedSystem} object. - */ - getSystem(): DistributedSystem; - /** - * Get the related {@link DistributedProcess} object. - */ - getProcess(): DistributedProcess; - /** - * Get weight. - * - * Gets weight of resource which indicates how heavy this {@link Invoke} message is. Default is 1. - */ - getWeight(): number; - /** - * @inheritdoc - */ - toXML(): library.XML; - } -} -declare namespace samchon.templates.external { - /** - * An interface for an {@link ExternalSystemArray} accepts {@link ExternalSystem external clients} as a - * {@link IServer server}. - * - * The easiest way to defining an {@link ExternalSystemArray} who opens server and accepts - * {@link ExternalSystem external clients} is to extending one of below, who are derived from this interface - * {@link IExternalClientArray}. However, if you can't specify an {@link ExternalSystemArray} to be whether server or - * client, then make a class (let's name it as **BaseSystemArray**) extending {@link ExternalSystemArray} and make - * a new class (now, I name it **BaseClientArray**) extending **BaseSystemArray** and implementing this - * interface {@link IExternalClientArray}. Define the **BaseClientArray** following those codes on below: - * - * - * - * @handbook [Templates - External System](https://github.com/samchon/framework/wiki/TypeScript-Templates-External_System) - * @author Jeongho Nam - */ - interface IExternalClientArray extends ExternalSystemArray, protocol.IServer { - } - /** - * An array and manager of {@link ExternalSystem external clients} as a server. - * - * The {@link ExternalClientArray} is an abstract class, derived from the {@link ExternalSystemArray} class, opening - * a server accepting {@link ExternalSystem external clients}. - * - * Extends this {@link ExternalClientArray}, overrides {@link createServerBase createServerBase()} to determine which - * protocol to follow and {@link createExternalClient createExternalClient()} creating child {@link ExternalSystem} - * object. After the extending and overridings, open this server using the {@link open open()} method. - * - * #### [Inherited] {@link ExternalSystemArray} - * The {@link ExternalSystemArray} is an abstract class containing and managing external system drivers, - * {@link ExternalSystem} objects. Within framewokr of network, {@link ExternalSystemArray} represents your system - * and children {@link ExternalSystem} objects represent remote, external systems connected with your system. - * With this {@link ExternalSystemArray}, you can manage multiple external systems as a group. - * - * - * - * - * - * #### Proxy Pattern - * The {@link ExternalSystemArray} class can use *Proxy Pattern*. In framework within user, which - * {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not - * important. Only interested in user's perspective is *which can be done*. - * - * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged - * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. - * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. - * - *
    - *
  • - * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring - * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. - *
  • - *
  • - * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call - * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the - * external system. - *
  • - *
  • Those strategy is called *Proxy Pattern*.
  • - *
- * - * @handbook [Templates - External System](https://github.com/samchon/framework/wiki/TypeScript-Templates-External_System) - * @author Jeongho Nam - */ - abstract class ExternalClientArray extends ExternalSystemArray implements IExternalClientArray { - /** - * @hidden - */ - private server_base_; - /** - * Default Constructor. - */ - constructor(); - /** - * Factory method creating {@link IServerBase} object. - * - * This method {@link createServerBase createServerBase()} determines which templates is used in this server, - * {@link ExternalClientArray}. If the templates is determined, then {@link ExternalSystem external clients} who - * may connect to {@link ExternalClientArray this server} must follow the specified templates. - * - * Creates and returns one of them: - * - * - {@link ServerBase} - * - {@link WebServerBase} - * - {@link SharedWorkerServerBase} - * - * @return A new {@link IServerBase} object. - */ - protected abstract createServerBase(): protocol.IServerBase; - /** - * Add a newly connected remote client. - * - * When a {@link IClientDriver remote client} connects to this *server* {@link ExternalClientArray} object, - * then this {@link ExternalClientArray} creates a child {@link ExternalSystem external client} object through - * the {@link createExternalClient createExternalClient()} method and {@link insert inserts} it. - * - * @param driver A communicator for external client. - */ - addClient(driver: protocol.IClientDriver): void; - /** - * (Deprecated) Factory method creating child object. - * - * The method {@link createChild createChild()} is deprecated. Don't use and override this. - * - * Note that, the {@link ExternalClientArray} is a server accepting {@link ExternalSystem external clients}. - * There's no way to creating the {@link ExternalSystem external clients} in advance before opening the server. - * - * @param xml An {@link XML} object represents the child {@link ExternalSystem} object. - * @return null - */ - createChild(xml: library.XML): T; - /** - * Factory method creating a child {@link ExternalSystem} object. - * - * @param driver A communicator with connected client. - * @return A newly created {@link ExternalSystem} object. - */ - protected abstract createExternalClient(driver: protocol.IClientDriver): T; - /** - * @inheritdoc - */ - open(port: number): void; - /** - * @inheritdoc - */ - close(): void; - } -} -declare namespace samchon.templates.external { - /** - * An interface for an external server driver. - * - * The easiest way to defining an external server driver is to extending one of below, who are derived from this - * interface {@link IExternalServer}. However, if you've to interact with an external system who can be both server - * and client, then make a class (let's name it as **BaseSystem**) extending {@link ExternalSystem} and make a - * new class (now, I name it **BaseServer**) extending **BaseSystem** and implementing this interface - * {@link IExternalServer}. Define the **BaseServer** following those codes on below: - * - * - * - * @handbook [Templates - External System](https://github.com/samchon/framework/wiki/TypeScript-Templates-External_System) - * @author Jeongho Nam - */ - interface IExternalServer extends ExternalSystem { - /** - * Connect to external server. - */ - connect(): void; - } - /** - * An external server driver. - * - * The {@link ExternalServer} is an abstract class, derived from the {@link ExternalSystem} class, connecting to - * remote, external server. Extends this {@link ExternalServer} class and overrides the - * {@link createServerConnector createServerConnector()} method following which protocol the external server uses. - * - * #### [Inherited] {@link ExternalSystem} - * The {@link ExternalSystem} class represents an external system, connected and interact with this system. - * {@link ExternalSystem} takes full charge of network communication with the remote, external system have connected. - * Replied {@link Invoke} messages from the external system is shifted to and processed in, children elements of this - * class, {@link ExternalSystemRole} objects. - * - * - * - * - * - * #### Bridge & Proxy Pattern - * The {@link ExternalSystem} class can be a *bridge* for *logical proxy*. In framework within user, - * which {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not - * important. Only interested in user's perspective is *which can be done*. - * - * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged - * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. - * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. - * - *
    - *
  • - * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring - * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. - *
  • - *
  • - * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call - * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the - * external system. - *
  • - *
  • Those strategy is called *Bridge Pattern* and *Proxy Pattern*.
  • - *
- * - * @handbook [Templates - External System](https://github.com/samchon/framework/wiki/TypeScript-Templates-External_System) - * @author Jeongho Nam - */ - abstract class ExternalServer extends ExternalSystem implements IExternalServer { - /** - * IP address of target external system to connect. - */ - protected ip: string; - /** - * Port number of target external system to connect. - */ - protected port: number; - /** - * Construct from parent {@link ExternalSystemArray}. - * - * @param systemArray The parent {@link ExternalSystemArray} object. - */ - constructor(systemArray: ExternalSystemArray); - /** - * Factory method creating {@link IServerConnector} object. - * - * The {@link createServerConnector createServerConnector()} is an abstract method creating - * {@link IServerConnector} object. Overrides and returns one of them, considering which templates the external - * system follows: - * - * - {@link ServerConnector} - * - {@link WebServerConnector} - * - {@link DedicatedWorkerServerConnector} - * - {@link SharedWorkerServerConnector} - * - * @return A newly created {@link IServerConnector} object. - */ - protected abstract createServerConnector(): protocol.IServerConnector; - /** - * @inheritdoc - */ - connect(): void; - } -} -declare namespace samchon.templates.external { - /** - * An interface for an {@link ExternalSystemArray} connects to {@link IExternalServer external servers} as a - * **client**. - * - * The easiest way to defining an {@link ExternalSystemArray} who connects to - * {@link IExternalServer external servers} is to extending one of below, who are derived from this interface - * {@link IExternalServerArray}. However, if you can't specify an {@link ExternalSystemArray} to be whether server or - * client, then make a class (let's name it as **BaseSystemArray**) extending {@link ExternalSystemArray} and make - * a new class (now, I name it **BaseServerArray**) extending **BaseSystemArray** and implementing this - * interface {@link IExternalServerArray}. Define the **BaseServerArray** following those codes on below: - * - * - * - * @handbook [Templates - External System](https://github.com/samchon/framework/wiki/TypeScript-Templates-External_System) - * @author Jeongho Nam - */ - interface IExternalServerArray extends ExternalSystemArray { - /** - * Connect to {@link IExternalServer external servers}. - * - * This method calls children elements' method {@link IExternalServer.connect} gradually. - */ - connect(): void; - } - /** - * An array and manager of {@link IExternalServer external servers}. - * - * The {@link ExternalServerArray} is an abstract class, derived from the {@link ExternalSystemArray} class, - * connecting to {@link IExternalServer external servers}. - * - * Extends this {@link ExternalServerArray} and overrides {@link createChild createChild()} method creating child - * {@link IExternalServer} object. After the extending and overriding, construct children {@link IExternalServer} - * objects and call the {@link connect connect()} method. - * - * #### [Inherited] {@link ExternalSystemArray} - * The {@link ExternalSystemArray} is an abstract class containing and managing external system drivers, - * {@link ExternalSystem} objects. Within framewokr of network, {@link ExternalSystemArray} represents your system - * and children {@link ExternalSystem} objects represent remote, external systems connected with your system. - * With this {@link ExternalSystemArray}, you can manage multiple external systems as a group. - * - * - * - * - * - * #### Proxy Pattern - * The {@link ExternalSystemArray} class can use *Proxy Pattern*. In framework within user, which - * {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not - * important. Only interested in user's perspective is *which can be done*. - * - * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged - * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. - * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. - * - *
    - *
  • - * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring - * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. - *
  • - *
  • - * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call - * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the - * external system. - *
  • - *
  • Those strategy is called *Proxy Pattern*.
  • - *
- * - * @handbook [Templates - External System](https://github.com/samchon/framework/wiki/TypeScript-Templates-External_System) - * @author Jeongho Nam - */ - abstract class ExternalServerArray extends ExternalSystemArray implements IExternalServerArray { - /** - * Default Constructor. - */ - constructor(); - /** - * @inheritdoc - */ - connect(): void; - } -} -declare namespace samchon.templates.external { - /** - * An interface for an {@link ExternalSystemArray} accepts {@link ExternalSystem external clients} as a - * {@link IServer server} and connects to {@link IExternalServer} as **client**, at the same time. - * - * The easiest way to defining an {@link IExternalServerClientArray} who opens server, accepts - * {@link ExternalSystem external clients} and connects to {@link IExternalServer external servers} is to extending - * one of below, who are derived from this interface {@link IExternalServerClientArray}. However, if you can't - * specify an {@link ExternalSystemArray} to be whether server or client or even can both them, then make a class - * (let's name it as **BaseSystemArray**) extending {@link ExternalSystemArray} and make a new class (now, I name - * it **BaseServerClientArray**) extending **BaseSystemArray** and implementing this interface - * {@link IExternalServerClientArray}. Define the **BaseServerClientArray** following those codes on below: - * - * - * - * @handbook [Templates - External System](https://github.com/samchon/framework/wiki/TypeScript-Templates-External_System) - * @author Jeongho Nam - */ - interface IExternalServerClientArray extends IExternalClientArray { - /** - * Connect to {@link IExternalServer external servers}. - * - * This method calls children elements' method {@link IExternalServer.connect} gradually. - */ - connect(): void; - } - /** - * An array and manager of {@link IExternalServer external servers} and {@link ExternalSystem external clients}. - * - * The {@link ExternalServerClientArray} is an abstract class, derived from the {@link ExternalSystemArray} class, - * opening a server accepting {@link ExternalSystem external clients} and being a client connecting to - * {@link IExternalServer external servers} at the same time. - * - * Extends this {@link ExternalServerClientArray} and overrides below methods. After the overridings, open server - * with {@link open open()} method and connect to {@link IExternalServer external servers} through the - * {@link connect connect()} method. - * - * - {@link createServerBase createServerBase()} - * - {@link createExternalClient createExternalClient()} - * - {@link createExternalServer createExternalServer()} - * - * #### [Inherited] {@link ExternalSystemArray} - * The {@link ExternalSystemArray} is an abstract class containing and managing external system drivers, - * {@link ExternalSystem} objects. Within framewokr of network, {@link ExternalSystemArray} represents your system - * and children {@link ExternalSystem} objects represent remote, external systems connected with your system. - * With this {@link ExternalSystemArray}, you can manage multiple external systems as a group. - * - * - * - * - * - * #### Proxy Pattern - * The {@link ExternalSystemArray} class can use *Proxy Pattern*. In framework within user, which - * {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not - * important. Only interested in user's perspective is *which can be done*. - * - * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged - * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. - * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. - * - *
    - *
  • - * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring - * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. - *
  • - *
  • - * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call - * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the - * external system. - *
  • - *
  • Those strategy is called *Proxy Pattern*.
  • - *
- * - * @handbook [Templates - External System](https://github.com/samchon/framework/wiki/TypeScript-Templates-External_System) - * @author Jeongho Nam - */ - abstract class ExternalServerClientArray extends ExternalClientArray implements IExternalServerClientArray { - /** - * Default Constructor. - */ - constructor(); - /** - * Factory method of a child Entity. - * - * This method is migrated to {@link createExternalServer}. Override the {@link createExternalServer} method. - * - * @param xml An {@link XML} object represents child element, so that can identify the type of child to create. - * @return A new child Entity via {@link createExternalServer createExternalServer()}. - */ - createChild(xml: library.XML): T; - /** - * Factory method creating an {@link IExternalServer} object. - * - * @param xml An {@link XML} object represents child element, so that can identify the type of child to create. - * @return A newly created {@link IExternalServer} object. - */ - protected abstract createExternalServer(xml: library.XML): T; - /** - * @inheritdoc - */ - connect(): void; - } -} -declare namespace samchon.templates.external { - /** - * A role of an external system. - * - * The {@link ExternalSystemRole} class represents a role, *WHAT TO DO*. Extends the {@link ExternalSystemRole} class - * and overrides {@link replyData replyData()} to define the *WHAT TO DO*. And assign this {@link ExternalSystemRole} - * object to related {@link ExternalSystem} object. - * - * - * - * - * - * #### Proxy Pattern - * The {@link ExternalSystemRole} class can be an *logical proxy*. In framework within user, which - * {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not - * important. Only interested in user's perspective is *which can be done*. - * - * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged - * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. - * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. - * - *
    - *
  • - * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring - * from {@link ExternalSystem} object, via {@link ExternalSystemArray.getRole ExternalSystemArray.getRole()}. - *
  • - *
  • - * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call - * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the - * external system. - *
  • - *
  • Those strategy is called *Proxy Pattern*.
  • - *
- * - * @handbook [Templates - External System](https://github.com/samchon/framework/wiki/TypeScript-Templates-External_System) - * @author Jeongho Nam - */ - abstract class ExternalSystemRole extends protocol.Entity implements protocol.IProtocol { - /** - * @hidden - */ - private system; - /** - * A name, represents and identifies this {@link ExternalSystemRole role}. - * - * This {@link name} is an identifier represents this {@link ExternalSystemRole role}. This {@link name} is - * used in {@link ExternalSystemArray.getRole} and {@link ExternalSystem.get}, as a key elements. Thus, this - * {@link name} should be unique in an {@link ExternalSystemArray}. - */ - protected name: string; - /** - * Constructor from a system. - * - * @param system An external system containing this role. - */ - constructor(system: ExternalSystem); - /** - * Identifier of {@link ExternalSystemRole} is its {@link name}. - */ - key(): string; - /** - * Get grandparent {@link ExternalSystemArray}. - * - * Get the grandparent {@link ExternalSystemArray} object through this parent {@link ExternalSystem}, - * {@link ExternalSystem.getSystemArray ExternalSystem.getSystemArray()}. - * - * @return The grandparent {@link ExternalSystemArray} object. - */ - getSystemArray(): ExternalSystemArray; - /** - * Get parent {@link ExternalSystemRole} object. - */ - getSystem(): ExternalSystem; - /** - * Get name, who represents and identifies this role. - */ - getName(): string; - /** - * Send an {@link Invoke} message. - * - * Sends an {@link Invoke} message to remote system through the parent {@link ExternalSystem} object. - * - * @param invoke An {@link Invoke} message to send to the external system. - */ - sendData(invoke: protocol.Invoke): void; - /** - * Handle replied {@link Invoke} message. - * - * {@link ExternalSystemRole.replyData ExternalSystemRole.replyData()} is an abstract method handling a replied - * {@link Invoke message} gotten from remote system via parent {@link ExternalSystem} object. Overrides this - * method and defines the *WHAT TO DO* with the {@link Invoke message}. - * - * @param invoke An {@link Invoke} message received from the {@link ExternalSystem external system}. - */ - abstract replyData(invoke: protocol.Invoke): void; - /** - * Tag name of the {@link ExternalSytemRole} in {@link XML}. - * - * @return *role*. - */ - TAG(): string; - } -} -declare namespace samchon.templates.slave { - abstract class SlaveSystem implements protocol.IProtocol { - /** - * @hidden - */ - protected communicator_: protocol.ICommunicator; - /** - * Default Constructor. - */ - constructor(); - sendData(invoke: protocol.Invoke): void; - /** - * @hidden - */ - protected _replyData(invoke: protocol.Invoke): void; - replyData(invoke: protocol.Invoke): void; - } -} -declare namespace samchon.templates.parallel { - /** - * A mediator, the master driver. - * - * The {@link MediatorSystem} is an abstract class helping {@link ParallelSystemArrayMediator} can be a **slave** - * system. The {@link MediatorSystem} interacts and communicates with the **master** system as a role of **slave**. - * - * This {@link MediatorSystem} object is created in {@link ParallelSystemArrayMediator.createMediator}. Override the - * method and return one of them, which are derived from this {@link MediatorSystem} class, considering which - * type and protocol the **master** system follows: - * - * - A client slave connecting to master server: - * - {@link MediatorClient} - * - {@link MediatorWebClient} - * - {@link MediatorSharedWorkerClient} - * - A server slave accepting master client: - * - {@link MediatorServer} - * - {@link MediatorWebServer} - * - {@link MediatorDedicatedWorkerServer} - * - {@link MediatorSharedWorkerServer} - * - * When the **master** orders a *parallel process* to this **slave**, then the {@link MediatorSystem} delivers the - * *parallel process* to its parent {@link ParallelSystemArrayMediator} object. The - * {@link ParallelSystemArrayMediator} object distributes the *parallel process* to its slaves system, - * {@link ParallelSystem} objects. When the *parallel process* has completed, then {@link MediatorSystem} reports the - * result to its **master**. - * - * - * - * - * - * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System), - * [Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) - * @author Jeongho Nam - */ - abstract class MediatorSystem extends slave.SlaveSystem { - /** - * @hidden - */ - private system_array_; - /** - * @hidden - */ - private progress_list_; - /** - * Construct from parent {@link ParallelSystemArrayMediator} object. - * - * @param systemArray The parent {@link ParallelSystemArrayMediator} object. - */ - constructor(systemArray: ParallelSystemArrayMediator); - /** - * Construct from parent {@link DistributedSystemArrayMediator} object. - * - * @param systemArray The parent {@link DistributedSystemArrayMediator} object. - */ - constructor(systemArray: distributed.DistributedSystemArrayMediator); - /** - * Start interaction. - * - * The {@link start start()} is an abstract method starting interaction with the **master** system. If the - * **master** is a server, then connects to the **master**. Otherwise, the **master** is client, then this - * {@link MediatorSystem} object wil open a server accepting the **master**. - */ - abstract start(): void; - /** - * Get parent {@link ParallelSystemArrayMediator} or {@link DistributedSystemArrayMediator} object. - */ - getSystemArray(): ParallelSystemArrayMediator | distributed.DistributedSystemArrayMediator; - /** - * Get parent {@link ParallelSystemArrayMediator} object. - */ - getSystemArray>(): SystemArray; - /** - * Get parent {@link DistributedSystemArrayMediator} object. - */ - getSystemArray>(): SystemArray; - /** - * @hidden - */ - private complete_history(uid); - /** - * @hidden - */ - protected _replyData(invoke: protocol.Invoke): void; - /** - * @inheritdoc - */ - replyData(invoke: protocol.Invoke): void; - } -} -declare namespace samchon.templates.parallel { - /** - * A mediator server, driver for the master client. - * - * The {@link MediatorServer} is a class opening a server accepting the **master** client, following the protocol of - * Samchon Framework's own. - * - * #### [Inherited] {@link MediatorSystem} - * The {@link MediatorSystem} is an abstract class helping {@link ParallelSystemArrayMediator} can be a **slave** - * system. The {@link MediatorSystem} interacts and communicates with the **master** system as a role of **slave**. - * - * This {@link MediatorSystem} object is created in {@link ParallelSystemArrayMediator.createMediator}. Override the - * method and return one of them, which are derived from this {@link MediatorSystem} class, considering which - * type and protocol the **master** system follows: - * - * - A client slave connecting to master server: - * - {@link MediatorClient} - * - {@link MediatorWebClient} - * - {@link MediatorSharedWorkerClient} - * - A server slave accepting master client: - * - {@link MediatorServer} - * - {@link MediatorWebServer} - * - {@link MediatorDedicatedWorkerServer} - * - {@link MediatorSharedWorkerServer} - * - * When the **master** orders a *parallel process* to this **slave**, then the {@link MediatorSystem} delivers the - * *parallel process* to its parent {@link ParallelSystemArrayMediator} object. The - * {@link ParallelSystemArrayMediator} object distributes the *parallel process* to its slaves system, - * {@link ParallelSystem} objects. When the *parallel process* has completed, then {@link MediatorSystem} reports the - * result to its **master**. - * - * - * - * - * - * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System), - * [Templates - Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) - * @author Jeongho Nam - */ - class MediatorServer extends MediatorSystem implements slave.ISlaveServer { - /** - * @hidden - */ - private server_base_; - /** - * @hidden - */ - private port; - /** - * Initializer Constructor. - * - * @param systemArray The parent {@link ParallelSystemArrayMediator} object. - * @param port Port number of server to open. - */ - constructor(systemArray: ParallelSystemArrayMediator, port: number); - /** - * Initializer Constructor. - * - * @param systemArray The parent {@link DistributedSystemArrayMediator} object. - * @param port Port number of server to open. - */ - constructor(systemArray: distributed.DistributedSystemArrayMediator, port: number); - /** - * Factory method creating {@link IServerBase} object. - * - * This method {@link createServerBase createServerBase()} determines which protocol is used in this server, - * {@link MediatorServer}. Note that, **slave** (this {@link MediatorServer} object) must follow the **master**'s - * protocol. - * - * Overrides and return one of them considering the which protocol to follow: - * - * - {@link ServerBase} - * - {@link WebServerBase} - * - {@link SharedWorkerServerBase} - */ - protected createServerBase(): protocol.IServerBase; - /** - * Add a newly connected remote client. - * - * {@link MediatorServer} represents a **slave** dedicating to its **master**. In that reason, the - * {@link MediatorServer} does not accept multiple **master** clients. It accepts only one. Thus, *listener* of - * the *communicator* is {@link MediatorSystem} object, itself. - * - * @param driver A communicator with remote client. - */ - addClient(driver: protocol.IClientDriver): void; - /** - * @inheritdoc - */ - start(): void; - /** - * @inheritdoc - */ - open(port: number): void; - /** - * @inheritdoc - */ - close(): void; - } - /** - * A mediator server, driver for the master client. - * - * The {@link MediatorWebServer} is a class opening a server accepting the **master** client, following the - * web-socket protocol. - * - * #### [Inherited] {@link MediatorSystem} - * The {@link MediatorSystem} is an abstract class helping {@link ParallelSystemArrayMediator} can be a **slave** - * system. The {@link MediatorSystem} interacts and communicates with the **master** system as a role of **slave**. - * - * This {@link MediatorSystem} object is created in {@link ParallelSystemArrayMediator.createMediator}. Override the - * method and return one of them, which are derived from this {@link MediatorSystem} class, considering which - * type and protocol the **master** system follows: - * - * - A client slave connecting to master server: - * - {@link MediatorClient} - * - {@link MediatorWebClient} - * - {@link MediatorSharedWorkerClient} - * - A server slave accepting master client: - * - {@link MediatorServer} - * - {@link MediatorWebServer} - * - {@link MediatorDedicatedWorkerServer} - * - {@link MediatorSharedWorkerServer} - * - * When the **master** orders a *parallel process* to this **slave**, then the {@link MediatorSystem} delivers the - * *parallel process* to its parent {@link ParallelSystemArrayMediator} object. The - * {@link ParallelSystemArrayMediator} object distributes the *parallel process* to its slaves system, - * {@link ParallelSystem} objects. When the *parallel process* has completed, then {@link MediatorSystem} reports the - * result to its **master**. - * - * - * - * - * - * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System), - * [Templates - Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) - * @author Jeongho Nam - */ - class MediatorWebServer extends MediatorServer { - /** - * @inheritdoc - */ - protected createServerBase(): protocol.IServerBase; - } - /** - * A mediator server, driver for the master client. - * - * The {@link MediatorDedicatedWorkerServer} is a class opening a server accepting the **master** client, following - * the DedicatedWorker's protocol. - * - * #### [Inherited] {@link MediatorSystem} - * The {@link MediatorSystem} is an abstract class helping {@link ParallelSystemArrayMediator} can be a **slave** - * system. The {@link MediatorSystem} interacts and communicates with the **master** system as a role of **slave**. - * - * This {@link MediatorSystem} object is created in {@link ParallelSystemArrayMediator.createMediator}. Override the - * method and return one of them, which are derived from this {@link MediatorSystem} class, considering which - * type and protocol the **master** system follows: - * - * - A client slave connecting to master server: - * - {@link MediatorClient} - * - {@link MediatorWebClient} - * - {@link MediatorSharedWorkerClient} - * - A server slave accepting master client: - * - {@link MediatorServer} - * - {@link MediatorWebServer} - * - {@link MediatorDedicatedWorkerServer} - * - {@link MediatorSharedWorkerServer} - * - * When the **master** orders a *parallel process* to this **slave**, then the {@link MediatorSystem} delivers the - * *parallel process* to its parent {@link ParallelSystemArrayMediator} object. The - * {@link ParallelSystemArrayMediator} object distributes the *parallel process* to its slaves system, - * {@link ParallelSystem} objects. When the *parallel process* has completed, then {@link MediatorSystem} reports the - * result to its **master**. - * - * - * - * - * - * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System), - * [Templates - Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) - * @author Jeongho Nam - */ - class MediatorDedicatedWorkerServer extends MediatorServer { - /** - * @inheritdoc - */ - protected createServerBase(): protocol.IServerBase; - } - /** - * A mediator server, driver for the master client. - * - * The {@link MediatorSharedWorkerServer} is a class opening a server accepting the **master** client, following the - * SharedWorker's protocol. - * - * #### [Inherited] {@link MediatorSystem} - * The {@link MediatorSystem} is an abstract class helping {@link ParallelSystemArrayMediator} can be a **slave** - * system. The {@link MediatorSystem} interacts and communicates with the **master** system as a role of **slave**. - * - * This {@link MediatorSystem} object is created in {@link ParallelSystemArrayMediator.createMediator}. Override the - * method and return one of them, which are derived from this {@link MediatorSystem} class, considering which - * type and protocol the **master** system follows: - * - * - A client slave connecting to master server: - * - {@link MediatorClient} - * - {@link MediatorWebClient} - * - {@link MediatorSharedWorkerClient} - * - A server slave accepting master client: - * - {@link MediatorServer} - * - {@link MediatorWebServer} - * - {@link MediatorDedicatedWorkerServer} - * - {@link MediatorSharedWorkerServer} - * - * When the **master** orders a *parallel process* to this **slave**, then the {@link MediatorSystem} delivers the - * *parallel process* to its parent {@link ParallelSystemArrayMediator} object. The - * {@link ParallelSystemArrayMediator} object distributes the *parallel process* to its slaves system, - * {@link ParallelSystem} objects. When the *parallel process* has completed, then {@link MediatorSystem} reports the - * result to its **master**. - * - * - * - * - * - * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System), - * [Templates - Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) - * @author Jeongho Nam - */ - class MediatorSharedWorkerServer extends MediatorServer { - /** - * @inheritdoc - */ - protected createServerBase(): protocol.IServerBase; - } -} -declare namespace samchon.templates.parallel { - /** - * A mediator client, driver for the master server. - * - * The {@link MediatorServer} is a class being a client connecting to the **master** server, following the protocol - * of Samchon Framework's own. - * - * #### [Inherited] {@link MediatorSystem} - * The {@link MediatorSystem} is an abstract class helping {@link ParallelSystemArrayMediator} can be a **slave** - * system. The {@link MediatorSystem} interacts and communicates with the **master** system as a role of **slave**. - * - * This {@link MediatorSystem} object is created in {@link ParallelSystemArrayMediator.createMediator}. Override the - * method and return one of them, which are derived from this {@link MediatorSystem} class, considering which - * type and protocol the **master** system follows: - * - * - A client slave connecting to master server: - * - {@link MediatorClient} - * - {@link MediatorWebClient} - * - {@link MediatorSharedWorkerClient} - * - A server slave accepting master client: - * - {@link MediatorServer} - * - {@link MediatorWebServer} - * - {@link MediatorDedicatedWorkerServer} - * - {@link MediatorSharedWorkerServer} - * - * When the **master** orders a *parallel process* to this **slave**, then the {@link MediatorSystem} delivers the - * *parallel process* to its parent {@link ParallelSystemArrayMediator} object. The - * {@link ParallelSystemArrayMediator} object distributes the *parallel process* to its slaves system, - * {@link ParallelSystem} objects. When the *parallel process* has completed, then {@link MediatorSystem} reports the - * result to its **master**. - * - * - * - * - * - * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System), - * [Templates - Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) - * @author Jeongho Nam - */ - class MediatorClient extends MediatorSystem implements slave.ISlaveClient { - /** - * @hidden - */ - private ip; - /** - * @hidden - */ - private port; - /** - * Initializer Constructor. - * - * @param systemArray The parent {@link ParallelSystemArrayMediator} object. - * @param ip IP address to connect. - * @param port Port number to connect. - */ - constructor(systemArray: ParallelSystemArrayMediator, ip: string, port: number); - /** - * Initializer Constructor. - * - * @param systemArray The parent {@link DistributedSystemArrayMediator} object. - * @param ip IP address to connect. - * @param port Port number to connect. - */ - constructor(systemArray: distributed.DistributedSystemArrayMediator, ip: string, port: number); - /** - * Factory method creating {@link IServerConnector} object. - * - * The {@link createServerConnector createServerConnector()} is an abstract method creating - * {@link IServerConnector} object. Overrides and returns one of them, considering which protocol the **master** - * server follows: - * - * - {@link ServerConnector} - * - {@link WebServerConnector} - * - {@link SharedWorkerServerConnector} - * - * @return A newly created {@link IServerConnector} object. - */ - protected createServerConnector(): protocol.IServerConnector; - /** - * @inheritdoc - */ - start(): void; - /** - * @inheritdoc - */ - connect(): void; - } - /** - * A mediator client, driver for the master server. - * - * The {@link MediatorWebClient} is a class being a client connecting to the **master** server, following the - * web-socket protocol. - * - * #### [Inherited] {@link MediatorSystem} - * The {@link MediatorSystem} is an abstract class helping {@link ParallelSystemArrayMediator} can be a **slave** - * system. The {@link MediatorSystem} interacts and communicates with the **master** system as a role of **slave**. - * - * This {@link MediatorSystem} object is created in {@link ParallelSystemArrayMediator.createMediator}. Override the - * method and return one of them, which are derived from this {@link MediatorSystem} class, considering which - * type and protocol the **master** system follows: - * - * - A client slave connecting to master server: - * - {@link MediatorClient} - * - {@link MediatorWebClient} - * - {@link MediatorSharedWorkerClient} - * - A server slave accepting master client: - * - {@link MediatorServer} - * - {@link MediatorWebServer} - * - {@link MediatorDedicatedWorkerServer} - * - {@link MediatorSharedWorkerServer} - * - * When the **master** orders a *parallel process* to this **slave**, then the {@link MediatorSystem} delivers the - * *parallel process* to its parent {@link ParallelSystemArrayMediator} object. The - * {@link ParallelSystemArrayMediator} object distributes the *parallel process* to its slaves system, - * {@link ParallelSystem} objects. When the *parallel process* has completed, then {@link MediatorSystem} reports the - * result to its **master**. - * - * - * - * - * - * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System), - * [Templates - Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) - * @author Jeongho Nam - */ - class MediatorWebClient extends MediatorClient { - /** - * @inheritdoc - */ - protected createServerConnector(): protocol.IServerConnector; - } - /** - * A mediator client, driver for the master server. - * - * The {@link MediatorSharedWorkerClient} is a class being a client connecting to the **master** server, following - * the SharedWorker's protocol. - * - * #### [Inherited] {@link MediatorSystem} - * The {@link MediatorSystem} is an abstract class helping {@link ParallelSystemArrayMediator} can be a **slave** - * system. The {@link MediatorSystem} interacts and communicates with the **master** system as a role of **slave**. - * - * This {@link MediatorSystem} object is created in {@link ParallelSystemArrayMediator.createMediator}. Override the - * method and return one of them, which are derived from this {@link MediatorSystem} class, considering which - * type and protocol the **master** system follows: - * - * - A client slave connecting to master server: - * - {@link MediatorClient} - * - {@link MediatorWebClient} - * - {@link MediatorSharedWorkerClient} - * - A server slave accepting master client: - * - {@link MediatorServer} - * - {@link MediatorWebServer} - * - {@link MediatorDedicatedWorkerServer} - * - {@link MediatorSharedWorkerServer} - * - * When the **master** orders a *parallel process* to this **slave**, then the {@link MediatorSystem} delivers the - * *parallel process* to its parent {@link ParallelSystemArrayMediator} object. The - * {@link ParallelSystemArrayMediator} object distributes the *parallel process* to its slaves system, - * {@link ParallelSystem} objects. When the *parallel process* has completed, then {@link MediatorSystem} reports the - * result to its **master**. - * - * - * - * - * - * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System), - * [Templates - Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) - * @author Jeongho Nam - */ - class MediatorSharedWorkerClient extends MediatorClient { - /** - * @inheritdoc - */ - protected createServerConnector(): protocol.IServerConnector; - } -} -declare namespace samchon.templates.parallel { - /** - * Master of Parallel Processing System, a server accepting slave clients. - * - * The {@link ParallelClientArray} is an abstract class, derived from the {@link ParallelSystemArray} class, opening - * a server accepting {@link ParallelSystem parallel clients}. - * - * Extends this {@link ParallelClientArray}, overrides {@link createServerBase createServerBase()} to determine which - * protocol to follow and {@link createExternalClient createExternalClient()} creating child {@link ParallelSystem} - * object. After the extending and overridings, open this server using the {@link open open()} method. - * - * #### [Inherited] {@link ParallelSystemArray} - * The {@link ParallelSystemArray} is an abstract class containing and managing remote parallel **slave** system - * drivers, {@link ParallelSystem} objects. Within framework of network, {@link ParallelSystemArray} represents your - * system, a **Master** of *Parallel Processing System* that requesting *parallel process* to slave systems and the - * children {@link ParallelSystem} objects represent the remote slave systems, who is being requested the - * *parallel processes*. - * - * When you need the **parallel process**, then call one of them: {@link sendSegmentData} or {@link sendPieceData}. - * When the **parallel process** has completed, {@link ParallelSystemArray} estimates each {@link ParallelSystem}'s - * {@link ParallelSystem.getPerformance performance index} basis on their execution time. Those performance indices - * will be reflected to the next **parallel process**, how much pieces to allocate to each {@link ParallelSystem}. - * - * - * - * - * - * #### Proxy Pattern - * This class {@link ParallelSystemArray} is derived from the {@link ExternalSystemArray} class. Thus, you can take - * advantage of the *Proxy Pattern* in the {@link ParallelSystemArray} class. If a process to request is not the - * *parallel process* (to be distrubted to all slaves), but the **exclusive process** handled in a system, then it - * may better to utilizing the *Proxy Pattern*: - * - * The {@link ExternalSystemArray} class can use *Proxy Pattern*. In framework within user, which - * {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not - * important. Only interested in user's perspective is *which can be done*. - * - * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged - * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. - * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. - * - *
    - *
  • - * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring - * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. - *
  • - *
  • - * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call - * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the - * external system. - *
  • - *
  • Those strategy is called *Proxy Pattern*.
  • - *
- * - * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System) - * @author Jeongho Nam - */ - abstract class ParallelClientArray extends ParallelSystemArray implements external.IExternalClientArray { - /** - * @hidden - */ - private server_base_; - /** - * Default Constructor. - */ - constructor(); - /** - * Factory method creating {@link IServerBase} object. - * - * This method {@link createServerBase createServerBase()} determines which protocol is used in this server, - * {@link ExternalClientArray}. If the protocol is determined, then {@link ExternalSystem external clients} who - * may connect to {@link ExternalClientArray this server} must follow the specified protocol. - * - * Overrides the {@link createServerBase createServerBase()} method to create and return one of them: - * - * - {@link ServerBase} - * - {@link WebServerBase} - * - {@link SharedWorkerServerBase} - * - * @return A new {@link IServerBase} object. - */ - protected abstract createServerBase(): protocol.IServerBase; - /** - * Add a newly connected remote client. - * - * When a {@link IClientDriver remote client} connects to this *master server of parallel processing system*, - * then this {@link ParallelClientArray} creates a child {@link ParallelSystem parallel client} object through - * the {@link createExternalClient createExternalClient()} method and {@link insert inserts} it. - * - * @param driver A communicator for external client. - */ - addClient(driver: protocol.IClientDriver): void; - /** - * (Deprecated) Factory method creating child object. - * - * The method {@link createChild createChild()} is deprecated. Don't use and override this. - * - * Note that, the {@link ParallelClientArray} is a server accepting {@link ParallelSystem parallel clients}. - * There's no way to creating the {@link ParallelSystem parallel clients} in advance before opening the server. - * - * @param xml An {@link XML} object represents the child {@link ParallelSystem} object. - * @return ```null``` - */ - createChild(xml: library.XML): System; - /** - * Factory method creating {@link ParallelSystem} object. - * - * The method {@link createExternalClient createExternalClient()} is a factory method creating a child - * {@link ParallelSystem} object, that is called whenever a parallel client has connected, by - * {@link addClient addClient()}. - * - * Overrides this {@link createExternalClient} method and creates a type of {@link ParallelSystem} object with - * the *driver* that communicates with the parallel client. After the creation, returns the {@link ParallelSystem} - * object. Then whenever a parallel client has connected, matched {@link ParallelSystem} object will be - * constructed and {@link insert inserted} into this {@link ParallelClientArray} object. - * - * @param driver A communicator with the parallel client. - * @return A newly created {@link ParallelSystem} object. - */ - protected abstract createExternalClient(driver: protocol.IClientDriver): System; - /** - * @inheritdoc - */ - open(port: number): void; - /** - * @inheritdoc - */ - close(): void; - } -} -declare namespace samchon.templates.parallel { - /** - * Mediator of Parallel Processing System. - * - * The {@link ParallelSystemArrayMediator} class be a **master** for its slave systems, and be a **slave** to its - * master system at the same time. This {@link ParallelSystemArrayMediator} be a **master **system, containing and - * managing {@link ParallelSystem} objects, which represent parallel slave systems, by extending - * {@link ParallelSystemArray} class. Also, be a **slave** system through {@link getMediator mediator} object, which is - * derived from the {@link SlaveSystem} class. - * - * As a **master**, you can specify this {@link ParallelSystemArrayMediator} class to be a master server accepting - * slave clients or a master client to connecting slave servers. Even both of them is possible. Extends one - * of them below and overrides abstract factory method(s) creating the child {@link ParallelSystem} object. - * - * - {@link ParallelClientArrayMediator}: A server accepting {@link ParallelSystem parallel clients}. - * - {@link ParallelServerArrayMediator}: A client connecting to {@link ParallelServer parallel servers}. - * - {@link ParallelServerClientArrayMediator}: Both of them. Accepts {@link ParallelSystem parallel clients} and - * connects to {@link ParallelServer parallel servers} at the same time. - * - * As a **slave**, you can specify this {@link ParallelSystemArrayMediator} to be a client slave connecting to - * master server or a server slave accepting master client by overriding the {@link createMediator} method. - * Overrides the {@link createMediator createMediator()} method and return one of them: - * - * - A client slave connecting to master server: - * - {@link MediatorClient} - * - {@link MediatorWebClient} - * - {@link MediatorSharedWorkerClient} - * - A server slave accepting master client: - * - {@link MediatorServer} - * - {@link MediatorWebServer} - * - {@link MediatorDedicatedWorkerServer} - * - {@link MediatorSharedWorkerServer} - * - * #### [Inherited] {@link ParallelSystemArray} - * The {@link ParallelSystemArray} is an abstract class containing and managing remote parallel **slave** system - * drivers, {@link ParallelSystem} objects. Within framework of network, {@link ParallelSystemArray} represents your - * system, a **Master** of *Parallel Processing System* that requesting *parallel process* to slave systems and the - * children {@link ParallelSystem} objects represent the remote slave systems, who is being requested the - * *parallel processes*. - * - * When you need the **parallel process**, then call one of them: {@link sendSegmentData} or {@link sendPieceData}. - * When the **parallel process** has completed, {@link ParallelSystemArray} estimates each {@link ParallelSystem}'s - * {@link ParallelSystem.getPerformance performance index} basis on their execution time. Those performance indices - * will be reflected to the next **parallel process**, how much pieces to allocate to each {@link ParallelSystem}. - * - * - * - * - * - * #### Proxy Pattern - * This class {@link ParallelSystemArray} is derived from the {@link ExternalSystemArray} class. Thus, you can take - * advantage of the *Proxy Pattern* in the {@link ParallelSystemArray} class. If a process to request is not the - * *parallel process* (to be distrubted to all slaves), but the **exclusive process** handled in a system, then it - * may better to utilizing the *Proxy Pattern*: - * - * The {@link ExternalSystemArray} class can use *Proxy Pattern*. In framework within user, which - * {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not - * important. Only interested in user's perspective is *which can be done*. - * - * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged - * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. - * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. - * - *
    - *
  • - * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring - * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. - *
  • - *
  • - * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call - * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the - * external system. - *
  • - *
  • Those strategy is called *Proxy Pattern*.
  • - *
- * - * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System) - * @author Jeongho Nam - */ - abstract class ParallelSystemArrayMediator extends ParallelSystemArray { - /** - * @hidden - */ - private mediator_; - /** - * Default Constructor. - */ - constructor(); - /** - * Factory method creating a {@link MediatorSystem} object. - * - * The {@link createMediator createMediator()} is an abstract method creating the {@link MediatorSystem} object. - * - * You know what? this {@link ParallelSystemArrayMediator} class be a **master** for its slave systems, and be a - * **slave** to its master system at the same time. The {@link MediatorSystem} object makes it possible; be a - * **slave** system. This {@link createMediator} determines specific type of the {@link MediatorSystem}. - * - * Overrides the {@link createMediator createMediator()} method to create and return one of them following which - * protocol and which type of remote connection (server or client) will be used: - * - * - A client slave connecting to master server: - * - {@link MediatorClient} - * - {@link MediatorWebClient} - * - {@link MediatorSharedWorkerClient} - * - A server slave accepting master client: - * - {@link MediatorServer} - * - {@link MediatorWebServer} - * - {@link MediatorDedicatedWorkerServer} - * - {@link MediatorSharedWorkerServer} - * - * @return A newly created {@link MediatorSystem} object. - */ - protected abstract createMediator(): MediatorSystem; - /** - * Start mediator. - * - * If the {@link getMediator mediator} is a type of server, then opens the server accepting master client. - * Otherwise, the {@link getMediator mediator} is a type of client, then connects the master server. - */ - protected startMediator(): void; - /** - * Get {@link MediatorSystem} object. - * - * When you need to send an {@link Invoke} message to the master system of this - * {@link ParallelSystemArrayMediator}, then send to the {@link MediatorSystem} through this {@link getMediator}. - * - * ```typescript - * this.getMediator().sendData(...); - * ``` - * - * @return The {@link MediatorSystem} object. - */ - getMediator(): MediatorSystem; - /** - * @hidden - */ - protected _Complete_history(history: PRInvokeHistory): boolean; - } -} -declare namespace samchon.templates.parallel { - /** - * Mediator of Parallel Processing System, a server accepting slave clients. - * - * The {@link ParallelClientArrayMediator} is an abstract class, derived from the {@link ParallelSystemArrayMediator} - * class, opening a server accepting {@link ParallelSystem parallel clients} as a **master**. - * - * Extends this {@link ParallelClientArrayMediator}, overrides {@link createServerBase createServerBase()} to - * determine which protocol to follow and {@link createExternalClient createExternalClient()} creating child - * {@link ParallelSystem} object. After the extending and overridings, open this server using the - * {@link open open()} method. - * - * #### [Inherited] {@link ParallelSystemArrayMediator} - * The {@link ParallelSystemArrayMediator} class be a **master** for its slave systems, and be a **slave** to its - * master system at the same time. This {@link ParallelSystemArrayMediator} be a **master **system, containing and - * managing {@link ParallelSystem} objects, which represent parallel slave systems, by extending - * {@link ParallelSystemArray} class. Also, be a **slave** system through {@link getMediator mediator} object, which is - * derived from the {@link SlaveSystem} class. - * - * As a **slave**, you can specify this {@link ParallelSystemArrayMediator} to be a client slave connecting to - * master server or a server slave accepting master client by overriding the {@link createMediator} method. - * Overrides the {@link createMediator createMediator()} method and return one of them: - * - * - A client slave connecting to master server: - * - {@link MediatorClient} - * - {@link MediatorWebClient} - * - {@link MediatorSharedWorkerClient} - * - A server slave accepting master client: - * - {@link MediatorServer} - * - {@link MediatorWebServer} - * - {@link MediatorDedicatedWorkerServer} - * - {@link MediatorSharedWorkerServer} - * - * #### [Inherited] {@link ParallelSystemArray} - * The {@link ParallelSystemArray} is an abstract class containing and managing remote parallel **slave** system - * drivers, {@link ParallelSystem} objects. Within framework of network, {@link ParallelSystemArray} represents your - * system, a **Master** of *Parallel Processing System* that requesting *parallel process* to slave systems and the - * children {@link ParallelSystem} objects represent the remote slave systems, who is being requested the - * *parallel processes*. - * - * When you need the **parallel process**, then call one of them: {@link sendSegmentData} or {@link sendPieceData}. - * When the **parallel process** has completed, {@link ParallelSystemArray} estimates each {@link ParallelSystem}'s - * {@link ParallelSystem.getPerformance performance index} basis on their execution time. Those performance indices - * will be reflected to the next **parallel process**, how much pieces to allocate to each {@link ParallelSystem}. - * - * - * - * - * - * #### Proxy Pattern - * This class {@link ParallelSystemArray} is derived from the {@link ExternalSystemArray} class. Thus, you can take - * advantage of the *Proxy Pattern* in the {@link ParallelSystemArray} class. If a process to request is not the - * *parallel process* (to be distrubted to all slaves), but the **exclusive process** handled in a system, then it - * may better to utilizing the *Proxy Pattern*: - * - * The {@link ExternalSystemArray} class can use *Proxy Pattern*. In framework within user, which - * {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not - * important. Only interested in user's perspective is *which can be done*. - * - * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged - * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. - * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. - * - *
    - *
  • - * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring - * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. - *
  • - *
  • - * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call - * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the - * external system. - *
  • - *
  • Those strategy is called *Proxy Pattern*.
  • - *
- * - * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System) - * @author Jeongho Nam - */ - abstract class ParallelClientArrayMediator extends ParallelSystemArrayMediator implements external.IExternalClientArray { - /** - * @hidden - */ - private server_base_; - /** - * Default Constructor. - */ - constructor(); - /** - * Factory method creating {@link IServerBase} object. - * - * This method {@link createServerBase createServerBase()} determines which protocol is used in this server, - * {@link ParallelClientArrayMediator}. If the protocol is determined, then - * {@link ParallelSystem parallel clients} who may connect to {@link ParallelClientArrayMediator this server} - * must follow the specified protocol. - * - * Overrides the {@link createServerBase createServerBase()} method to create and return one of them: - * - * - {@link ServerBase} - * - {@link WebServerBase} - * - {@link SharedWorkerServerBase} - * - * @return A new {@link IServerBase} object. - */ - protected abstract createServerBase(): protocol.IServerBase; - /** - * Add a newly connected remote client. - * - * When a {@link IClientDriver remote client} connects to this *master server of parallel processing system*, - * then this {@link ParallelClientArrayMediator} creates a child {@link ParallelSystem parallel client} object - * through the {@link createExternalClient createExternalClient()} method and {@link insert inserts} it. - * - * @param driver A communicator for parallel client. - */ - addClient(driver: protocol.IClientDriver): void; - /** - * (Deprecated) Factory method creating child object. - * - * The method {@link createChild createChild()} is deprecated. Don't use and override this. - * - * Note that, the {@link ParallelClientArrayMediator} is a server accepting {@link ParallelSystem parallel - * clients} as a master. There's no way to creating the {@link ParallelSystem parallel clients} in advance before - * opening the server. - * - * @param xml An {@link XML} object represents the child {@link ParallelSystem} object. - * @return null - */ - createChild(xml: library.XML): System; - /** - * Factory method creating {@link ParallelSystem} object. - * - * The method {@link createExternalClient createExternalClient()} is a factory method creating a child - * {@link ParallelSystem} object, that is called whenever a parallel client has connected, by - * {@link addClient addClient()}. - * - * Overrides this {@link createExternalClient} method and creates a type of {@link ParallelSystem} object with - * the *driver* that communicates with the parallel client. After the creation, returns the {@link ParallelSystem} - * object. Then whenever a parallel client has connected, matched {@link ParallelSystem} object will be - * constructed and {@link insert inserted} into this {@link ParallelClientArrayMediator} object. - * - * @param driver A communicator with the parallel client. - * @return A newly created {@link ParallelSystem} object. - */ - protected abstract createExternalClient(driver: protocol.IClientDriver): System; - /** - * @inheritdoc - */ - open(port: number): void; - /** - * @inheritdoc - */ - close(): void; - } -} -declare namespace samchon.templates.parallel { - /** - * An interface for a parallel slave server driver. - * - * The easiest way to defining a driver for parallel **slave** server is extending {@link ParallelServer} class. - * However, if you've to interact with a prallel **slave** system who can be both server and client, them make a class - * (let's name it **BaseSystem**) extending the {@link ParallelSystem} class. At next, make a new class (now, I name it - * **BaseServer**) extending the **BaseSystem** and implements this interface {@link IParallelServer}. Define the - * **BaseServer** following those codes on below: - * - * - * - * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System) - * @author Jeongho Nam - */ - interface IParallelServer extends ParallelSystem { - /** - * Connect to slave server. - */ - connect(): void; - } - /** - * A driver for parallel slave server. - * - * The {@link ParallelServer} is an abstract class, derived from the {@link ParallelSystem} class, connecting to - * remote, parallel **slave** server. Extends this {@link ParallelServer} class and overrides the - * {@link createServerConnector createServerConnector()} method following which protocol the **slave** server uses. - * - * #### [Inherited] {@link ParallelSystem} - * The {@link ParallelSystem} is an abstract class represents a **slave** system in *Parallel Processing System*, - * connected with this **master** system. This {@link ParallelSystem} takes full charge of network communication with - * the remote, parallel **slave** system has connected. - * - * When a *parallel process* is requested (by {@link ParallelSystemArray.sendSegmentData} or - * {@link ParallelSystemArray.sendPieceData}), the number of pieces to be allocated to a {@link ParallelSystem} is - * turn on its {@link getPerformance performance index}. Higher {@link getPerformance performance index}, then - * more pieces are requested. The {@link getPerformance performance index} is revaluated whenever a *parallel process* - * has completed, basic on the execution time and number of pieces. You can sugguest or enforce the - * {@link getPerformance performance index} with {@link setPerformance} or {@link enforcePerformance}. - * - * - * - * - * - * #### Bridge & Proxy Pattern - * This class {@link ParallelSystem} is derived from the {@link ExternalSystem} class. Thus, you can take advantage - * of the *Bridge & Proxy Pattern* in this {@link ParallelSystem} class. If a process to request is not the - * *parallel process* (to be distrubted to all slaves), but the **exclusive process** handled in a system, then it - * may better to utilizing the *Bridge & Proxy Pattern*: - * - * The {@link ExternalSystem} class can be a *bridge* for *logical proxy*. In framework within user, - * which {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not - * important. Only interested in user's perspective is *which can be done*. - * - * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged - * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. - * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. - * - *
    - *
  • - * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring - * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. - *
  • - *
  • - * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call - * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the - * external system. - *
  • - *
  • Those strategy is called *Bridge Pattern* and *Proxy Pattern*.
  • - *
- * - * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System) - * @author Jeongho Nam - */ - abstract class ParallelServer extends ParallelSystem implements IParallelServer { - /** - * IP address of target external system to connect. - */ - protected ip: string; - /** - * Port number of target external system to connect. - */ - protected port: number; - /** - * Construct from parent {@link ParallelSystemArray}. - * - * @param systemArray The parent {@link ParallelSystemArray} object. - */ - constructor(systemArray: ParallelSystemArray); - /** - * Factory method creating {@link IServerConnector} object. - * - * The {@link createServerConnector createServerConnector()} is an abstract method creating - * {@link IServerConnector} object. Overrides and returns one of them, considering which protocol the slave server - * follows: - * - * - {@link ServerConnector} - * - {@link WebServerConnector} - * - {@link DedicatedWorkerServerConnector} - * - {@link SharedWorkerServerConnector} - * - * @return A newly created {@link IServerConnector} object. - */ - protected abstract createServerConnector(): protocol.IServerConnector; - /** - * @inheritdoc - */ - connect(): void; - } -} -declare namespace samchon.templates.parallel { - /** - * Master of Parallel Processing System, a client connecting to slave servers. - * - * The {@link ParallelServerArray} is an abstract class, derived from the {@link ParallelSystemArray} class, - * connecting to {@link IParallelServer parallel servers}. - * - * Extends this {@link ParallelServerArray} and overrides {@link createChild createChild()} method creating child - * {@link IParallelServer} object. After the extending and overriding, construct children {@link IParallelServer} - * objects and call the {@link connect connect()} method. - * - * #### [Inherited] {@link ParallelSystemArray} - * The {@link ParallelSystemArray} is an abstract class containing and managing remote parallel **slave** system - * drivers, {@link ParallelSystem} objects. Within framework of network, {@link ParallelSystemArray} represents your - * system, a **Master** of *Parallel Processing System* that requesting *parallel process* to slave systems and the - * children {@link ParallelSystem} objects represent the remote slave systems, who is being requested the - * *parallel processes*. - * - * When you need the **parallel process**, then call one of them: {@link sendSegmentData} or {@link sendPieceData}. - * When the **parallel process** has completed, {@link ParallelSystemArray} estimates each {@link ParallelSystem}'s - * {@link ParallelSystem.getPerformance performance index} basis on their execution time. Those performance indices - * will be reflected to the next **parallel process**, how much pieces to allocate to each {@link ParallelSystem}. - * - * - * - * - * - * #### Proxy Pattern - * This class {@link ParallelSystemArray} is derived from the {@link ExternalSystemArray} class. Thus, you can take - * advantage of the *Proxy Pattern* in the {@link ParallelSystemArray} class. If a process to request is not the - * *parallel process* (to be distrubted to all slaves), but the **exclusive process** handled in a system, then it - * may better to utilizing the *Proxy Pattern*: - * - * The {@link ExternalSystemArray} class can use *Proxy Pattern*. In framework within user, which - * {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not - * important. Only interested in user's perspective is *which can be done*. - * - * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged - * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. - * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. - * - *
    - *
  • - * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring - * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. - *
  • - *
  • - * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call - * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the - * external system. - *
  • - *
  • Those strategy is called *Proxy Pattern*.
  • - *
- * - * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System) - * @author Jeongho Nam - */ - abstract class ParallelServerArray extends ParallelSystemArray implements external.IExternalServerArray { - /** - * Default Constructor. - */ - constructor(); - /** - * @inheritdoc - */ - connect(): void; - } -} -declare namespace samchon.templates.parallel { - /** - * Mediator of Parallel Processing System, a client connecting to slave servers. - * - * The {@link ParallelServerArrayMediator} is an abstract class, derived from the {@link ParallelSystemArrayMediator} - * class, connecting to {@link IParallelServer parallel servers}. - * - * Extends this {@link ParallelServerArrayMediator} and overrides {@link createChild createChild()} method creating - * child {@link IParallelServer} object. After the extending and overriding, construct children - * {@link IParallelServer} objects and call the {@link connect connect()} method. - * - * #### [Inherited] {@link ParallelSystemArrayMediator} - * The {@link ParallelSystemArrayMediator} class be a **master** for its slave systems, and be a **slave** to its - * master system at the same time. This {@link ParallelSystemArrayMediator} be a **master **system, containing and - * managing {@link ParallelSystem} objects, which represent parallel slave systems, by extending - * {@link ParallelSystemArray} class. Also, be a **slave** system through {@link getMediator mediator} object, which is - * derived from the {@link SlaveSystem} class. - * - * As a **master**, you can specify this {@link ParallelSystemArrayMediator} class to be a master server accepting - * slave clients or a master client to connecting slave servers. Even both of them is possible. Extends one - * of them below and overrides abstract factory method(s) creating the child {@link ParallelSystem} object. - * - * - {@link ParallelClientArrayMediator}: A server accepting {@link ParallelSystem parallel clients}. - * - {@link ParallelServerArrayMediator}: A client connecting to {@link ParallelServer parallel servers}. - * - {@link ParallelServerClientArrayMediator}: Both of them. Accepts {@link ParallelSystem parallel clients} and - * connects to {@link ParallelServer parallel servers} at the same time. - * - * As a **slave**, you can specify this {@link ParallelSystemArrayMediator} to be a client slave connecting to - * master server or a server slave accepting master client by overriding the {@link createMediator} method. - * Overrides the {@link createMediator createMediator()} method and return one of them: - * - * - A client slave connecting to master server: - * - {@link MediatorClient} - * - {@link MediatorWebClient} - * - {@link MediatorSharedWorkerClient} - * - A server slave accepting master client: - * - {@link MediatorServer} - * - {@link MediatorWebServer} - * - {@link MediatorDedicatedWorkerServer} - * - {@link MediatorSharedWorkerServer} - * - * #### [Inherited] {@link ParallelSystemArray} - * The {@link ParallelSystemArray} is an abstract class containing and managing remote parallel **slave** system - * drivers, {@link ParallelSystem} objects. Within framework of network, {@link ParallelSystemArray} represents your - * system, a **Master** of *Parallel Processing System* that requesting *parallel process* to slave systems and the - * children {@link ParallelSystem} objects represent the remote slave systems, who is being requested the - * *parallel processes*. - * - * When you need the **parallel process**, then call one of them: {@link sendSegmentData} or {@link sendPieceData}. - * When the **parallel process** has completed, {@link ParallelSystemArray} estimates each {@link ParallelSystem}'s - * {@link ParallelSystem.getPerformance performance index} basis on their execution time. Those performance indices - * will be reflected to the next **parallel process**, how much pieces to allocate to each {@link ParallelSystem}. - * - * - * - * - * - * #### Proxy Pattern - * This class {@link ParallelSystemArray} is derived from the {@link ExternalSystemArray} class. Thus, you can take - * advantage of the *Proxy Pattern* in the {@link ParallelSystemArray} class. If a process to request is not the - * *parallel process* (to be distrubted to all slaves), but the **exclusive process** handled in a system, then it - * may better to utilizing the *Proxy Pattern*: - * - * The {@link ExternalSystemArray} class can use *Proxy Pattern*. In framework within user, which - * {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not - * important. Only interested in user's perspective is *which can be done*. - * - * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged - * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. - * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. - * - *
    - *
  • - * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring - * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. - *
  • - *
  • - * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call - * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the - * external system. - *
  • - *
  • Those strategy is called *Proxy Pattern*.
  • - *
- * - * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System) - * @author Jeongho Nam - */ - abstract class ParallelServerArrayMediator extends ParallelSystemArrayMediator implements external.IExternalServerArray { - /** - * Default Constructor. - */ - constructor(); - /** - * @inheritdoc - */ - connect(): void; - } -} -declare namespace samchon.templates.parallel { - /** - * Master of Parallel Processing System, be a server and client at the same time. - * - * The {@link ParallelServerClientArray} is an abstract class, derived from the {@link ParallelSystemArray} class, - * opening a server accepting {@link ParallelSystem parallel clients} and being a client connecting to - * {@link IParallelServer parallel servers} at the same time. - * - * Extends this {@link ParallelServerClientArray} and overrides below methods. After the overridings, open server - * with {@link open open()} method and connect to {@link IParallelServer parallel servers} through the - * {@link connect connect()} method. - * - * - {@link createServerBase createServerBase()} - * - {@link createExternalClient createExternalClient()} - * - {@link createExternalServer createExternalServer()} - * - * #### [Inherited] {@link ParallelSystemArray} - * The {@link ParallelSystemArray} is an abstract class containing and managing remote parallel **slave** system - * drivers, {@link ParallelSystem} objects. Within framework of network, {@link ParallelSystemArray} represents your - * system, a **Master** of *Parallel Processing System* that requesting *parallel process* to slave systems and the - * children {@link ParallelSystem} objects represent the remote slave systems, who is being requested the - * *parallel processes*. - * - * When you need the **parallel process**, then call one of them: {@link sendSegmentData} or {@link sendPieceData}. - * When the **parallel process** has completed, {@link ParallelSystemArray} estimates each {@link ParallelSystem}'s - * {@link ParallelSystem.getPerformance performance index} basis on their execution time. Those performance indices - * will be reflected to the next **parallel process**, how much pieces to allocate to each {@link ParallelSystem}. - * - * - * - * - * - * #### Proxy Pattern - * This class {@link ParallelSystemArray} is derived from the {@link ExternalSystemArray} class. Thus, you can take - * advantage of the *Proxy Pattern* in the {@link ParallelSystemArray} class. If a process to request is not the - * *parallel process* (to be distrubted to all slaves), but the **exclusive process** handled in a system, then it - * may better to utilizing the *Proxy Pattern*: - * - * The {@link ExternalSystemArray} class can use *Proxy Pattern*. In framework within user, which - * {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not - * important. Only interested in user's perspective is *which can be done*. - * - * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged - * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. - * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. - * - *
    - *
  • - * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring - * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. - *
  • - *
  • - * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call - * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the - * external system. - *
  • - *
  • Those strategy is called *Proxy Pattern*.
  • - *
- * - * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System) - * @author Jeongho Nam - */ - abstract class ParallelServerClientArray extends ParallelClientArray implements external.IExternalServerClientArray { - /** - * Default Constructor. - */ - constructor(); - /** - * Factory method of a child Entity. - * - * This method is migrated to {@link createExternalServer}. Override the {@link createExternalServer} method. - * - * @param xml An {@link XML} object represents child element, so that can identify the type of child to create. - * @return A new child Entity via {@link createExternalServer createExternalServer()}. - */ - createChild(xml: library.XML): System; - /** - * Factory method creating an {@link IParallelServer} object. - * - * @param xml An {@link XML} object represents child element, so that can identify the type of child to create. - * @return A newly created {@link IParallelServer} object. - */ - protected abstract createExternalServer(xml: library.XML): System; - /** - * @inheritdoc - */ - connect(): void; - } -} -declare namespace samchon.templates.parallel { - /** - * Mediator of Parallel Processing System, be a server and client at the same time as a **master**. - * - * The {@link ParallelServerClientArrayMediator} is an abstract class, derived from the - * {@link ParallelSystemArrayMediator} class, opening a server accepting {@link ParallelSystem parallel clients} and - * being a client connecting to {@link IParallelServer parallel servers} at the same time. - * - * Extends this {@link ParallelServerClientArrayMediator} and overrides below methods. After the overridings, open - * server with {@link open open()} method and connect to {@link IParallelServer parallel servers} through the - * {@link connect connect()} method. - * - * - {@link createServerBase createServerBase()} - * - {@link createExternalClient createExternalClient()} - * - {@link createExternalServer createExternalServer()} - * - * #### [Inherited] {@link ParallelSystemArrayMediator} - * The {@link ParallelSystemArrayMediator} class be a **master** for its slave systems, and be a **slave** to its - * master system at the same time. This {@link ParallelSystemArrayMediator} be a **master **system, containing and - * managing {@link ParallelSystem} objects, which represent parallel slave systems, by extending - * {@link ParallelSystemArray} class. Also, be a **slave** system through {@link getMediator mediator} object, which is - * derived from the {@link SlaveSystem} class. - * - * As a **master**, you can specify this {@link ParallelSystemArrayMediator} class to be a master server accepting - * slave clients or a master client to connecting slave servers. Even both of them is possible. Extends one - * of them below and overrides abstract factory method(s) creating the child {@link ParallelSystem} object. - * - * - {@link ParallelClientArrayMediator}: A server accepting {@link ParallelSystem parallel clients}. - * - {@link ParallelServerArrayMediator}: A client connecting to {@link ParallelServer parallel servers}. - * - {@link ParallelServerClientArrayMediator}: Both of them. Accepts {@link ParallelSystem parallel clients} and - * connects to {@link ParallelServer parallel servers} at the same time. - * - * As a **slave**, you can specify this {@link ParallelSystemArrayMediator} to be a client slave connecting to - * master server or a server slave accepting master client by overriding the {@link createMediator} method. - * Overrides the {@link createMediator createMediator()} method and return one of them: - * - * - A client slave connecting to master server: - * - {@link MediatorClient} - * - {@link MediatorWebClient} - * - {@link MediatorSharedWorkerClient} - * - A server slave accepting master client: - * - {@link MediatorServer} - * - {@link MediatorWebServer} - * - {@link MediatorDedicatedWorkerServer} - * - {@link MediatorSharedWorkerServer} - * - * #### [Inherited] {@link ParallelSystemArray} - * The {@link ParallelSystemArray} is an abstract class containing and managing remote parallel **slave** system - * drivers, {@link ParallelSystem} objects. Within framework of network, {@link ParallelSystemArray} represents your - * system, a **Master** of *Parallel Processing System* that requesting *parallel process* to slave systems and the - * children {@link ParallelSystem} objects represent the remote slave systems, who is being requested the - * *parallel processes*. - * - * When you need the **parallel process**, then call one of them: {@link sendSegmentData} or {@link sendPieceData}. - * When the **parallel process** has completed, {@link ParallelSystemArray} estimates each {@link ParallelSystem}'s - * {@link ParallelSystem.getPerformance performance index} basis on their execution time. Those performance indices - * will be reflected to the next **parallel process**, how much pieces to allocate to each {@link ParallelSystem}. - * - * - * - * - * - * #### Proxy Pattern - * This class {@link ParallelSystemArray} is derived from the {@link ExternalSystemArray} class. Thus, you can take - * advantage of the *Proxy Pattern* in the {@link ParallelSystemArray} class. If a process to request is not the - * *parallel process* (to be distrubted to all slaves), but the **exclusive process** handled in a system, then it - * may better to utilizing the *Proxy Pattern*: - * - * The {@link ExternalSystemArray} class can use *Proxy Pattern*. In framework within user, which - * {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not - * important. Only interested in user's perspective is *which can be done*. - * - * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged - * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. - * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. - * - *
    - *
  • - * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring - * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. - *
  • - *
  • - * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call - * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the - * external system. - *
  • - *
  • Those strategy is called *Proxy Pattern*.
  • - *
- * - * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System) - * @author Jeongho Nam - */ - abstract class ParallelServerClientArrayMediator extends ParallelClientArrayMediator implements external.IExternalServerClientArray { - /** - * Default Constructor. - */ - constructor(); - /** - * Factory method of a child Entity. - * - * This method is migrated to {@link createExternalServer}. Override the {@link createExternalServer} method. - * - * @param xml An {@link XML} object represents child element, so that can identify the type of child to create. - * @return A new child Entity via {@link createExternalServer createExternalServer()}. - */ - createChild(xml: library.XML): System; - /** - * Factory method creating an {@link IParallelServer} object. - * - * @param xml An {@link XML} object represents child element, so that can identify the type of child to create. - * @return A newly created {@link IParallelServer} object. - */ - protected abstract createExternalServer(xml: library.XML): System; - /** - * @inheritdoc - */ - connect(): void; - } -} -declare namespace samchon.templates.parallel { - /** - * History of an {@link Invoke} message. - * - * The {@link PRInvokeHistory} is a class archiving history log of an {@link Invoke} message which requests the - * *parallel process*, created whenever {@link ParallelSystemArray.sendSegmentData} or - * {@link ParallelSystemArray.sendSegmentData} is called. - * - * When the *parallel process* has completed, then {@link complete complete()} is called and the *elapsed time* is - * determined. The elapsed time is utilized for computation of {@link ParallelSystem.getPerformance performance index} - * of each {@link ParallelSystem parallel slave system}. - * - * - * - * - * - * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System) - * @author Jeongho Nam - */ - class PRInvokeHistory extends protocol.InvokeHistory { - /** - * @hidden - */ - private first; - /** - * @hidden - */ - private last; - /** - * Default Constructor. - */ - constructor(); - /** - * Construct from an {@link Invoke} message. - * - * @param invoke An {@link Invoke} message requesting a *parallel process*. - */ - constructor(invoke: protocol.Invoke); - /** - * Get initial piece's index. - * - * Returns initial piece's index in the section of requested *parallel process*. - * - * @return The initial index. - */ - getFirst(): number; - /** - * Get final piece's index. - * - * Returns initial piece's index in the section of requested *parallel process*. The range used is - * [*first*, *last*), which contains all the pieces' indices between *first* and *last*, including the piece - * pointed by index *first*, but not the piece pointed by the index *last*. - * - * @return The final index. - */ - getLast(): number; - /** - * Compute number of allocated pieces. - */ - computeSize(): number; - } -} -declare namespace samchon.templates.service { - /** - * A driver of remote client. - * - * The {@link Client} is an abstract class representing and interacting with a remote client. It deals the network - * communication with the remote client and shifts {@link Invoke} message to related {@link User} and {@link Service} - * objects. - * - * Extends this {@link Client} class and override the {@link createService} method, a factory method creating a child - * {@link Service} object. Note that, {@link Client} represents a remote client, not *an user*, a specific *web page* - * or *service*. Do not define logics about user or account information. It must be declared in the parent - * {@link User} class. Also, don't define processes of a specific a web page or service. Defines them in the child - * {@link Service} class. - * - * - * - * - * - * @handbook [Templates - Cloud Service](https://github.com/samchon/framework/wiki/TypeScript-Templates-Cloud_Service) - * @author Jeongho Nam - */ - abstract class Client implements protocol.IProtocol { - /** - * @hidden - */ - private user_; - /** - * @hidden - */ - private no_; - /** - * @hidden - */ - private communicator_; - /** - * @hidden - */ - private service_; - /** - * Construct from parent {@link User} and communicator. - * - * @param user Parent {@link User} object. - * @param driver Communicator with remote client. - */ - constructor(user: User, driver: protocol.WebClientDriver); - /** - * Default Destructor. - * - * This {@link destructor destructor()} method is called when the {@link Client} object is destructed and this - * {@link Client} object is destructed when connection with the remote client is closed or this {@link Client} - * object is {@link User.erase erased} from its parent {@link User} object. - * - * Note that, don't call this {@link destructor destructor()} method by yourself. It must be called automatically - * by those *destruction* cases. Also, if your derived {@link Client} class has something to do on the - * *destruction*, then overrides this {@link destructor destructor()} method and defines the something to do. - * Overriding this {@link destructor destructor()}, don't forget to calling ```super.destructor();``` on tail. - * - * ```typescript - * class MyUser extends protocol.service.Client - * { - * protected destructor(): void - * { - * // DO SOMETHING - * this.do_something(); - * - * // CALL SUPER.DESTRUCTOR() ON TAIL. DON'T FORGET THIS - * super.destructor(); - * } - * } - * ``` - */ - protected destructor(): void; - /** - * Factory method creating {@link Service} object. - * - * @param path Requested path. - * @return A newly created {@link Service} object or ```null```. - */ - protected abstract createService(path: string): Service; - /** - * Close connection. - */ - close(): void; - /** - * Get parent {@link User} object. - * - * Get the parent {@link User} object, who is groupping {@link Client} objects with same session id. - * - * @return The parent {@link User} object. - */ - getUser(): User; - /** - * Get child {@link Service} object. - * - * @return The child {@link Service} object. - */ - getService(): Service; - /** - * Get sequence number. - * - * Get sequence number of this {@link Client} object in the parent {@link User} object. This sequence number also - * be a *key* in the parent {@link User} object, who extended the ```std.HashMap```. - * - * @return Sequence number. - */ - getNo(): number; - /** - * Change related {@link Service} object. - * - * @param path Requested, identifier path. - */ - protected changeService(path: string): void; - /** - * Change {@link Service} to another. - * - * @param service {@link service} object to newly assigned. - */ - protected changeService(service: Service): void; - /** - * Send an {@link Invoke} message. - * - * Sends an {@link Invoke} message to remote client. - * - * @param invoke An {@link Invoke} messgae to send to remote client. - */ - sendData(invoke: protocol.Invoke): void; - /** - * Handle a replied {@link Invoke} message. - * - * The default {@link Client.replyData Client.replyData()} shifts chain to its parent {@link User} and belonged - * {@link Service} objects, by calling the the {@link User.replyData User.replyData()} and - * {@link Service.replyData Service.replyData()} methods. - * - * Note that, {@link Client} represents a remote client, not *an user*, a specific *web page* or *service*. Do not - * define logics about user or account information. It must be declared in the parent {@link User} class. Also, - * don't define processes of a specific a web page or service. Defines them in the child {@link Service} class. - * - * ```typescript - * class protocol.service.Client - * { - * public replyData(invoke: protocol.Invoke): void - * { - * // SHIFT TO PARENT USER - * // THE PARENT USER ALSO MAY SHIFT TO ITS PARENT SERVER - * this.getUser().replyData(invoke); - * - * // SHIFT TO BELOGED SERVICE - * if (this.getService() != null) - * this.getService().replyData(invoke); - * } - * } - * - * class MyClient extends protocol.service.Client - * { - * public replyData(invoke: protocol.Invoke): void - * { - * if (invoke.getListener() == "do_something_in_client_level") - * this.do_something_in_client_level(); - * else - * super.replyData(invoke); - * } - * } - * ``` - * - * @param invoke An {@link Invoke invoke} message to be handled in {@link Client} level. - */ - replyData(invoke: protocol.Invoke): void; - } -} -/** - * A system template for Cloud Service. - * - * @handbook [Templates - Cloud Service](https://github.com/samchon/framework/wiki/TypeScript-Templates-Cloud_Service) - * @author Jeongho Nam - */ -declare namespace samchon.templates.service { - /** - * A cloud server. - * - * The {@link Server} is an abstract server class, who can build a real-time cloud server, that is following the - * web-socket protocol. Extends this {@link Server} and related classes and overrides abstract methods under below. - * After the overridings, open this {@link Server cloud server} using the {@link open open()} method. - * - * - Objects in composite relationship and their factory methods - * - {@link User}: {@link Server.createUser Server.createUser()} - * - {@link Client}: {@link User.createClient User.createClient()} - * - {@link Service}: {@link Client.createService Client.createService()} - * - {@link Invoke} message chains; {@link IProtocol.replyData replyData} - * - {@link Server.replyData} - * - {@link User.replyData} - * - {@link Client.replyData} - * - {@link Service.replyData} - * - * - * - * - * - * @handbook [Templates - Cloud Service](https://github.com/samchon/framework/wiki/TypeScript-Templates-Cloud_Service) - * @author Jeongho Nam - */ - abstract class Server extends protocol.WebServer implements protocol.IProtocol { - /** - * @hidden - */ - private session_map_; - /** - * @hidden - */ - private account_map_; - /** - * Default Constructor. - */ - constructor(); - /** - * Factory method creating {@link User} object. - * - * @return A newly created {@link User} object. - */ - protected abstract createUser(): User; - /** - * Test wheter an {@link User} exists with the *accountID*. - * - * @param accountID Account id of {@link User} to find. - * @return Exists or not. - */ - has(accountID: string): boolean; - /** - * Get an {@link User} object by its *accountID*. - * - * @param accountID Account id of {@link User} to get. - * @return An {@link User} object. - */ - get(accountID: string): User; - /** - * Send an {@link Invoke} message. - * - * Sends an {@link Invoke} message to all remote clients through the belonged {@link User} and {@link Client} - * objects. Sending the {@link Invoke} message to all remote clients, it's came true by passing through - * {@link User.sendData User.sendData()}. And the {@link User.sendData} also pass through the - * {@link Client.sendData Client.sendData()}. - * - * ```typescript - * class protocol.service.Server - * { - * public sendData(invoke: Invoke): void - * { - * for (user: User in this) - * for (client: Client in user) - * client.sendData(invoke); - * } - * } - * ``` - * - * @param invoke {@link Invoke} message to send to all remote clients. - */ - sendData(invoke: protocol.Invoke): void; - /** - * Handle a replied {@link Invoke} message. - * - * The {@link Server.replyData Server.replyData()} is an abstract method that handling {@link Invoke} message - * that should be handled in the {@link Server} level. Overrides this {@link replyData replyData()} method and - * defines what to do with the {@link Invoke} message in this {@link Server} level. - * - * @param invoke An {@link Invoke invoke} message to be handled in {@link Server} level. - */ - abstract replyData(invoke: protocol.Invoke): void; - /** - * Add a newly connected remote client. - * - * When a {@link WebClientDriver remote client} connects to this cloud server, then {@link Server} queries the - * {WebClientDriver.getSessionID session id} of the {@link WebClientDriver remote client}. If the - * {WebClientDriver.getSessionID session id} is new one, then creates a new {@link User} object. - * - * At next, creates a {@link Client} object who represents the newly connected remote client and insert the - * {@link Client} object to the matched {@link User} object which is new or ordinary one following the - * {WebClientDriver.getSessionID session id}. At last, a {@link Service} object can be created with referencing - * the {@link WebClientDriver.getPath path}. - * - * List of objects can be created by this method. - * - {@link User} by {@link createUser createUser()}. - * - {@link Client} by {@link User.createClient User.createClient()}. - * - {@link Service} by {@link Client.createService Client.createService()}. - * - * @param driver A web communicator for remote client. - */ - addClient(driver: protocol.WebClientDriver): void; - /** - * @hidden - */ - private erase_user(user); - } -} -declare namespace samchon.templates.service { - /** - * A service. - * - * The {@link Service} is an abstract class who represents a service, that is providing functions a specific page. - * - * Extends the {@link Service} class and defines its own service, which to be provided for the specific weg page, - * by overriding the {@link replyData replyData()} method. Note that, the service, functions for the specific page - * should be defined in this {@link Service} class, not its parent {@link Client} class who represents a remote client - * and takes communication responsibility. - * - * - * - * - * - * @handbook [Templates - Cloud Service](https://github.com/samchon/framework/wiki/TypeScript-Templates-Cloud_Service) - * @author Jeongho Nam - */ - abstract class Service implements protocol.IProtocol { - /** - * @hidden - */ - private client_; - /** - * @hidden - */ - private path_; - /** - * Construct from parent {@link Client} and requested path. - * - * @param client Driver of remote client. - * @param path Requested path that identifies this {@link Service}. - */ - constructor(client: Client, path: string); - /** - * Default Destructor. - * - * This {@link destructor destructor()} method is call when the {@link Service} object is destructed and the - * {@link Service} object is destructed when its parent {@link Client} object has - * {@link Client.destructor destructed} or the {@link Client} object {@link Client.changeService changed} its - * child {@link Service service} object to another one. - * - * Note that, don't call this {@link destructor destructor()} method by yourself. It must be called automatically - * by those *destruction* cases. Also, if your derived {@link Service} class has something to do on the - * *destruction*, then overrides this {@link destructor destructor()} method and defines the something to do. - */ - protected destructor(): void; - /** - * Get client. - */ - getClient(): Client; - /** - * Get requested path. - */ - getPath(): string; - /** - * Send an {@link Invoke} message. - * - * Sends an {@link Invoke} message to remote system through parent {@link Client} object ({@link Client.sendData}). - * - * @param invoke An {@link Invoke} message to send to the remte system. - */ - sendData(invoke: protocol.Invoke): void; - /** - * @inheritdoc - */ - abstract replyData(invoke: protocol.Invoke): void; - } -} -declare namespace samchon.templates.service { - /** - * An user. - * - * The {@link User} is an abstract class groupping {@link Client} objects, who communicates with remote client, with - * same *session id*. This {@link User} represents a *remote user* literally. Within framework of remote system, - * an {@link User} corresponds to a web-browser and a {@link Client} represents a window in the web-browser. - * - * Extends this {@link User} class and override the {@link createClient} method, a factory method creating a child - * {@link Client} object. I repeat, the {@link User} class represents a *remote user*, groupping {@link Client} - * objects with same *session id*. If your cloud server has some processes to be handled in the **user level**, then - * defines method in this {@link User} class. Methods managing **account** under below are some of them: - * - * - {@link setAccount setAccount()} - * - {@link getAccountID getAccountID()} - * - {@link getAuthority getAuthority()} - * - * The children {@link Client} objects, they're contained with their key, the {@link Client.getNo sequence number}. - * If you {@link User.erase erase} the children {@link Client} object by yourself, then their connection with the - * remote clients will be {@link Client.close closed} and their {@link Client.destructor destruction method} will be - * called. If you remove {@link clear all children}, then this {@link User} object will be also - * {@link destructor destructed} and erased from the parent {@link Server} object. - * - * - * - * - * - * @handbook [Templates - Cloud Service](https://github.com/samchon/framework/wiki/TypeScript-Templates-Cloud_Service) - * @author Jeongho Nam - */ - abstract class User extends collections.HashMapCollection implements protocol.IProtocol { - /** - * @hidden - */ - private server_; - /** - * @hidden - */ - private session_id_; - /** - * @hidden - */ - private sequence_; - /** - * @hidden - */ - private account_id_; - /** - * @hidden - */ - private authority_; - /** - * Construct from its parent {@link Server}. - * - * @param server The parent {@link Server} object. - */ - constructor(server: Server); - /** - * Default Destructor. - * - * This {@link destructor destructor()} method is called when the {@link User} object is destructed. The - * {@link User} object is destructed when connections with the remote clients are all closed, that is all the - * children {@link Client} objects are all removed, and 30 seconds has left. If some remote client connects - * within the 30 seconds, then the {@link User} object doesn't be destructed. - * - * Note that, don't call this {@link destructor destructor()} method by yourself. It must be called automatically - * by those *destruction* cases. Also, if your derived {@link User} class has something to do on the - * *destruction*, then overrides this {@link destructor destructor()} method and defines the something to do. - * Overriding this {@link destructor destructor()}, don't forget to calling ```super.destructor();``` on tail. - * - * ```typescript - * class MyUser extends protocol.service.User - * { - * protected destructor(): void - * { - * // DO SOMETHING - * this.do_something(); - * - * // CALL SUPER.DESTRUCTOR() ON TAIL. DON'T FORGET THIS - * super.destructor(); - * } - * } - * ``` - */ - protected destructor(): void; - /** - * Factory method creating a {@link Client} object. - * - * @param driver A web communicator for remote client. - * @return A newly created {@link Client} object. - */ - protected abstract createClient(driver: protocol.WebClientDriver): Client; - /** - * @hidden - */ - private handle_erase_client(event); - /** - * Get parent {@lin Server} object. - * - * @return Parent {@link Server} object. - */ - getServer(): Server; - /** - * Get account id. - * - * @return Account ID. - */ - getAccountID(): string; - /** - * Get authority. - * - * @return Authority - */ - getAuthority(): number; - /** - * Set *account id* and *authority*. - * - * The {@link setAccount setAccount()} is a method configuring *account id* and *authority* of this {@link User}. - * - * After the configuring, the {@link getAccountID account id} is enrolled into the parent {@link Server} as a - * **key** for this {@link User} object. You can test existence and access this {@link User} object from - * {@link Server.has Server.has()} and {@link Server.get Server.get()} with the {@link getAccountID account id}. - * Of course, if ordinary {@link getAccountID account id} had existed, then the ordinary **key** will be - * replaced. - * - * As you suggest, this {@link setAccount setAccount()} is something like a **log-in** function. If what you want - * is not **logging-in**, but **logging-out**, then configure the *account id* to empty string ``""```` or call - * the {@link lgout logout()} method. - * - * @param id To be account id. - * @param authority To be authority. - */ - setAccount(id: string, authority: number): void; - /** - * Log-out. - * - * This {@link logout logout()} method configures {@link getAccountID account id} to empty string and - * {@link getAuthority authority} to zero. - * - * The ordinary {@link getAccountID account id} will be also erased from the parent {@link Server} object. You - * can't access this {@link User} object from {@link Server.has Server.has()} and {@link Server.get Server.get()} - * with the ordinary {@link getAccountID account id} more. - */ - logout(): void; - /** - * Send an {@link Invoke} message. - * - * Sends an {@link Invoke} message to all remote clients through the belonged {@link Client} objects. Sending the - * {@link Invoke} message to all remote clients, it's came true by passing through the - * {@link Client.sendData Client.sendData()} methods. - * - * ```typescript - * class protocol.service.User - * { - * public sendData(invoke: Invoke): void - * { - * for (let it = this.begin(); !it.equal_to(this.end()); it = it.next()) - * it.second.sendData(invoke); - * } - * } - * ``` - * - * @param invoke {@link Invoke} message to send to all remote clients. - */ - sendData(invoke: protocol.Invoke): void; - /** - * Handle a replied {@link Invoke} message. - * - * The default {@link User.replyData User.replyData()} shifts chain to its parent {@link Server} object, by - * calling the {@link Server.replyData Server.replyData()} method. If there're some {@link Invoke} message to be - * handled in this {@link User} level, then override this method and defines what to do with the {@link Invoke} - * message in this {@link User} level. - * - * ```typescript - * class protocol.service.User - * { - * public replyData(invoke: protocol.Invoke): void - * { - * this.getServer().replyData(invoke); - * } - * } - * - * class MyUser extends protocol.service.User - * { - * public replyData(invoke: protocol.Invoke): void - * { - * if (invoke.apply(this) == false) // IS TARGET TO BE HANDLED IN THIS USER LEVEL - * super.replyData(invoke); // SHIFT TO SERVER - * } - * } - * ``` - * - * @param invoke An {@link Invoke invoke} message to be handled in {@link User} level. - */ - replyData(invoke: protocol.Invoke): void; - } -} -declare namespace samchon.templates.slave { - interface ISlaveClient extends SlaveSystem { - connect(ip: string, port: number): void; - } - abstract class SlaveClient extends SlaveSystem implements ISlaveClient { - /** - * Default Constructor. - */ - constructor(); - /** - * @inheritdoc - */ - protected abstract createServerConnector(): protocol.IServerConnector; - /** - * @inheritdoc - */ - connect(ip: string, port: number): void; - } -} -declare namespace samchon.templates.slave { - interface ISlaveServer extends SlaveSystem, protocol.IServer { - } - abstract class SlaveServer extends SlaveSystem implements ISlaveServer { - private server_base_; - constructor(); - protected abstract createServerBase(): protocol.IServerBase; - open(port: number): void; - close(): void; - addClient(driver: protocol.IClientDriver): void; - } -} +} \ No newline at end of file diff --git a/samchon/index.d.ts b/samchon/index.d.ts new file mode 100644 index 0000000000..6f2bc17b43 --- /dev/null +++ b/samchon/index.d.ts @@ -0,0 +1,8403 @@ +// Type definitions for Samchon Framework v2.0.7 +// Project: https://github.com/samchon/framework +// Definitions by: Jeongho Nam +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare module "samchon" +{ + export = samchon; +} + +/** + * # Samchon Framework + * + * + * + * + * Samchon, a OON (Object-Oriented Network) framework. + * + * With Samchon Framework, you can implement distributed processing system within framework of OOD like handling S/W + * objects (classes). You can realize cloud and distributed system very easily with provided system templates and even + * integration with C++ is possible. + * + * The goal, ultimate utilization model of Samchon Framework is, building cloud system with NodeJS and taking heavy works + * to C++ distributed systems with provided modules (those are system templates). + * + * @git https://github.com/samchon/framework + * @author Jeongho Nam + */ +declare namespace samchon { +} +declare namespace samchon.collections { + /** + * A {@link Vector} who can detect element I/O events. + * + * Below is the list of methods who are dispatching {@link CollectionEvent}: + * - *insert* typed events: + * - {@link assign} + * - {@link insert} + * - {@link push} + * - {@link push_back} + * - *erase* typed events: + * - {@link assign} + * - {@link clear} + * - {@link erase} + * - {@link pop_back} + * - *refresh* typed events: + * - {@link refresh} + * + * #### [Inherited] {@link Vector} + * @copydoc Vector + */ + class ArrayCollection extends std.Vector implements ICollection { + /** + * @hidden + */ + private event_dispatcher_; + /** + * @inheritdoc + */ + push(...items: T[]): number; + /** + * @inheritdoc + */ + push_back(val: T): void; + /** + * @hidden + */ + protected _Insert_by_range>(position: std.VectorIterator, begin: InputIterator, end: InputIterator): std.VectorIterator; + /** + * @hidden + */ + protected _Erase_by_range(first: std.VectorIterator, last: std.VectorIterator): std.VectorIterator; + /** + * @hidden + */ + private _Notify_insert(first, last); + /** + * @hidden + */ + private _Notify_erase(first, last); + /** + * @inheritdoc + */ + hasEventListener(type: string): boolean; + /** + * @inheritdoc + */ + dispatchEvent(event: library.BasicEvent): boolean; + /** + * @inheritdoc + */ + refresh(): void; + /** + * @inheritdoc + */ + refresh(it: std.VectorIterator): void; + /** + * @inheritdoc + */ + refresh(first: std.VectorIterator, last: std.VectorIterator): void; + /** + * @inheritdoc + */ + addEventListener(type: string, listener: library.BasicEventListener): void; + addEventListener(type: "insert", listener: CollectionEventListener): void; + addEventListener(type: "erase", listener: CollectionEventListener): void; + addEventListener(type: "refresh", listener: CollectionEventListener): void; + /** + * @inheritdoc + */ + addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + addEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; + addEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; + addEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; + /** + * @inheritdoc + */ + removeEventListener(type: string, listener: library.BasicEventListener): void; + removeEventListener(type: "insert", listener: CollectionEventListener): void; + removeEventListener(type: "erase", listener: CollectionEventListener): void; + removeEventListener(type: "refresh", listener: CollectionEventListener): void; + /** + * @inheritdoc + */ + removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + removeEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; + removeEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; + removeEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; + } +} +declare namespace samchon.library { + /** + * A basic event class of Samchon Framework. + * + * @reference https://developer.mozilla.org/en-US/docs/Web/API/Event + * @handbook https://github.com/samchon/framework/wiki/TypeScript-Library-EventDispatcher + * @author Jeongho Nam + */ + class BasicEvent { + protected type_: string; + protected target_: IEventDispatcher; + private currentTarget_; + protected trusted_: boolean; + protected bubbles_: boolean; + protected cancelable_: boolean; + protected defaultPrevented_: boolean; + protected cancelBubble_: boolean; + private timeStamp_; + constructor(type: string, bubbles?: boolean, cancelable?: boolean); + /** + * @inheritdoc + */ + initEvent(type: string, bubbles: boolean, cancelable: boolean): void; + /** + * @inheritdoc + */ + /** + * @inheritdoc + */ + stopImmediatePropagation(): void; + /** + * @inheritdoc + */ + stopPropagation(): void; + /** + * @inheritdoc + */ + readonly type: string; + /** + * @inheritdoc + */ + target: IEventDispatcher; + /** + * @inheritdoc + */ + readonly currentTarget: IEventDispatcher; + /** + * @inheritdoc + */ + readonly bubbles: boolean; + /** + * @inheritdoc + */ + readonly cancelable: boolean; + /** + * @inheritdoc + */ + readonly eventPhase: number; + /** + * @inheritdoc + */ + readonly defaultPrevented: boolean; + /** + * @inheritdoc + */ + readonly srcElement: Element; + /** + * @inheritdoc + */ + readonly cancelBubble: boolean; + /** + * @inheritdoc + */ + readonly timeStamp: number; + /** + * Don't know what it is. + */ + readonly returnValue: boolean; + } +} +declare namespace samchon.collections { + /** + * Type of function pointer for listener of {@link CollectionEvent CollectionEvents}. + */ + type CollectionEventListener = (event: CollectionEvent) => void; +} +declare namespace samchon.collections { + /** + * An event occured in a {@link ICollection collection} object. + * + * @handbook [Collections](https://github.com/samchon/framework/wiki/TypeScript-STL#collections) + * @author Jeongho Nam + */ + class CollectionEvent extends library.BasicEvent { + /** + * @hidden + */ + private first_; + /** + * @hidden + */ + private last_; + /** + * @hidden + */ + private temporary_container_; + /** + * @hidden + */ + private origin_first_; + /** + * Initialization Constructor. + * + * @param type Type of collection event. + * @param first An {@link Iterator} to the initial position in this {@link CollectionEvent}. + * @param last An {@link Iterator} to the final position in this {@link CollectionEvent}. + */ + constructor(type: string, first: std.Iterator, last: std.Iterator); + constructor(type: "insert", first: std.Iterator, last: std.Iterator); + constructor(type: "erase", first: std.Iterator, last: std.Iterator); + constructor(type: "refresh", first: std.Iterator, last: std.Iterator); + /** + * Associative target, the {@link ICollection collection}. + */ + readonly target: ICollection; + /** + * An {@link Iterator} to the initial position in this {@link CollectionEvent}. + */ + readonly first: std.Iterator; + /** + * An {@link Iterator} to the final position in this {@link CollectionEvent}. + */ + readonly last: std.Iterator; + /** + * @inheritdoc + */ + preventDefault(): void; + } +} +declare namespace samchon.collections.CollectionEvent { + const INSERT: "insert"; + const ERASE: "erase"; + const REFRESH: "refresh"; +} +declare namespace samchon.collections { + /** + * A {@link Deque} who can detect element I/O events. + * + * Below is the list of methods who are dispatching {@link CollectionEvent}: + * - *insert* typed events: + * - {@link assign} + * - {@link insert} + * - {@link push} + * - {@link push_front} + * - {@link push_back} + * - *erase* typed events: + * - {@link assign} + * - {@link clear} + * - {@link erase} + * - {@link pop_front} + * - {@link pop_back} + * - *refresh* typed events: + * - {@link refresh} + * + * #### [Inherited] {@link Deque} + * @copydoc Deque + */ + class DequeCollection extends std.Deque implements ICollection { + /** + * @hidden + */ + private event_dispatcher_; + /** + * @inheritdoc + */ + push_front(val: T): void; + /** + * @inheritdoc + */ + push_back(val: T): void; + /** + * @hidden + */ + protected _Insert_by_range>(position: std.DequeIterator, begin: InputIterator, end: InputIterator): std.DequeIterator; + /** + * @inheritdoc + */ + pop_front(): void; + /** + * @inheritdoc + */ + pop_back(): void; + /** + * @hidden + */ + protected _Erase_by_range(first: std.DequeIterator, last: std.DequeIterator): std.DequeIterator; + /** + * @hidden + */ + private _Notify_insert(first, last); + /** + * @hidden + */ + private _Notify_erase(first, last); + /** + * @inheritdoc + */ + hasEventListener(type: string): boolean; + /** + * @inheritdoc + */ + dispatchEvent(event: library.BasicEvent): boolean; + /** + * @inheritdoc + */ + refresh(): void; + /** + * @inheritdoc + */ + refresh(it: std.DequeIterator): void; + /** + * @inheritdoc + */ + refresh(first: std.DequeIterator, last: std.DequeIterator): void; + /** + * @inheritdoc + */ + addEventListener(type: string, listener: library.BasicEventListener): void; + addEventListener(type: "insert", listener: CollectionEventListener): void; + addEventListener(type: "erase", listener: CollectionEventListener): void; + addEventListener(type: "refresh", listener: CollectionEventListener): void; + /** + * @inheritdoc + */ + addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + addEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; + addEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; + addEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; + /** + * @inheritdoc + */ + removeEventListener(type: string, listener: library.BasicEventListener): void; + removeEventListener(type: "insert", listener: CollectionEventListener): void; + removeEventListener(type: "erase", listener: CollectionEventListener): void; + removeEventListener(type: "refresh", listener: CollectionEventListener): void; + /** + * @inheritdoc + */ + removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + removeEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; + removeEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; + removeEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; + } +} +declare namespace samchon.collections { + /** + * A {@link HashMap} who can detect element I/O events. + * + * Below is the list of methods who are dispatching {@link MapCollectionEvent}: + * - *insert* typed events: + * - {@link assign} + * - {@link insert} + * - {@link insert_or_assign} + * - {@link emplace} + * - {@link set} + * - {@link push} + * - *erase* typed events: + * - {@link assign} + * - {@link clear} + * - {@link erase} + * - {@link extract} + * - *refresh* typed events: + * - {@link refresh} + * + * #### [Inherited] {@link HashMap} + * @copydoc HashMap + */ + class HashMapCollection extends std.HashMap implements ICollection> { + /** + * @hidden + */ + private event_dispatcher_; + /** + * @hidden + */ + protected _Handle_insert(first: std.MapIterator, last: std.MapIterator): void; + /** + * @hidden + */ + protected _Handle_erase(first: std.MapIterator, last: std.MapIterator): void; + /** + * @inheritdoc + */ + hasEventListener(type: string): boolean; + /** + * @inheritdoc + */ + dispatchEvent(event: library.BasicEvent): boolean; + /** + * @inheritdoc + */ + refresh(): void; + /** + * @inheritdoc + */ + refresh(it: std.MapIterator): void; + /** + * @inheritdoc + */ + refresh(first: std.MapIterator, last: std.MapIterator): void; + /** + * @inheritdoc + */ + addEventListener(type: string, listener: library.BasicEventListener): void; + addEventListener(type: "insert", listener: MapCollectionEventListener): void; + addEventListener(type: "erase", listener: MapCollectionEventListener): void; + addEventListener(type: "refresh", listener: MapCollectionEventListener): void; + /** + * @inheritdoc + */ + addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + addEventListener(type: "insert", listener: MapCollectionEventListener, thisArg: Object): void; + addEventListener(type: "erase", listener: MapCollectionEventListener, thisArg: Object): void; + addEventListener(type: "refresh", listener: MapCollectionEventListener, thisArg: Object): void; + /** + * @inheritdoc + */ + removeEventListener(type: string, listener: library.BasicEventListener): void; + removeEventListener(type: "insert", listener: MapCollectionEventListener): void; + removeEventListener(type: "erase", listener: MapCollectionEventListener): void; + removeEventListener(type: "refresh", listener: MapCollectionEventListener): void; + /** + * @inheritdoc + */ + removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + removeEventListener(type: "insert", listener: MapCollectionEventListener, thisArg: Object): void; + removeEventListener(type: "erase", listener: MapCollectionEventListener, thisArg: Object): void; + removeEventListener(type: "refresh", listener: MapCollectionEventListener, thisArg: Object): void; + } +} +declare namespace samchon.collections { + /** + * A {@link HashMultiMap} who can detect element I/O events. + * + * Below is the list of methods who are dispatching {@link MapCollectionEvent}: + * - *insert* typed events: + * - {@link assign} + * - {@link insert} + * - {@link emplace} + * - {@link push} + * - *erase* typed events: + * - {@link assign} + * - {@link clear} + * - {@link erase} + * - *refresh* typed events: + * - {@link refresh} + * + * #### [Inherited] {@link HashMultiMap} + * @copydoc HashMultiMap + */ + class HashMultiMapCollection extends std.HashMultiMap implements ICollection> { + /** + * @hidden + */ + private event_dispatcher_; + /** + * @hidden + */ + protected _Handle_insert(first: std.MapIterator, last: std.MapIterator): void; + /** + * @hidden + */ + protected _Handle_erase(first: std.MapIterator, last: std.MapIterator): void; + /** + * @inheritdoc + */ + hasEventListener(type: string): boolean; + /** + * @inheritdoc + */ + dispatchEvent(event: library.BasicEvent): boolean; + /** + * @inheritdoc + */ + refresh(): void; + /** + * @inheritdoc + */ + refresh(it: std.MapIterator): void; + /** + * @inheritdoc + */ + refresh(first: std.MapIterator, last: std.MapIterator): void; + /** + * @inheritdoc + */ + addEventListener(type: string, listener: library.BasicEventListener): void; + addEventListener(type: "insert", listener: MapCollectionEventListener): void; + addEventListener(type: "erase", listener: MapCollectionEventListener): void; + addEventListener(type: "refresh", listener: MapCollectionEventListener): void; + /** + * @inheritdoc + */ + addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + addEventListener(type: "insert", listener: MapCollectionEventListener, thisArg: Object): void; + addEventListener(type: "erase", listener: MapCollectionEventListener, thisArg: Object): void; + addEventListener(type: "refresh", listener: MapCollectionEventListener, thisArg: Object): void; + /** + * @inheritdoc + */ + removeEventListener(type: string, listener: library.BasicEventListener): void; + removeEventListener(type: "insert", listener: MapCollectionEventListener): void; + removeEventListener(type: "erase", listener: MapCollectionEventListener): void; + removeEventListener(type: "refresh", listener: MapCollectionEventListener): void; + /** + * @inheritdoc + */ + removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + removeEventListener(type: "insert", listener: MapCollectionEventListener, thisArg: Object): void; + removeEventListener(type: "erase", listener: MapCollectionEventListener, thisArg: Object): void; + removeEventListener(type: "refresh", listener: MapCollectionEventListener, thisArg: Object): void; + } +} +declare namespace samchon.collections { + /** + * A {@link HashMultiSet} who can detect element I/O events. + * + * Below is the list of methods who are dispatching {@link CollectionEvent}: + * - *insert* typed events: + * - {@link assign} + * - {@link insert} + * - {@link push} + * - *erase* typed events: + * - {@link assign} + * - {@link clear} + * - {@link erase} + * - *refresh* typed events: + * - {@link refresh} + * + * #### [Inherited] {@link HashMultiSet} + * @copydoc HashMultiSet + */ + class HashMultiSetCollection extends std.HashMultiSet implements ICollection { + /** + * @hidden + */ + private event_dispatcher_; + /** + * @hidden + */ + protected _Handle_insert(first: std.SetIterator, last: std.SetIterator): void; + /** + * @hidden + */ + protected _Handle_erase(first: std.SetIterator, last: std.SetIterator): void; + /** + * @inheritdoc + */ + hasEventListener(type: string): boolean; + /** + * @inheritdoc + */ + dispatchEvent(event: library.BasicEvent): boolean; + /** + * @inheritdoc + */ + refresh(): void; + /** + * @inheritdoc + */ + refresh(it: std.SetIterator): void; + /** + * @inheritdoc + */ + refresh(first: std.SetIterator, last: std.SetIterator): void; + /** + * @inheritdoc + */ + addEventListener(type: string, listener: library.BasicEventListener): void; + addEventListener(type: "insert", listener: CollectionEventListener): void; + addEventListener(type: "erase", listener: CollectionEventListener): void; + addEventListener(type: "refresh", listener: CollectionEventListener): void; + /** + * @inheritdoc + */ + addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + addEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; + addEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; + addEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; + /** + * @inheritdoc + */ + removeEventListener(type: string, listener: library.BasicEventListener): void; + removeEventListener(type: "insert", listener: CollectionEventListener): void; + removeEventListener(type: "erase", listener: CollectionEventListener): void; + removeEventListener(type: "refresh", listener: CollectionEventListener): void; + /** + * @inheritdoc + */ + removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + removeEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; + removeEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; + removeEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; + } +} +declare namespace samchon.collections { + /** + * A {@link HashSet} who can detect element I/O events. + * + * Below is the list of methods who are dispatching {@link CollectionEvent}: + * - *insert* typed events: + * - {@link assign} + * - {@link insert} + * - {@link push} + * - {@link insert_or_assign} + * - *erase* typed events: + * - {@link assign} + * - {@link clear} + * - {@link erase} + * - {@link extract} + * - *refresh* typed events: + * - {@link refresh} + * + * #### [Inherited] {@link HashSet} + * @copydoc HashSet + */ + class HashSetCollection extends std.HashSet implements ICollection { + /** + * @hidden + */ + private event_dispatcher_; + /** + * @hidden + */ + protected _Handle_insert(first: std.SetIterator, last: std.SetIterator): void; + /** + * @hidden + */ + protected _Handle_erase(first: std.SetIterator, last: std.SetIterator): void; + /** + * @inheritdoc + */ + hasEventListener(type: string): boolean; + /** + * @inheritdoc + */ + dispatchEvent(event: library.BasicEvent): boolean; + /** + * @inheritdoc + */ + refresh(): void; + /** + * @inheritdoc + */ + refresh(it: std.SetIterator): void; + /** + * @inheritdoc + */ + refresh(first: std.SetIterator, last: std.SetIterator): void; + /** + * @inheritdoc + */ + addEventListener(type: string, listener: library.BasicEventListener): void; + addEventListener(type: "insert", listener: CollectionEventListener): void; + addEventListener(type: "erase", listener: CollectionEventListener): void; + addEventListener(type: "refresh", listener: CollectionEventListener): void; + /** + * @inheritdoc + */ + addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + addEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; + addEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; + addEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; + /** + * @inheritdoc + */ + removeEventListener(type: string, listener: library.BasicEventListener): void; + removeEventListener(type: "insert", listener: CollectionEventListener): void; + removeEventListener(type: "erase", listener: CollectionEventListener): void; + removeEventListener(type: "refresh", listener: CollectionEventListener): void; + /** + * @inheritdoc + */ + removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + removeEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; + removeEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; + removeEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; + } +} +/** + * Collections, elements I/O detectable STL containers. + * + * STL Containers | Collections + * ---------------------|------------------- + * {@link Vector} | {@link ArrayCollection} + * {@link List} | {@link ListCollection} + * {@link Deque} | {@link DequeCollection} + * | + * {@link TreeSet} | {@link TreeSetCollection} + * {@link HashSet} | {@link HashSetCollection} + * {@link TreeMultiSet} | {@link TreeMultiSetCollection} + * {@link HashMultiSet} | {@link HashMultiSetCollection} + * | + * {@link TreeMap} | {@link TreeMapCollection} + * {@link HashMap} | {@link HashMapCollection} + * {@link TreeMultiMap} | {@link TreeMultiMapCollection} + * {@link HashMultiMap} | {@link HashMultiMapCollection} + * + * @author Jeongho Nam + */ +declare namespace samchon.collections { + /** + * An interface for {@link IContainer containers} who can detect element I/O events. + * + * Below are list of methods who are dispatching {@link CollectionEvent}: + * - *insert* typed events: + * - {@link assign} + * - {@link insert} + * - {@link push} + * - *erase* typed events: + * - {@link assign} + * - {@link clear} + * - {@link erase} + * - *refresh* typed events: + * - {@link refresh} + * + * @author Jeongho Nam + */ + interface ICollection extends std.base.Container, library.IEventDispatcher { + /** + * Dispatch a {@link CollectionEvent} with *refresh* typed. + * + * {@link ICollection} dispatches {@link CollectionEvent} typed *insert* or *erase* whenever elements I/O has + * occured. However, unlike those elements I/O events, content change in element level can't be detected. + * There's no way to detect those events automatically by {@link IContainer}. + * + * If you want to dispatch those typed events (notifying change on contents in element level), you've to + * dispatch *refresh* typed event manually, by yourself. Call {@link refresh refresh()} with specified + * iterators who're pointing the elements whose content have changed. Then a {@link CollectionEvent} with + * *refresh* typed will be dispatched. + * + * If you don't specify any iterator, then the range of the *refresh* event will be all elements in this + * {@link ICollection collection}; {@link begin begin()} to {@link end end()}. + */ + refresh(): void; + /** + * Dispatch a {@link CollectionEvent} with *refresh* typed. + * + * {@link ICollection} dispatches {@link CollectionEvent} typed *insert* or *erase* whenever elements I/O has + * occured. However, unlike those elements I/O events, content change in element level can't be detected. + * There's no way to detect those events automatically by {@link IContainer}. + * + * If you want to dispatch those typed events (notifying change on contents in element level), you've to + * dispatch *refresh* typed event manually, by yourself. Call {@link refresh refresh()} with specified + * iterators who're pointing the elements whose content have changed. Then a {@link CollectionEvent} with + * *refresh* typed will be dispatched. + * + * @param it An iterator targeting the content changed element. + */ + refresh(it: std.Iterator): void; + /** + * Dispatch a {@link CollectionEvent} with *refresh* typed. + * + * {@link ICollection} dispatches {@link CollectionEvent} typed *insert* or *erase* whenever elements I/O has + * occured. However, unlike those elements I/O events, content change in element level can't be detected. + * There's no way to detect those events automatically by {@link IContainer}. + * + * If you want to dispatch those typed events (notifying change on contents in element level), you've to + * dispatch *refresh* typed event manually, by yourself. Call {@link refresh refresh()} with specified + * iterators who're pointing the elements whose content have changed. Then a {@link CollectionEvent} with + * *refresh* typed will be dispatched. + * + * @param first An Iterator to the initial position in a sequence of the content changed elmeents. + * @param last An {@link Iterator} to the final position in a sequence of the content changed elements. The range + * used is [*first*, *last*), which contains all the elements between *first* and + * *last*, including the element pointed by *first* but not the element pointed by + * *last*. + */ + refresh(first: std.Iterator, last: std.Iterator): void; + /** + * @inheritdoc + */ + addEventListener(type: string, listener: library.BasicEventListener): void; + addEventListener(type: "insert", listener: CollectionEventListener): void; + addEventListener(type: "erase", listener: CollectionEventListener): void; + addEventListener(type: "refresh", listener: CollectionEventListener): void; + /** + * @inheritdoc + */ + addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + addEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; + addEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; + addEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; + /** + * @inheritdoc + */ + removeEventListener(type: string, listener: library.BasicEventListener): void; + removeEventListener(type: "insert", listener: CollectionEventListener): void; + removeEventListener(type: "erase", listener: CollectionEventListener): void; + removeEventListener(type: "refresh", listener: CollectionEventListener): void; + /** + * @inheritdoc + */ + removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + removeEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; + removeEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; + removeEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; + } + /** + * @hidden + */ + namespace ICollection { + /** + * @hidden + */ + function _Dispatch_CollectionEvent(collection: ICollection, type: string, first: std.Iterator, last: std.Iterator): void; + /** + * @hidden + */ + function _Dispatch_MapCollectionEvent(collection: ICollection>, type: string, first: std.MapIterator, last: std.MapIterator): void; + } +} +declare namespace samchon.collections { + /** + * A {@link List} who can detect element I/O events. + * + * Below is the list of methods who are dispatching {@link CollectionEvent}: + * - *insert* typed events: + * - {@link assign} + * - {@link insert} + * - {@link push} + * - {@link push_front} + * - {@link push_back} + * - {@link merge} + * - *erase* typed events: + * - {@link assign} + * - {@link clear} + * - {@link erase} + * - {@link pop_front} + * - {@link pop_back} + * - {@link unique} + * - {@link remove} + * - {@link remove_if} + * - {@link splice} + * - *refresh* typed events: + * - {@link refresh} + * - {@link sort} + * + * #### [Inherited] {@link List} + * @copydoc List + */ + class ListCollection extends std.List implements ICollection { + /** + * @hidden + */ + private event_dispatcher_; + /** + * @hidden + */ + protected _Insert_by_range>(position: std.ListIterator, begin: InputIterator, end: InputIterator): std.ListIterator; + /** + * @hidden + */ + protected _Erase_by_range(first: std.ListIterator, last: std.ListIterator): std.ListIterator; + /** + * @hidden + */ + private _Notify_insert(first, last); + /** + * @hidden + */ + private _Notify_erase(first, last); + /** + * @inheritdoc + */ + hasEventListener(type: string): boolean; + /** + * @inheritdoc + */ + dispatchEvent(event: library.BasicEvent): boolean; + /** + * @inheritdoc + */ + refresh(): void; + /** + * @inheritdoc + */ + refresh(it: std.ListIterator): void; + /** + * @inheritdoc + */ + refresh(first: std.ListIterator, last: std.ListIterator): void; + /** + * @inheritdoc + */ + addEventListener(type: string, listener: library.BasicEventListener): void; + addEventListener(type: "insert", listener: CollectionEventListener): void; + addEventListener(type: "erase", listener: CollectionEventListener): void; + addEventListener(type: "refresh", listener: CollectionEventListener): void; + /** + * @inheritdoc + */ + addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + addEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; + addEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; + addEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; + /** + * @inheritdoc + */ + removeEventListener(type: string, listener: library.BasicEventListener): void; + removeEventListener(type: "insert", listener: CollectionEventListener): void; + removeEventListener(type: "erase", listener: CollectionEventListener): void; + removeEventListener(type: "refresh", listener: CollectionEventListener): void; + /** + * @inheritdoc + */ + removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + removeEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; + removeEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; + removeEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; + } +} +declare namespace samchon.collections { + type MapCollectionEventListener = (event: MapCollectionEvent) => void; + /** + * An event occured in a {@link MapContainer map container} object. + * + * @handbook [Collections](https://github.com/samchon/framework/wiki/TypeScript-STL#collections) + * @author Jeongho Nam + */ + class MapCollectionEvent extends CollectionEvent> { + /** + * @inheritdoc + */ + readonly first: std.MapIterator; + /** + * @inheritdoc + */ + readonly last: std.MapIterator; + } +} +declare namespace samchon.collections { + /** + * A {@link TreeMap} who can detect element I/O events. + * + * Below is the list of methods who are dispatching {@link MapCollectionEvent}: + * - *insert* typed events: + * - {@link assign} + * - {@link insert} + * - {@link insert_or_assign} + * - {@link emplace} + * - {@link set} + * - {@link push} + * - *erase* typed events: + * - {@link assign} + * - {@link clear} + * - {@link erase} + * - {@link extract} + * - *refresh* typed events: + * - {@link refresh} + * + * #### [Inherited] {@link TreeMap} + * @copydoc TreeMap + */ + class TreeMapCollection extends std.TreeMap implements ICollection> { + /** + * @hidden + */ + private event_dispatcher_; + /** + * @hidden + */ + protected _Handle_insert(first: std.MapIterator, last: std.MapIterator): void; + /** + * @hidden + */ + protected _Handle_erase(first: std.MapIterator, last: std.MapIterator): void; + /** + * @inheritdoc + */ + hasEventListener(type: string): boolean; + /** + * @inheritdoc + */ + dispatchEvent(event: library.BasicEvent): boolean; + /** + * @inheritdoc + */ + refresh(): void; + /** + * @inheritdoc + */ + refresh(it: std.MapIterator): void; + /** + * @inheritdoc + */ + refresh(first: std.MapIterator, last: std.MapIterator): void; + /** + * @inheritdoc + */ + addEventListener(type: string, listener: library.BasicEventListener): void; + addEventListener(type: "insert", listener: MapCollectionEventListener): void; + addEventListener(type: "erase", listener: MapCollectionEventListener): void; + addEventListener(type: "refresh", listener: MapCollectionEventListener): void; + /** + * @inheritdoc + */ + addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + addEventListener(type: "insert", listener: MapCollectionEventListener, thisArg: Object): void; + addEventListener(type: "erase", listener: MapCollectionEventListener, thisArg: Object): void; + addEventListener(type: "refresh", listener: MapCollectionEventListener, thisArg: Object): void; + /** + * @inheritdoc + */ + removeEventListener(type: string, listener: library.BasicEventListener): void; + removeEventListener(type: "insert", listener: MapCollectionEventListener): void; + removeEventListener(type: "erase", listener: MapCollectionEventListener): void; + removeEventListener(type: "refresh", listener: MapCollectionEventListener): void; + /** + * @inheritdoc + */ + removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + removeEventListener(type: "insert", listener: MapCollectionEventListener, thisArg: Object): void; + removeEventListener(type: "erase", listener: MapCollectionEventListener, thisArg: Object): void; + removeEventListener(type: "refresh", listener: MapCollectionEventListener, thisArg: Object): void; + } +} +declare namespace samchon.collections { + /** + * A {@link TreeMultiMap} who can detect element I/O events. + * + * Below is the list of methods who are dispatching {@link MapCollectionEvent}: + * - *insert* typed events: + * - {@link assign} + * - {@link insert} + * - {@link emplace} + * - {@link push} + * - *erase* typed events: + * - {@link assign} + * - {@link clear} + * - {@link erase} + * - *refresh* typed events: + * - {@link refresh} + * + * #### [Inherited] {@link TreeMultiMap} + * @copydoc TreeMultiMap + */ + class TreeMultiMapCollection extends std.TreeMultiMap implements ICollection> { + /** + * @hidden + */ + private event_dispatcher_; + /** + * @hidden + */ + protected _Handle_insert(first: std.MapIterator, last: std.MapIterator): void; + /** + * @hidden + */ + protected _Handle_erase(first: std.MapIterator, last: std.MapIterator): void; + /** + * @inheritdoc + */ + hasEventListener(type: string): boolean; + /** + * @inheritdoc + */ + dispatchEvent(event: library.BasicEvent): boolean; + /** + * @inheritdoc + */ + refresh(): void; + /** + * @inheritdoc + */ + refresh(it: std.MapIterator): void; + /** + * @inheritdoc + */ + refresh(first: std.MapIterator, last: std.MapIterator): void; + /** + * @inheritdoc + */ + addEventListener(type: string, listener: library.BasicEventListener): void; + addEventListener(type: "insert", listener: MapCollectionEventListener): void; + addEventListener(type: "erase", listener: MapCollectionEventListener): void; + addEventListener(type: "refresh", listener: MapCollectionEventListener): void; + /** + * @inheritdoc + */ + addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + addEventListener(type: "insert", listener: MapCollectionEventListener, thisArg: Object): void; + addEventListener(type: "erase", listener: MapCollectionEventListener, thisArg: Object): void; + addEventListener(type: "refresh", listener: MapCollectionEventListener, thisArg: Object): void; + /** + * @inheritdoc + */ + removeEventListener(type: string, listener: library.BasicEventListener): void; + removeEventListener(type: "insert", listener: MapCollectionEventListener): void; + removeEventListener(type: "erase", listener: MapCollectionEventListener): void; + removeEventListener(type: "refresh", listener: MapCollectionEventListener): void; + /** + * @inheritdoc + */ + removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + removeEventListener(type: "insert", listener: MapCollectionEventListener, thisArg: Object): void; + removeEventListener(type: "erase", listener: MapCollectionEventListener, thisArg: Object): void; + removeEventListener(type: "refresh", listener: MapCollectionEventListener, thisArg: Object): void; + } +} +declare namespace samchon.collections { + /** + * A {@link TreeMultiSet} who can detect element I/O events. + * + * Below is the list of methods who are dispatching {@link CollectionEvent}: + * - *insert* typed events: + * - {@link assign} + * - {@link insert} + * - {@link push} + * - *erase* typed events: + * - {@link assign} + * - {@link clear} + * - {@link erase} + * - *refresh* typed events: + * - {@link refresh} + * + * #### [Inherited] {@link TreeMultiSet} + * @copydoc TreeMultiSet + */ + class TreeMultiSetCollection extends std.TreeMultiSet implements ICollection { + /** + * @hidden + */ + private event_dispatcher_; + /** + * @hidden + */ + protected _Handle_insert(first: std.SetIterator, last: std.SetIterator): void; + /** + * @hidden + */ + protected _Handle_erase(first: std.SetIterator, last: std.SetIterator): void; + /** + * @inheritdoc + */ + hasEventListener(type: string): boolean; + /** + * @inheritdoc + */ + dispatchEvent(event: library.BasicEvent): boolean; + /** + * @inheritdoc + */ + refresh(): void; + /** + * @inheritdoc + */ + refresh(it: std.SetIterator): void; + /** + * @inheritdoc + */ + refresh(first: std.SetIterator, last: std.SetIterator): void; + /** + * @inheritdoc + */ + addEventListener(type: string, listener: library.BasicEventListener): void; + addEventListener(type: "insert", listener: CollectionEventListener): void; + addEventListener(type: "erase", listener: CollectionEventListener): void; + addEventListener(type: "refresh", listener: CollectionEventListener): void; + /** + * @inheritdoc + */ + addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + addEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; + addEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; + addEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; + /** + * @inheritdoc + */ + removeEventListener(type: string, listener: library.BasicEventListener): void; + removeEventListener(type: "insert", listener: CollectionEventListener): void; + removeEventListener(type: "erase", listener: CollectionEventListener): void; + removeEventListener(type: "refresh", listener: CollectionEventListener): void; + /** + * @inheritdoc + */ + removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + removeEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; + removeEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; + removeEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; + } +} +declare namespace samchon.collections { + /** + * A {@link TreeMap} who can detect element I/O events. + * + * Below is the list of methods who are dispatching {@link CollectionEvent}: + * - *insert* typed events: + * - {@link assign} + * - {@link insert} + * - {@link insert_or_assign} + * - {@link push} + * - *erase* typed events: + * - {@link assign} + * - {@link clear}7 + * - {@link erase} + * - {@link extract} + * - *refresh* typed events: + * - {@link refresh} + * + * #### [Inherited] {@link TreeSet} + * @copydoc TreeSet + */ + class TreeSetCollection extends std.TreeSet implements ICollection { + /** + * @hidden + */ + private event_dispatcher_; + /** + * @hidden + */ + protected _Handle_insert(first: std.SetIterator, last: std.SetIterator): void; + /** + * @hidden + */ + protected _Handle_erase(first: std.SetIterator, last: std.SetIterator): void; + /** + * @inheritdoc + */ + hasEventListener(type: string): boolean; + /** + * @inheritdoc + */ + dispatchEvent(event: library.BasicEvent): boolean; + /** + * @inheritdoc + */ + refresh(): void; + /** + * @inheritdoc + */ + refresh(it: std.SetIterator): void; + /** + * @inheritdoc + */ + refresh(first: std.SetIterator, last: std.SetIterator): void; + /** + * @inheritdoc + */ + addEventListener(type: string, listener: library.BasicEventListener): void; + addEventListener(type: "insert", listener: CollectionEventListener): void; + addEventListener(type: "erase", listener: CollectionEventListener): void; + addEventListener(type: "refresh", listener: CollectionEventListener): void; + /** + * @inheritdoc + */ + addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + addEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; + addEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; + addEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; + /** + * @inheritdoc + */ + removeEventListener(type: string, listener: library.BasicEventListener): void; + removeEventListener(type: "insert", listener: CollectionEventListener): void; + removeEventListener(type: "erase", listener: CollectionEventListener): void; + removeEventListener(type: "refresh", listener: CollectionEventListener): void; + /** + * @inheritdoc + */ + removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + removeEventListener(type: "insert", listener: CollectionEventListener, thisArg: Object): void; + removeEventListener(type: "erase", listener: CollectionEventListener, thisArg: Object): void; + removeEventListener(type: "refresh", listener: CollectionEventListener, thisArg: Object): void; + } +} +declare namespace samchon.library { + /** + * Case generator. + * + * {@link CaseGenerator} is an abstract case generator being used like a matrix. + *
    + *
  • n��r(n^r) -> {@link CombinedPermutationGenerator}
  • + *
  • nPr -> {@link PermutationGenerator}
  • + *
  • n! -> {@link FactorialGenerator}
  • + *
+ * + * @author Jeongho Nam + */ + abstract class CaseGenerator { + /** + * Size, the number of all cases. + */ + protected size_: number; + /** + * N, size of the candidates. + */ + protected n_: number; + /** + * R, size of elements of each case. + */ + protected r_: number; + /** + * Construct from size of N and R. + * + * @param n Size of candidates. + * @param r Size of elements of each case. + */ + constructor(n: number, r: number); + /** + * Get size of all cases. + * + * @return Get a number of the all cases. + */ + size(): number; + /** + * Get size of the N. + */ + n(): number; + /** + * Get size of the R. + */ + r(): number; + /** + * Get index'th case. + * + * @param index Index number + * @return The row of the index'th in combined permuation case + */ + abstract at(index: number): number[]; + } + /** + * A combined-permutation case generator. + * + * n��r + * + * @author Jeongho Nam + */ + class CombinedPermutationGenerator extends CaseGenerator { + /** + * An array using for dividing each element index. + */ + private divider_array; + /** + * Construct from size of N and R. + * + * @param n Size of candidates. + * @param r Size of elements of each case. + */ + constructor(n: number, r: number); + at(index: number): number[]; + } + /** + * A permutation case generator. + * + * nPr + * + * @author Jeongho Nam + */ + class PermuationGenerator extends CaseGenerator { + /** + * Construct from size of N and R. + * + * @param n Size of candidates. + * @param r Size of elements of each case. + */ + constructor(n: number, r: number); + /** + * @inheritdoc + */ + at(index: number): number[]; + } + /** + * Factorial case generator. + * + * n! = nPn + * + * @author Jeongho Nam + */ + class FactorialGenerator extends PermuationGenerator { + /** + * Construct from factorial size N. + * + * @param n Factoria size N. + */ + constructor(n: number); + } +} +declare namespace samchon.library { + type BasicEventListener = (event: BasicEvent) => void; + /** + * The IEventDispatcher interface defines methods for adding or removing event listeners, checks whether specific + * types of event listeners are registered, and dispatches events. + * + * The event target serves as the local point for how events flow through the display list hierarchy. When an + * event such as a mouse click or a key press occurs, an event object is dispatched into the event flow from the + * root of the display list. The event object makes a round-trip journey to the event target, which is + * conceptually divided into three phases: the capture phase includes the journey from the root to the last node + * before the event target's node; the target phase includes only the event target node; and the bubbling phase + * includes any subsequent nodes encountered on the return trip to the root of the display list. + * + * In general, the easiest way for a user-defined class to gain event dispatching capabilities is to extend + * {@link EventDispatcher}. If this is impossible (that is, if the class is already extending another class), you + * can instead implement the {@link IEventDispatcher} interface, create an {@link EventDispatcher} member, and + * write simple hooks to route calls into the aggregated {@link EventDispatcher}. + * + * @reference http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/IEventDispatcher.html + * @handbook https://github.com/samchon/framework/wiki/TypeScript-Library-EventDispatcher + * @author Migrated by Jeongho Nam + */ + interface IEventDispatcher { + /** + * Checks whether the {@link EventDispatcher} object has any listeners registered for a specific type of event. + * This allows you to determine where an {@link EventDispatcher} object has altered handling of an event type + * in the event flow hierarchy. To determine whether a specific event type actually triggers an event listener, + * use {@link willTrigger willTrigger()}. + * + * The difference between {@link hasEventListener hasEventListener()} and {@link willTrigger willTrigger()} is + * that {@link hasEventListener} examines only the object to which it belongs, whereas {@link willTrigger} + * examines the entire event flow for the event specified by the type parameter. + * + * @param type The type of event. + */ + hasEventListener(type: string): boolean; + /** + * Dispatches an event into the event flow. + * + * The event target is the {@link EventDispatcher} object upon which the {@link dispatchEvent dispatchEvent()} + * method is called. + * + * @param event The {@link BasicEvent} object that is dispatched into the event flow. If the event is being + * redispatched, a clone of the event is created automatically. After an event is dispatched, its + * target property cannot be changed, so you must create a new copy + * of the event for redispatching to work. + */ + dispatchEvent(event: library.BasicEvent): boolean; + /** + * Registers an event listener object with an {@link EventDispatcher} object so that the listener receives + * notification of an event. You can register event listeners on all nodes in the display list for a specific + * type of event, phase, and priority. + * + * After you successfully register an event listener, you cannot change its priority through additional calls + * to {@link addEventListener addEventListener()|} To change a listener's priority, you must first call + * {@link removeEventListener removeEventListener()}. Then you can register the listener again with the new + * priority level. + * + * Keep in mind that after the listener is registered, subsequent calls to {@link addEventListener} with a + * different type or useCapture value result in the creation of a separate listener registration. For example, + * if you first register a listener with useCapture set to true, it listens only during the capture phase. If + * you call {@link addEventListener} again using the same listener object, but with useCapture set to false, + * you have two separate listeners: one that listens during the capture phase and another that listens during + * the target and bubbling phases. + * + * You cannot register an event listener for only the target phase or the bubbling phase. Those phases are + * coupled during registration because bubbling applies only to the ancestors of the target node. + * + * If you no longer need an event listener, remove it by calling {@link removeEventListener}, or memory + * problems could result. Event listeners are not automatically removed from memory because the garbage + * collector does not remove the listener as long as the dispatching object exists (unless the + * useWeakReference parameter is set to true). + * + * Copying an {@link EventDispatcher} instance does not copy the event listeners attached to it. (If your n + * ewly created node needs an event listener, you must attach the listener after creating the node.) However, + * if you move an {@link EventDispatcher} instance, the event listeners attached to it move along with it. + * + * If the event listener is being registered on a node while an event is also being processed on this node, + * the event listener is not triggered during the current phase but may be triggered during a later phase in + * the event flow, such as the bubbling phase. + * + * If an event listener is removed from a node while an event is being processed on the node, it is still + * triggered by the current actions. After it is removed, the event listener is never invoked again (unless it + * is registered again for future processing). + * + * @param event The type of event. + * @param listener The listener function that processes the event. + * This function must accept an Event object as its only parameter and must return + * nothing. + */ + addEventListener(type: string, listener: library.BasicEventListener): void; + /** + * Registers an event listener object with an {@link EventDispatcher} object so that the listener receives + * notification of an event. You can register event listeners on all nodes in the display list for a specific + * type of event, phase, and priority. + * + * After you successfully register an event listener, you cannot change its priority through additional calls + * to {@link addEventListener addEventListener()|} To change a listener's priority, you must first call + * {@link removeEventListener removeEventListener()}. Then you can register the listener again with the new + * priority level. + * + * Keep in mind that after the listener is registered, subsequent calls to {@link addEventListener} with a + * different type or useCapture value result in the creation of a separate listener registration. For example, + * if you first register a listener with useCapture set to true, it listens only during the capture phase. If + * you call {@link addEventListener} again using the same listener object, but with useCapture set to false, + * you have two separate listeners: one that listens during the capture phase and another that listens during + * the target and bubbling phases. + * + * You cannot register an event listener for only the target phase or the bubbling phase. Those phases are + * coupled during registration because bubbling applies only to the ancestors of the target node. + * + * If you no longer need an event listener, remove it by calling {@link removeEventListener}, or memory + * problems could result. Event listeners are not automatically removed from memory because the garbage + * collector does not remove the listener as long as the dispatching object exists (unless the + * useWeakReference parameter is set to true). + * + * Copying an {@link EventDispatcher} instance does not copy the event listeners attached to it. (If your n + * ewly created node needs an event listener, you must attach the listener after creating the node.) However, + * if you move an {@link EventDispatcher} instance, the event listeners attached to it move along with it. + * + * If the event listener is being registered on a node while an event is also being processed on this node, + * the event listener is not triggered during the current phase but may be triggered during a later phase in + * the event flow, such as the bubbling phase. + * + * If an event listener is removed from a node while an event is being processed on the node, it is still + * triggered by the current actions. After it is removed, the event listener is never invoked again (unless it + * is registered again for future processing). + * + * @param event The type of event. + * @param listener The listener function that processes the event. + * This function must accept an Event object as its only parameter and must return + * nothing. + * @param thisArg The object to be used as the **this** object. + */ + addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + /** + * Removes a listener from the {@link EventDispatcher} object. If there is no matching listener registered + * with the {@link EventDispatcher} object, a call to this method has no effect. + * + * @param type The type of event. + * @param listener The listener object to remove. + */ + removeEventListener(type: string, listener: library.BasicEventListener): void; + /** + * Removes a listener from the {@link EventDispatcher} object. If there is no matching listener registered + * with the {@link EventDispatcher} object, a call to this method has no effect. + * + * @param type The type of event. + * @param listener The listener object to remove. + * @param thisArg The object to be used as the **this** object. + */ + removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + } + /** + * The {@link EventDispatcher} class is the base class for all classes that dispatch events. The + * {@link EventDispatcher} class implements the {@link IEventDispatcher} interface and is the base class for the + * {@link DisplayObject} class. The {@link EventDispatcher} class allows any object on the display list to be an + * event target and as such, to use the methods of the {@link IEventDispatcher} interface. + * + * The event target serves as the local point for how events flow through the display list hierarchy. When an + * event such as a mouse click or a key press occurs, an event object is dispatched into the event flow from the + * root of the display list. The event object makes a round-trip journey to the event target, which is + * conceptually divided into three phases: the capture phase includes the journey from the root to the last node + * before the event target's node; the target phase includes only the event target node; and the bubbling phase + * includes any subsequent nodes encountered on the return trip to the root of the display list. + * + * In general, the easiest way for a user-defined class to gain event dispatching capabilities is to extend + * {@link EventDispatcher}. If this is impossible (that is, if the class is already extending another class), you + * can instead implement the {@link IEventDispatcher} interface, create an {@link EventDispatcher} member, and + * write simple hooks to route calls into the aggregated {@link EventDispatcher}. + * + * @reference http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/EventDispatcher.html + * @author Migrated by Jeongho Nam + */ + class EventDispatcher implements IEventDispatcher { + /** + * @hidden + */ + private event_dispatcher_; + /** + * @hidden + */ + private event_listeners_; + /** + * Default Constructor. + */ + constructor(); + /** + * Construct from the origin event dispatcher. + * + * @param dispatcher The origin object who issuing events. + */ + constructor(dispatcher: IEventDispatcher); + /** + * @inheritdoc + */ + hasEventListener(type: string): boolean; + /** + * @inheritdoc + */ + dispatchEvent(event: library.BasicEvent): boolean; + /** + * @inheritdoc + */ + addEventListener(type: string, listener: library.BasicEventListener): void; + /** + * @inheritdoc + */ + addEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + /** + * @inheritdoc + */ + removeEventListener(type: string, listener: library.BasicEventListener): void; + /** + * @inheritdoc + */ + removeEventListener(type: string, listener: library.BasicEventListener, thisArg: Object): void; + } +} +declare namespace samchon.library { + /** + * The {@link FileReference} class provides a means to load and save files in browser level. + * + * The {@link FileReference} class provides a means to {@link load} and {@link save} files in browser level. A + * browser-system dialog box prompts the user to select a file to {@link load} or a location for {@link svae}. Each + * {@link FileReference} object refers to a single file on the user's disk and has properties that contain + * information about the file's size, type, name, creation date, modification date, and creator type (Macintosh only). + * + * + * FileReference instances are created in the following ways: + *
    + *
  • + * When you use the new operator with the {@link FileReference} constructor: + * let myFileReference: FileReference = new FileReference(); + *
  • + *
  • + * When you call the {@link FileReferenceList.browse} method, which creates an array of {@link FileReference} + * objects. + *
  • + *
+ * + * During a load operation, all the properties of a {@link FileReference} object are populated by calls to the + * {@link FileReference.browse} or {@link FileReferenceList.browse} methods. During a save operation, the name + * property is populated when the select event is dispatched; all other properties are populated when the complete + * event is dispatched. + * + * The {@link browse browse()} method opens an browser-system dialog box that prompts the user to select a file + * for {@link load}. The {@link FileReference.browse} method lets the user select a single file; the + * {@link FileReferenceList.browse} method lets the user select multiple files. After a successful call to the + * {@link browse browse()} method, call the {@link FileReference.load} method to load one file at a time. The + * {@link FileReference.save} method prompts the user for a location to save the file and initiates downloading from + * a binary or string data. + * + * The {@link FileReference} and {@link FileReferenceList} classes do not let you set the default file location + * for the dialog box that the {@link browse} or {@link save} methods generate. The default location shown in the + * dialog box is the most recently browsed folder, if that location can be determined, or the desktop. The classes do + * not allow you to read from or write to the transferred file. They do not allow the browser that initiated the + * {@link load} or {@link save} to access the loaded or saved file or the file's location on the user's disk. + * + * @references http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html + * @author Jeongho Nam + */ + class FileReference extends EventDispatcher { + /** + * @hidden + */ + private file_; + /** + * @hidden + */ + private data_; + /** + * Default Constructor. + */ + constructor(); + /** + * The data from the loaded file after a successful call to the {@link load load()} method. + * + * If the {@link FileReference} object was not populated (by a valid call to {@link FileReference.browse}), + * an {@link LogicError exception} will be thrown when you try to get the value of this property. + * + * All the properties of a {@link FileReference} object are populated by calling the {@link browse browse()}. + * + */ + readonly data: any; + /** + * The name of the file on the local disk. + * + * If the {@link FileReference} object was not populated (by a valid call to {@link FileReference.browse}), + * an {@link LogicError exception} will be thrown when you try to get the value of this property. + * + * All the properties of a {@link FileReference} object are populated by calling the {@link browse browse()}. + * + */ + readonly name: string; + /** + * The filename extension. + * + * A file's extension is the part of the name following (and not including) the final dot ("."). If + * there is no dot in the filename, the extension is null. + * + * If the {@link FileReference} object was not populated (by a valid call to {@link FileReference.browse}), + * an {@link LogicError exception} will be thrown when you try to get the value of this property. + * + * All the properties of a {@link FileReference} object are populated by calling the {@link browse browse()}. + * + */ + readonly extension: string; + /** + * The file type, metadata of the {@link extension}. + * + * If the {@link FileReference} object was not populated (by a valid call to {@link FileReference.browse}), + * an {@link LogicError exception} will be thrown when you try to get the value of this property. + * + * All the properties of a {@link FileReference} object are populated by calling the {@link browse browse()}. + * + */ + readonly type: string; + /** + * The size of the file on the local disk in bytes. + * + * If the {@link FileReference} object was not populated (by a valid call to {@link FileReference.browse}), + * an {@link LogicError exception} will be thrown when you try to get the value of this property. + * + * All the properties of a {@link FileReference} object are populated by calling the {@link browse browse()}. + * + */ + readonly size: number; + /** + * The date that the file on the local disk was last modified. + * + * If the {@link FileReference} object was not populated (by a valid call to {@link FileReference.browse}), + * an {@link LogicError exception} will be thrown when you try to get the value of this property. + * + * All the properties of a {@link FileReference} object are populated by calling the {@link browse browse()}. + * + */ + readonly modificationDate: Date; + /** + * Displays a file-browsing dialog box that lets the user select a file to upload. The dialog box is native + * to the user's browser system. The user can select a file on the local computer or from other systems, for + * example, through a UNC path on Windows. + * + * When you call this method and the user successfully selects a file, the properties of this + * {@link FileReference} object are populated with the properties of that file. Each subsequent time that the + * {@link FileReference.browse} method is called, the {@link FileReference} object's properties are reset to + * the file that the user selects in the dialog box. Only one {@link browse browse()} can be performed at a time + * (because only one dialog box can be invoked at a time). + * + * Using the *typeFilter parameter*, you can determine which files the dialog box displays. + * + * @param typeFilter An array of filter strings used to filter the files that are displayed in the dialog box. + * If you omit this parameter, all files are displayed. + */ + browse(...typeFilter: string[]): void; + /** + * Starts the load of a local file selected by a user. + * + * You must call the {@link FileReference.browse} or {@link FileReferenceList.browse} method before you call + * the {@link load load()} method. + * + * Listeners receive events to indicate the progress, success, or failure of the load. Although you can use + * the {@link FileReferenceList} object to let users select multiple files to load, you must {@link load} the + * {@link FileReferenceList files} one by one. To {@link load} the files one by one, iterate through the + * {@link FileReferenceList.fileList} array of {@link FileReference} objects. + * + * If the file finishes loading successfully, its contents are stored in the {@link data} property. + */ + load(): void; + /** + * Save a file to local filesystem. + * + * {@link FileReference.save} implemented the save function by downloading a file from a hidden anchor tag. + * However, the plan, future's {@link FileReference} will follow such rule: + * + * Opens a dialog box that lets the user save a file to the local filesystem. + * + * The {@link save save()} method first opens an browser-system dialog box that asks the user to enter a + * filename and select a location on the local computer to save the file. When the user selects a location and + * confirms the save operation (for example, by clicking Save), the save process begins. Listeners receive events + * to indicate the progress, success, or failure of the save operation. To ascertain the status of the dialog box + * and the save operation after calling {@link save save()}, your code must listen for events such as cancel, + * open, progress, and complete. + * + * When the file is saved successfully, the properties of the {@link FileReference} object are populated with + * the properties of the local file. The complete event is dispatched if the save is successful. + * + * Only one {@link browse browse()} or {@link save()} session can be performed at a time (because only one + * dialog box can be invoked at a time). + * + * @param data The data to be saved. The data can be in one of several formats, and will be treated appropriately. + * @param fileName File name to be saved. + */ + save(data: string, fileName: string): void; + /** + * Save a file to local filesystem. + * + * {@link FileReference.save} implemented the save function by downloading a file from a hidden anchor tag. + * However, the plan, future's {@link FileReference} will follow such rule: + * + * Opens a dialog box that lets the user save a file to the local filesystem. + * + * The {@link save save()} method first opens an browser-system dialog box that asks the user to enter a + * filename and select a location on the local computer to save the file. When the user selects a location and + * confirms the save operation (for example, by clicking Save), the save process begins. Listeners receive events + * to indicate the progress, success, or failure of the save operation. To ascertain the status of the dialog box + * and the save operation after calling {@link save save()}, your code must listen for events such as cancel, + * open, progress, and complete. + * + * When the file is saved successfully, the properties of the {@link FileReference} object are populated with + * the properties of the local file. The complete event is dispatched if the save is successful. + * + * Only one {@link browse browse()} or {@link save()} session can be performed at a time (because only one + * dialog box can be invoked at a time). + * + * @param data The data to be saved. The data can be in one of several formats, and will be treated appropriately. + * @param fileName File name to be saved. + */ + static save(data: string, fileName: string): void; + } + /** + * The {@link FileReferenceList} class provides a means to let users select one or more files for + * {@link FileReference.load loading}. A {@link FileReferenceList} object represents a group of one or more local + * files on the user's disk as an array of {@link FileReference} objects. For detailed information and important + * considerations about {@link FileReference} objects and the FileReference class, which you use with + * {@link FileReferenceList}, see the {@link FileReference} class. + * + * To work with the {@link FileReferenceList} class: + *
    + *
  • Instantiate the class: var myFileRef = new FileReferenceList();
  • + *
  • + * Call the {@link FileReferenceList.browse} method, which opens a dialog box that lets the user select one or + * more files for upload: myFileRef.browse(); + *
  • + *
  • + * After the {@link browse browse()} method is called successfully, the {@link fileList} property of the + * {@link FileReferenceList} object is populated with an array of {@link FileReference} objects. + *
  • + *
  • Call {@link FileReference.load} on each element in the {@link fileList} array.
  • + *
+ * + * The {@link FileReferenceList} class includes a {@link browse browse()} method and a {@link fileList} property + * for working with multiple files. + * + * @reference http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReferenceList.html + * @author Jeongho Nam + */ + class FileReferenceList extends EventDispatcher { + /** + * @hidden + */ + file_list: std.Vector; + /** + * Default Constructor. + */ + constructor(); + /** + * An array of {@link FileReference} objects. + * + * When the {@link FileReferenceList.browse} method is called and the user has selected one or more files + * from the dialog box that the {@link browse browse()} method opens, this property is populated with an array of + * {@link FileReference} objects, each of which represents the files the user selected. + * + * The {@link fileList} property is populated anew each time {@link browse browse()} is called on that + * {@link FileReferenceList} object. + */ + readonly fileList: std.Vector; + /** + * Displays a file-browsing dialog box that lets the user select one or more local files to upload. The + * dialog box is native to the user's browser system. + * + * When you call this method and the user successfully selects files, the {@link fileList} property of this + * {@link FileReferenceList} object is populated with an array of {@link FileReference} objects, one for each + * file that the user selects. Each subsequent time that the {@link FileReferenceList.browse} method is called, + * the {@link FileReferenceList.fileList} property is reset to the file(s) that the user selects in the dialog + * box. + * + * Using the *typeFilter* parameter, you can determine which files the dialog box displays. + * + * Only one {@link FileReference.browse}, {@link FileReference.load}, or {@link FileReferenceList.browse} + * session can be performed at a time on a {@link FileReferenceList} object (because only one dialog box can be + * opened at a time). + * + * @param typeFilter An array of filter strings used to filter the files that are displayed in the dialog box. + * If you omit this parameter, all files are displayed. + */ + browse(...typeFilter: string[]): void; + } +} +declare namespace samchon.library { + /** + * A genetic algorithm class. + * + * In the field of artificial intelligence, a genetic algorithm (GA) is a search heuristic that mimics the + * process of natural selection. This heuristic (also sometimes called a metaheuristic) is routinely used to generate + * useful solutions to optimization and search problems. + * + * Genetic algorithms belong to the larger class of evolutionary algorithms (EA), which generate solutions to + * optimization problems using techniques inspired by natural evolution, such as inheritance, {@link mutate mutation}, + * {@link selection}, and {@link crossover}. + * + * @reference https://en.wikipedia.org/wiki/Genetic_algorithm + * @author Jeongho Nam + */ + class GeneticAlgorithm { + /** + * Whether each element (Gene) is unique in their GeneArray. + */ + private unique_; + /** + * Rate of mutation. + * + * The {@link mutation_rate} determines the percentage of occurence of mutation in GeneArray. + * + *
    + *
  • When {@link mutation_rate} is too high, it is hard to ancitipate studying on genetic algorithm.
  • + *
  • + * When {@link mutation_rate} is too low and initial set of genes (GeneArray) is far away from optimal, the + * evolution tends to wandering outside of he optimal. + *
  • + *
+ */ + private mutation_rate_; + /** + * Number of tournaments in selection. + */ + private tournament_; + /** + * Initialization Constructor. + * + * @param unique Whether each Gene is unique in their GeneArray. + * @param mutation_rate Rate of mutation. + * @param tournament Number of tournaments in selection. + */ + constructor(unique?: boolean, mutation_rate?: number, tournament?: number); + /** + * Evolove *GeneArray*. + * + * Convenient method accessing to {@link evolvePopulation evolvePopulation()}. + * + * @param individual An initial set of genes; sequence listing. + * @param population Size of population in a generation. + * @param generation Size of generation in evolution. + * @param compare A comparison function returns whether left gene is more optimal. + * + * @return An evolved *GeneArray*, optimally. + * + * @see {@link GAPopulation.compare} + */ + evolveGeneArray>(individual: GeneArray, population: number, generation: number, compare?: (left: T, right: T) => boolean): GeneArray; + /** + * Evolve *population*, a mass of *GeneArraies*. + * + * @param population An initial population. + * @param compare A comparison function returns whether left gene is more optimal. + * + * @return An evolved population. + * + * @see {@link GAPopulation.compare} + */ + evolvePopulation>(population: GAPopulation, compare?: (left: T, right: T) => boolean): GAPopulation; + /** + * Select the best GeneArray in *population* from tournament. + * + * {@link selection Selection} is the stage of a genetic algorithm in which individual genomes are chosen + * from a population for later breeding (using {@linlk crossover} operator). A generic {@link selection} + * procedure may be implemented as follows: + * + *
    + *
  1. + * The fitness function is evaluated for each individual, providing fitness values, which are then + * normalized. ization means dividing the fitness value of each individual by the sum of all fitness + * values, so that the sum of all resulting fitness values equals 1. + *
  2. + *
  3. The population is sorted by descending fitness values.
  4. + *
  5. + * Accumulated normalized fitness values are computed (the accumulated fitness value of an individual is the + * sum of its own fitness value plus the fitness values of all the previous individuals). The accumulated + * fitness of the last individual should be 1 (otherwise something went wrong in the normalization step). + *
  6. + *
  7. A random number R between 0 and 1 is chosen.
  8. + *
  9. The selected individual is the first one whose accumulated normalized value is greater than R.
  10. + *
+ * + * @param population The target of tournament. + * @return The best genes derived by the tournament. + * + * @reference https://en.wikipedia.org/wiki/Selection_(genetic_algorithm) + */ + private selection(population); + /** + * Create a new GeneArray by crossing over two *GeneArray*(s). + * + * {@link crossover} is a genetic operator used to vary the programming of a chromosome or chromosomes from + * one generation to the next. It is analogous to reproduction and biological crossover, upon which genetic + * algorithms are based. + * + * {@link crossover Cross over} is a process of taking more than one parent solutions and producing a child + * solution from them. There are methods for selection of the chromosomes. + * + * @param parent1 A parent sequence listing + * @param parent2 A parent sequence listing + * + * @reference https://en.wikipedia.org/wiki/Crossover_(genetic_algorithm) + */ + private crossover(parent1, parent2); + /** + * Cause a mutation on the *GeneArray*. + * + * {@link mutate Mutation} is a genetic operator used to maintain genetic diversity from one generation of a + * population of genetic algorithm chromosomes to the next. It is analogous to biological mutation. + * + * {@link mutate Mutation} alters one or more gene values in a chromosome from its initial state. In + * {@link mutate mutation}, the solution may change entirely from the previous solution. Hence GA can come to + * better solution by using {@link mutate mutation}. + * + * {@link mutate Mutation} occurs during evolution according to a user-definable mutation probability. This + * probability should be set low. If it is set too high, the search will turn into a primitive random search. + * + *

Note

+ * Muttion is pursuing diversity. Mutation is useful for avoiding the following problem. + * + * When initial set of genes(GeneArray) is far away from optimail, without mutation (only with selection and + * crossover), the genetic algorithm has a tend to wandering outside of the optimal. + * + * Genes in the GeneArray will be swapped following percentage of the {@link mutation_rate}. + * + * @param individual A container of genes to mutate + * + * @reference https://en.wikipedia.org/wiki/Mutation_(genetic_algorithm) + * @see {@link mutation_rate} + */ + private mutate(individual); + } + /** + * A population in a generation. + * + * {@link GAPopulation} is a class representing population of candidate genes (sequence listing) having an array + * of GeneArray as a member. {@link GAPopulation} also manages initial set of genes and handles fitting test direclty + * by the method {@link fitTest fitTest()}. + * + * The success of evolution of genetic algorithm is depend on the {@link GAPopulation}'s initial set and fitting + * test. (*GeneArray* and {@link compare}.) + * + *

Warning

+ * Be careful for the mistakes of direction or position of the {@link compare}. + * Most of logical errors failed to access optimal solution are occured from those mistakes. + * + * @param Type of gene elements. + * @param An array containing genes as elments; sequnce listing. + * + * @author Jeongho Nam + */ + class GAPopulation> { + /** + * Genes representing the population. + */ + private children_; + /** + * A comparison function returns whether left gene is more optimal, greater. + * + * Default value of this {@link compare} is {@link std.greater}. It means to compare two array + * (GeneArray must be a type of {@link std.base.IArrayContainer}). Thus, you've to keep follwing rule. + * + *
    + *
  • GeneArray is implemented from {@link std.base.IArrayContainer}.
  • + *
      + *
    • {@link std.Vector}
    • + *
    • {@link std.Deque}
    • + *
    + *
  • GeneArray has custom public less(obj: T): boolean; function.
  • + *
+ * + * If you don't want to follow the rule or want a custom comparison function, you have to realize a + * comparison function. + */ + private compare_; + /** + * Private constructor with population. + * + * Private constructor of GAPopulation does not create {@link children}. (candidate genes) but only assigns + * *null* repeatedly following the *population size*. + * + * This private constructor is designed only for {@link GeneticAlgorithm}. Don't create {@link GAPopulation} + * with this constructor, by yourself. + * + * @param size Size of the population. + */ + constructor(size: number); + /** + * Construct from a {@link GeneArray} and *size of the population*. + * + * This public constructor creates *GeneArray(s)* as population (size) having shuffled genes which are + * came from the initial set of genes (*geneArray*). It uses {@link std.greater} as default comparison function. + * + * + * @param geneArray An initial sequence listing. + * @param size The size of population to have as children. + */ + constructor(geneArray: GeneArray, size: number); + /** + * Constructor from a GeneArray, size of the poluation and custom comparison function. + * + * This public constructor creates *GeneArray(s)* as population (size) having shuffled genes which are + * came from the initial set of genes (*geneArray*). The *compare* is used for comparison function. + * + * + * @param geneArray An initial sequence listing. + * @param size The size of population to have as children. + * @param compare A comparison function returns whether left gene is more optimal. + */ + constructor(geneArray: GeneArray, size: number, compare: (left: GeneArray, right: GeneArray) => boolean); + children(): std.Vector; + /** + * Test fitness of each *GeneArray* in the {@link population}. + * + * @return The best *GeneArray* in the {@link population}. + */ + fitTest(): GeneArray; + /** + * @hidden + */ + private clone(obj); + } +} +declare namespace samchon.library { + /** + * A utility class supporting static methods of string. + * + * The {@link StringUtil} utility class is an all-static class with methods for working with string objects. + * You do not create instances of {@link StringUtil}; instead you call methods such as the + * ```StringUtil.substitute()``` method. + * + * @reference http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/utils/StringUtil.html + * @author Jeongho Nam + */ + class StringUtil { + /** + * Generate a substring. + * + * Extracts a substring consisting of the characters from specified start to end. + * It's same with str.substring( ? = (str.find(start) + start.size()), str.find(end, ?) ) + * + * ```typescript + * let str: string = StringUtil.between("ABCD(EFGH)IJK", "(", ")"); + * console.log(str); // PRINTS "EFGH" + * ``` + * + * - If start is not specified, extracts from begin of the string to end. + * - If end is not specified, extracts from start to end of the string. + * - If start and end are all omitted, returns str, itself. + * + * @param str Target string to be applied between. + * @param start A string for separating substring at the front. + * @param end A string for separating substring at the end. + * + * @return substring by specified terms. + */ + static between(str: string, start?: string, end?: string): string; + /** + * Fetch substrings. + * + * Splits a string into an array of substrings dividing by specified delimeters of start and end. + * It's the array of substrings adjusted the between. + * + *
    + *
  • If startStr is omitted, it's same with the split by endStr not having last item.
  • + *
  • If endStr is omitted, it's same with the split by startStr not having first item.
  • + *
  • If startStr and endStar are all omitted, returns *str*.
  • + *
+ * + * @param str Target string to split by between. + * @param start A string for separating substring at the front. + * If omitted, it's same with split(end) not having last item. + * @param end A string for separating substring at the end. + * If omitted, it's same with split(start) not having first item. + * @return An array of substrings. + */ + static betweens(str: string, start?: string, end?: string): Array; + /** + * An array containing whitespaces. + */ + private static SPACE_ARRAY; + /** + * Remove all designated characters from the beginning and end of the specified string. + * + * @param str The string whose designated characters should be trimmed. + * @param args Designated character(s). + * + * @return Updated string where designated characters was removed from the beginning and end. + */ + static trim(str: string, ...args: string[]): string; + /** + * Remove all designated characters from the beginning of the specified string. + * + * @param str The string should be trimmed. + * @param delims Designated character(s). + * + * @return Updated string where designated characters was removed from the beginning + */ + static ltrim(str: string, ...args: string[]): string; + /** + * Remove all designated characters from the end of the specified string. + * + * @param str The string should be trimmed. + * @param delims Designated character(s). + * + * @return Updated string where designated characters was removed from the end. + */ + static rtrim(str: string, ...args: string[]): string; + /** + * Substitute `{n}` tokens within the specified string. + * + * @param format The string to make substitutions in. This string can contain special tokens of the form + * `{n}`, where *n* is a zero based index, that will be replaced with the additional parameters + * found at that index if specified. + * @param args Additional parameters that can be substituted in the *format* parameter at each + * `{n}` location, where *n* is an integer (zero based) index value into the array of values + * specified. + * + * @return New string with all of the `{n}` tokens replaced with the respective arguments specified. + */ + static substitute(format: string, ...args: any[]): string; + /** + * Substitute `{n}` tokens within the specified SQL-string. + * + * @param format The string to make substitutions in. This string can contain special tokens of the form + * `{n}`, where *n* is a zero based index, that will be replaced with the additional parameters + * found at that index if specified. + * @param args Additional parameters that can be substituted in the *format* parameter at each + * `{n}` location, where *n* is an integer (zero based) index value into the array of values + * specified. + * + * @return New SQL-string with all of the `{n}` tokens replaced with the respective arguments specified. + */ + static substituteSQL(format: string, ...args: any[]): string; + /** + * @hidden + */ + private static _Fetch_substitute_index(format); + /** + * Returns a string specified word is replaced. + * + * @param str Target string to replace + * @param before Specific word you want to be replaced + * @param after Specific word you want to replace + * + * @return A string specified word is replaced + */ + static replaceAll(str: string, before: string, after: string): string; + /** + * Returns a string specified words are replaced. + * + * @param str Target string to replace + * @param pairs A specific word's pairs you want to replace and to be replaced + * + * @return A string specified words are replaced + */ + static replaceAll(str: string, ...pairs: std.Pair[]): string; + /** + * Replace all HTML spaces to a literal space. + * + * @param str Target string to replace. + */ + static removeHTMLSpaces(str: string): string; + /** + * Repeat a string. + * + * Returns a string consisting of a specified string concatenated with itself a specified number of times. + * + * @param str The string to be repeated. + * @param n The repeat count. + * + * @return The repeated string. + */ + static repeat(str: string, n: number): string; + /** + * Number to formatted string with "," sign. + * + * Returns a string converted from the number rounded off from specified precision with "," symbols. + * + * @param val A number wants to convert to string. + * @param precision Target precision of round off. + * + * @return A string who represents the number with roundoff and "," symbols. + */ + static numberFormat(val: number, precision?: number): string; + static percentFormat(val: number, precision?: number): string; + } +} +declare namespace samchon.library { + /** + * URLVariables class is for representing variables of HTTP. + * + * {@link URLVariables} class allows you to transfer variables between an application and server. + * + * When transfering, {@link URLVariables} will be converted to a *URI* string. + * - URI: Uniform Resource Identifier + * + * @reference http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLVariables.html + * @author Migrated by Jeongho Nam + */ + class URLVariables extends std.HashMap { + /** + * Default Constructor. + */ + constructor(); + /** + * Construct from a URL-encoded string. + * + * The {@link decode decode()} method is automatically called to convert the string to properties of the {@link URLVariables} object. + * + * @param str A URL-encoded string containing name/value pairs. + */ + constructor(str: string); + /** + * Converts the variable string to properties of the specified URLVariables object. + * + * @param str A URL-encoded query string containing name/value pairs. + */ + decode(str: string): void; + /** + * Returns a string containing all enumerable variables, in the MIME content encoding application/x-www-form-urlencoded. + */ + toString(): string; + } +} +declare namespace samchon.library { + /** + * A tree-structured XML object. + * + * The {@link XML| class contains methods and properties for working with XML objects. The {@link XML} class (along + * with the {@link XMLList}) implements the powerful XML-handling standards defined in ECMAScript for XML (E4X) + * specification (ECMA-357 edition 2). + * + * An XML object, it is composed with three members; {@link getTag tag}, {@link getProperty properties} and + * {@link getValue value}. As you know, XML is a tree structured data expression method. The tree-stucture; + * {@link XML} class realizes it by extending ```std.HashMap```. Child {@link XML} objects are + * contained in the matched {@link XMLList} object being grouped by their {@link getTag tag name}. The + * {@link XMLList} objects, they're stored in the {@link std.HashMap} ({@link XML} itself) with its **key**; common + * {@link getTag tag name} of children {@link XML} objects. + * + * ```typescript + * class XML extends std.HashMap + * { + * private tag_: string; + * private properties_: std.HashMap; + * private value_: string; + * } + * ``` + * + * ```xml + * + * + * + * {value} + * {value} + * {value} + * + * + * + * + * ``` + * + * Use the {@link toString toString()} method to return a string representation of the {@link XML} object regardless + * of whether the {@link XML} object has simple content or complex content. + * + * @reference http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XML.html + * @handbook https://github.com/samchon/framework/wiki/TypeScript-Library-XML + * @author Jeongho Nam + */ + class XML extends std.HashMap { + /** + * @hidden + */ + private tag_; + /** + * @hidden + */ + private value_; + /** + * @hidden + */ + private property_map_; + /** + * Default Constructor. + */ + constructor(); + /** + * Construct from string. + * + * Creates {@link XML} object by parsing a string who represents xml structure. + * + * @param str A string represents XML structure. + */ + constructor(str: string); + /** + * @hidden + */ + private _Parse(str); + /** + * @hidden + */ + private _Parse_tag(str); + /** + * @hidden + */ + private _Parse_properties(str); + /** + * @hidden + */ + private _Parse_value(str); + /** + * @hidden + */ + private _Parse_children(str); + /** + * Get tag. + * + * ```xml + * {value} + * ``` + * + * @return tag. + */ + getTag(): string; + /** + * Get value. + * + * ```xml + * {VALUE} + * ``` + * + * @return value. + */ + getValue(): string; + /** + * Get iterator to property element. + * + * Searches the {@link getPropertyMap properties} for an element with a identifier equivalent to key + * and returns an iterator to it if found, otherwise it returns an iterator to {@link HashMap.end end()}. + * + *

Two keys are considered equivalent if the properties' comparison object returns false reflexively + * (i.e., no matter the order in which the elements are passed as arguments).

+ * + * Another member function, {@link hasProperty hasProperty()} can be used to just check whether a particular + * key exists. + * + * ```xml + * {value} + * ``` + * + * @param key Key to be searched for + * @return An iterator to the element, if an element with specified key is found, or + * {@link end HashMap.end()} otherwise. + */ + findProperty(key: string): std.MapIterator; + /** + * Test whether a property exists. + * + * ```xml + * {value} + * ``` + * + * @return Whether a property has the *key* exists or not. + */ + hasProperty(key: string): boolean; + /** + * Get property. + * + * Get property by its *key*, property name. If the matched *key* does not exist, then exception + * {@link std.OutOfRange} is thrown. Thus, it would better to test whether the *key* exits or not by calling the + * {@link hasProperty hasProperty()} method before calling this {@link getProperty getProperty()}. + * + * This method can be substituted by {@link getPropertyMap getPropertyMap()} such below: + * - ```getPropertyMap().get(key, value);``` + * - ```getPropertyMap().find(key).second;``` + * + * ```xml + * {value} + * ``` + * + * @return Value of the matched property. + */ + getProperty(key: string): string; + /** + * Get property map. + * + * ```xml + * {value} + * ``` + * + * @return {@link HashMap} containing properties' keys and values. + */ + getPropertyMap(): std.HashMap; + /** + * Set tag. + * + * Set tag name, identifier of this {@link XML} object. + * + * If this {@link XML} object is belonged to, a child of, an {@link XMLList} and its related {@link XML} objects, + * then calling this {@link setTag setTag()} method direclty is not recommended. Erase this {@link XML} object + * from parent objects and insert this object again. + * + * ```xml + * {value} + * ``` + * + * @param val To be new {@link getTag tag}. + */ + setTag(val: string): void; + /** + * Set value. + * + * ```xml + * {VALUE} + * ``` + * + * @param val To be new {@link getValue value}. + */ + setValue(val: string): void; + /** + * Set property. + * + * Set a property *value* with its *key*. If the *key* already exists, then the *value* will be overwritten to + * the property. Otherwise the *key* is not exist yet, then insert the *key* and *value* {@link Pair pair} to + * {@link getPropertyMao property map}. + * + * This method can be substituted by {@link getPropertyMap getPropertyMap()} such below: + * - ```getPropertyMap().set(key, value);``` + * - ```getPropertyMap().emplace(key, value);``` + * - ```getPropertyMap().insert([key, value]);``` + * - ```getPropertyMap().insert(std.make_pair(key, value));``` + * + * ```xml + * {value} + * ``` + * + * @param key Key, identifier of property to be newly inserted. + * @param value Value of new property to be newly inserted. + */ + setProperty(key: string, value: string): void; + /** + * Erase property. + * + * Erases a property by its *key*, property name. If the matched *key* does not exist, then exception + * {@link std.OutOfRange} is thrown. Thus, it would better to test whether the *key* exits or not by calling the + * {@link hasProperty hasProperty()} method before calling this {@link eraseProperty eraseProperty()}. + * + * This method can be substituted by ``getPropertyMap().erase(key)````. + * + * ```xml + * {value} + * ``` + * + * @param key Key of the property to erase + * @throw {@link std.OutOfRange} + */ + eraseProperty(key: string): void; + /** + * @hidden + */ + push(...args: std.Pair[]): number; + /** + * @hidden + */ + push(...args: [string, XMLList][]): number; + push(...xmls: XML[]): number; + push(...xmlLists: XMLList[]): number; + /** + * Add all properties from other {@link XML} object. + * + * All the properties in the *obj* are copied to this {@link XML} object. If this {@link XML} object has same + * property key in the *obj*, then value of the property will be replaced to *obj*'s own. If you don't want to + * overwrite properties with same key, then use {@link getPropertyMap getPropertyMap()} method. + * + * ```typescript + * let x: library.XML; + * let y: library.XML; + * + * x.addAllProperties(y); // duplicated key exists, then overwrites + * x.getPropertyMap().insert(y.getPropertyMap().begin(), y.getPropertyMap().end()); + * // ducpliated key, then ignores. only non-duplicateds are copied. + * ``` + * + * ```xml + * {value} + * ``` + * + * @param obj Target {@link XML} object to copy properties. + */ + insertAllProperties(obj: XML): void; + /** + * Clear properties. + * + * Remove all properties. It's same with calling ```getPropertyMap().clear()```. + * + * ```xml + * {value} + * ``` + */ + clearProperties(): void; + /** + * @hidden + */ + private _Compute_min_index(...args); + /** + * @hidden + */ + private _Decode_value(str); + /** + * @hidden + */ + private _Encode_value(str); + /** + * @hidden + */ + private _Decode_property(str); + /** + * @hidden + */ + private _Encode_property(str); + /** + * {@link XML} object to xml string. + * + * Returns a string representation of the {@link XML} object. + * + * @param tab Number of tabs to spacing. + * @return The string representation of the {@link XML} object. + */ + toString(tab?: number): string; + } +} +declare namespace samchon.library { + /** + * List of {@link XML} objects with same tag. + * + * @reference http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XMLList.html + * @handbook https://github.com/samchon/framework/wiki/TypeScript-Library-XML + * @author Jeongho Nam + */ + class XMLList extends std.Deque { + /** + * Get tag. + */ + getTag(): string; + /** + * {@link XMLList XML objects} to string. + * + * Returns a string representation of the {@link XMLList XML objects}. + * + * @param tab Number of tabs to spacing. + * @return The string representation of the {@link XMLList XML objects}. + */ + toString(level?: number): string; + } +} +declare namespace samchon.protocol { + /** + * An interface of entity. + * + * Entity is a class for standardization of expression method using on network I/O by XML. If + * Invoke is a standard message protocol of Samchon Framework which must be kept, Entity is a + * recommended semi-protocol of message for expressing a data class. Following the semi-protocol + * Entity is not imposed but encouraged. + * + * As we could get advantages from standardization of message for network I/O with Invoke, + * we can get additional advantage from standardizing expression method of data class with Entity. + * We do not need to know a part of network communication. Thus, with the Entity, we can only + * concentrate on entity's own logics and relationships between another entities. Entity does not + * need to how network communications are being done. + * + * I say repeatedly. Expression method of Entity is recommended, but not imposed. It's a semi + * protocol for network I/O but not a essential protocol must be kept. The expression method of + * Entity, using on network I/O, is expressed by XML string. + * + * If your own network system has a critical performance issue on communication data class, + * it would be better to using binary communication (with ByteArray). + * Don't worry about the problem! Invoke also provides methods for binary data (ByteArray). + * + * ![Class Diagram](http://samchon.github.io/framework/images/design/ts_class_diagram/protocol_message_protocol.png) + * + * @author Jeongho Nam + */ + interface IEntity { + /** + * Construct data of the Entity from a XML object. + * + * Overrides the construct() method and fetch data of member variables from the XML. + * + * By recommended guidance, data representing member variables are contained in properties + * of the put XML object. + * + * @param xml An xml used to contruct data of entity. + */ + construct(xml: library.XML): void; + /** + * Get a key that can identify the Entity uniquely. + * + * If identifier of the Entity is not atomic value, returns a paired or tuple object + * that can represents the composite identifier. + * + * + * class Point extends Entity + * { + * private x: number; + * private y: number; + * + * public key(): std.Pair + * { + * return std.make_pair(this.x, this.y); + * } + * } + * + */ + key(): any; + /** + * A tag name when represented by XML. + * + * + */ + TAG(): string; + /** + * Get a XML object represents the Entity. + * + * A member variable (not object, but atomic value like number, string or date) is categorized + * as a property within the framework of entity side. Thus, when overriding a toXML() method and + * archiving member variables to an XML object to return, puts each variable to be a property + * belongs to only a XML object. + * + * Don't archive the member variable of atomic value to XML::value causing enormouse creation + * of XML objects to number of member variables. An Entity must be represented by only a XML + * instance (tag). + * + *

Standard Usage.

+ * + * + * + * + * + * + * + *

Non-standard usage abusing value.

+ * + * + * jhnam88 + * Jeongho Nam + * 1988-03-11 + * + * + * master + * Administartor + * 2011-07-28 + * + * + * + * @return An XML object representing the Entity. + */ + toXML(): library.XML; + } + /** + * @hidden + */ + namespace IEntity { + function construct(entity: IEntity, xml: library.XML, ...prohibited_names: string[]): void; + function toXML(entity: IEntity, ...prohibited_names: string[]): library.XML; + } + /** + * An entity, a standard data class. + * + * Entity is a class for standardization of expression method using on network I/O by XML. If + * Invoke is a standard message protocol of Samchon Framework which must be kept, Entity is a + * recommended semi-protocol of message for expressing a data class. Following the semi-protocol + * Entity is not imposed but encouraged. + * + * As we could get advantages from standardization of message for network I/O with Invoke, + * we can get additional advantage from standardizing expression method of data class with Entity. + * We do not need to know a part of network communication. Thus, with the Entity, we can only + * concentrate on entity's own logics and relationships between another entities. Entity does not + * need to how network communications are being done. + * + * I say repeatedly. Expression method of Entity is recommended, but not imposed. It's a semi + * protocol for network I/O but not a essential protocol must be kept. The expression method of + * Entity, using on network I/O, is expressed by XML string. + * + * If your own network system has a critical performance issue on communication data class, + * it would be better to using binary communication (with ByteArray). + * Don't worry about the problem! Invoke also provides methods for binary data (ByteArray). + * + * ![Class Diagram](http://samchon.github.io/framework/images/design/ts_class_diagram/protocol_message_protocol.png) + * + * @author Jeongho Nam + */ + abstract class Entity implements IEntity { + /** + * Default Constructor. + */ + constructor(); + construct(xml: library.XML): void; + /** + * @inheritdoc + */ + key(): any; + /** + * @inheritdoc + */ + abstract TAG(): string; + /** + * @inheritdoc + */ + toXML(): library.XML; + } +} +declare namespace samchon.protocol { + /** + * @inheritdoc + */ + interface IEntityCollection extends IEntityGroup, collections.ICollection { + } +} +declare namespace samchon.protocol { + /** + * @inheritdoc + */ + abstract class EntityArrayCollection extends collections.ArrayCollection implements IEntityCollection { + /** + * @inheritdoc + */ + construct(xml: library.XML): void; + /** + * @inheritdoc + */ + abstract createChild(xml: library.XML): T; + /** + * @inheritdoc + */ + key(): any; + /** + * @inheritdoc + */ + has(key: any): boolean; + /** + * @inheritdoc + */ + count(key: any): number; + /** + * @inheritdoc + */ + get(key: any): T; + /** + * @inheritdoc + */ + abstract TAG(): string; + /** + * @inheritdoc + */ + abstract CHILD_TAG(): string; + /** + * @inheritdoc + */ + toXML(): library.XML; + } +} +declare namespace samchon.protocol { + /** + * @inheritdoc + */ + abstract class EntityListCollection extends collections.ListCollection implements IEntityCollection { + /** + * @inheritdoc + */ + construct(xml: library.XML): void; + /** + * @inheritdoc + */ + abstract createChild(xml: library.XML): T; + /** + * @inheritdoc + */ + key(): any; + /** + * @inheritdoc + */ + has(key: any): boolean; + /** + * @inheritdoc + */ + count(key: any): number; + /** + * @inheritdoc + */ + get(key: any): T; + /** + * @inheritdoc + */ + abstract TAG(): string; + /** + * @inheritdoc + */ + abstract CHILD_TAG(): string; + /** + * @inheritdoc + */ + toXML(): library.XML; + } +} +declare namespace samchon.protocol { + /** + * @inheritdoc + */ + abstract class EntityDequeCollection extends collections.DequeCollection implements IEntityCollection { + /** + * @inheritdoc + */ + construct(xml: library.XML): void; + /** + * @inheritdoc + */ + abstract createChild(xml: library.XML): T; + /** + * @inheritdoc + */ + key(): any; + /** + * @inheritdoc + */ + has(key: any): boolean; + /** + * @inheritdoc + */ + count(key: any): number; + /** + * @inheritdoc + */ + get(key: any): T; + /** + * @inheritdoc + */ + abstract TAG(): string; + /** + * @inheritdoc + */ + abstract CHILD_TAG(): string; + /** + * @inheritdoc + */ + toXML(): library.XML; + } +} +/** + * A template for External Systems Manager. + * + * @handbook [Templates - External System](https://github.com/samchon/framework/wiki/TypeScript-Templates-External_System) + * @author Jeongho Nam + */ +declare namespace samchon.templates.external { + /** + * An array and manager of {@link ExternalSystem external system drivers}. + * + * The {@link ExternalSystemArray} is an abstract class containing and managing external system drivers, + * {@link ExternalSystem} objects. Within framewokr of network, {@link ExternalSystemArray} represents your system + * and children {@link ExternalSystem} objects represent remote, external systems connected with your system. + * With this {@link ExternalSystemArray}, you can manage multiple external systems as a group. + * + * You can specify this {@link ExternalSystemArray} class to be *a server accepting external clients* or + * *a client connecting to external servers*. Even both of them is also possible. + * + * - {@link ExternalClientArray}: A server accepting {@link ExternalSystem external clients}. + * - {@link ExternalServerArray}: A client connecting to {@link ExternalServer external servers}. + * - {@link ExternalServerClientArray}: Both of them. Accepts {@link ExternalSystem external clients} and connects to + * {@link ExternalServer external servers} at the same time. + * + * + * + * + * + * #### Proxy Pattern + * The {@link ExternalSystemArray} class can use *Proxy Pattern*. In framework within user, which + * {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not + * important. Only interested in user's perspective is *which can be done*. + * + * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged + * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. + * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. + * + *
    + *
  • + * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring + * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. + *
  • + *
  • + * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call + * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the + * external system. + *
  • + *
  • Those strategy is called *Proxy Pattern*.
  • + *
+ * + * @handbook [Templates - External System](https://github.com/samchon/framework/wiki/TypeScript-Templates-External_System) + * @author Jeongho Nam + */ + abstract class ExternalSystemArray extends protocol.EntityDequeCollection implements protocol.IProtocol { + /** + * Default Constructor. + */ + constructor(); + /** + * @hidden + */ + private _Handle_system_erase(event); + /** + * Test whether the role exists. + * + * @param name Name, identifier of target {@link ExternalSystemRole role}. + * + * @return Whether the role has or not. + */ + hasRole(name: string): boolean; + /** + * Get a role. + * + * @param name Name, identifier of target {@link ExternalSystemRole role}. + * + * @return The specified role. + */ + getRole(name: string): ExternalSystemRole; + /** + * Send an {@link Invoke} message. + * + * @param invoke An {@link Invoke} message to send. + */ + sendData(invoke: protocol.Invoke): void; + /** + * Handle an {@Invoke} message have received. + * + * @param invoke An {@link Invoke} message have received. + */ + abstract replyData(invoke: protocol.Invoke): void; + /** + * Tag name of the {@link ExternalSytemArray} in {@link XML}. + * + * @return *systemArray*. + */ + TAG(): string; + /** + * Tag name of {@link ExternalSystem children elements} belonged to the {@link ExternalSytemArray} in {@link XML}. + * + * @return *system*. + */ + CHILD_TAG(): string; + } +} +/** + * A template for Parallel Processing System. + * + * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System) + * @author Jeongho Nam + */ +declare namespace samchon.templates.parallel { + /** + * Master of Parallel Processing System. + * + * The {@link ParallelSystemArray} is an abstract class containing and managing remote parallel **slave** system + * drivers, {@link ParallelSystem} objects. Within framework of network, {@link ParallelSystemArray} represents your + * system, a **Master** of *Parallel Processing System* that requesting *parallel process* to **slave** systems and the + * children {@link ParallelSystem} objects represent the remote **slave** systems, who is being requested the + * *parallel processes*. + * + * You can specify this {@link ParallelSystemArray} class to be *a server accepting parallel clients* or + * *a client connecting to parallel servers*. Even both of them is possible. Extends one of them below and overrides + * abstract factory method(s) creating the child {@link ParallelSystem} object. + * + * - {@link ParallelClientArray}: A server accepting {@link ParallelSystem parallel clients}. + * - {@link ParallelServerArray}: A client connecting to {@link ParallelServer parallel servers}. + * - {@link ParallelServerClientArray}: Both of them. Accepts {@link ParallelSystem parallel clients} and connects to + * {@link ParallelServer parallel servers} at the same time. + * + * When you need the **parallel process**, then call one of them: {@link sendSegmentData} or {@link sendPieceData}. + * When the **parallel process** has completed, {@link ParallelSystemArray} estimates each {@link ParallelSystem}'s + * {@link ParallelSystem.getPerformance performance index} basis on their execution time. Those performance indices + * will be reflected to the next **parallel process**, how much pieces to allocate to each {@link ParallelSystem}. + * + * + * + * + * + * #### Proxy Pattern + * This class {@link ParallelSystemArray} is derived from the {@link ExternalSystemArray} class. Thus, you can take + * advantage of the *Proxy Pattern* in the {@link ParallelSystemArray} class. If a process to request is not the + * *parallel process* (to be distrubted to all slaves), but the **exclusive process** handled in a system, then it + * may better to utilizing the *Proxy Pattern*: + * + * The {@link ExternalSystemArray} class can use *Proxy Pattern*. In framework within user, which + * {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not + * important. Only interested in user's perspective is *which can be done*. + * + * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged + * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. + * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. + * + *
    + *
  • + * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring + * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. + *
  • + *
  • + * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call + * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the + * external system. + *
  • + *
  • Those strategy is called *Proxy Pattern*.
  • + *
+ * + * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System) + * @author Jeongho Nam + */ + abstract class ParallelSystemArray extends external.ExternalSystemArray { + /** + * @hidden + */ + private history_sequence_; + /** + * Default Constructor. + */ + constructor(); + /** + * Send an {@link Invoke} message with segment size. + * + * Sends an {@link Invoke} message requesting a **parallel process** with its *segment size*. The {@link Invoke} + * message will be delivered to children {@link ParallelSystem} objects with the *piece size*, which is divided + * from the *segment size*, basis on their {@link ParallelSystem.getPerformance performance indices}. + * + * - If segment size is 100, + * - The segment will be allocated such below: + * + * Name | Performance index | Number of pieces to be allocated | Formula + * --------|-------------------|----------------------------------|-------------- + * Snail | 1 | 10 | 100 / 10 * 1 + * Cheetah | 4 | 40 | 100 / 10 * 4 + * Rabbit | 3 | 30 | 100 / 10 * 3 + * Turtle | 2 | 20 | 100 / 10 * 2 + * + * When the **parallel process** has completed, then this {@link ParallelSystemArraY} will estimate + * {@link ParallelSystem.getPerformance performance indices} of {@link ParallelSystem} objects basis on their + * execution time. + * + * @param invoke An {@link Invoke} message requesting parallel process. + * @param size Number of pieces to segment. + * + * @return Number of {@link ParallelSystem slave systems} participating in the *Parallel Process*. + * + * @see {@link sendPieceData}, {@link ParallelSystem.getPerformacen} + */ + sendSegmentData(invoke: protocol.Invoke, size: number): number; + /** + * Send an {@link Invoke} message with range of pieces. + * + * Sends an {@link Invoke} message requesting a **parallel process** with its *range of pieces [first, last)*. + * The {@link Invoke} will be delivered to children {@link ParallelSystem} objects with the newly computed + * *range of sub-pieces*, which is divided from the *range of pieces (first to last)*, basis on their + * {@link ParallelSystem.getPerformance performance indices}. + * + * - If indices of pieces are 0 to 50, + * - The sub-pieces will be allocated such below: + * + * Name | Performance index | Range of sub-pieces to be allocated | Formula + * --------|-------------------|-------------------------------------|------------------------ + * Snail | 1 | ( 0, 5] | (50 - 0) / 10 * 1 + * Cheetah | 4 | ( 5, 25] | (50 - 0) / 10 * 4 + 5 + * Rabbit | 3 | (25, 40] | (50 - 0) / 10 * 3 + 25 + * Turtle | 2 | (40, 50] | (50 - 0) / 10 * 2 + 40 + * + * When the **parallel process** has completed, then this {@link ParallelSystemArraY} will estimate + * {@link ParallelSystem.getPerformance performance indices} of {@link ParallelSystem} objects basis on their + * execution time. + * + * @param invoke An {@link Invoke} message requesting parallel process. + * @param first Initial piece's index in a section. + * @param last Final piece's index in a section. The range used is [*first*, *last*), which contains + * all the pieces' indices between *first* and *last*, including the piece pointed by index + * *first*, but not the piece pointed by the index *last*. + * + * @return Number of {@link ParallelSystem slave systems} participating in the *Parallel Process*. + * + * @see {@link sendSegmentData}, {@link ParallelSystem.getPerformacen} + */ + sendPieceData(invoke: protocol.Invoke, first: number, last: number): number; + /** + * @hidden + */ + protected _Complete_history(history: slave.InvokeHistory): boolean; + /** + * @hidden + */ + protected _Normalize_performance(): void; + } +} +/** + * A template for Distributed Processing System. + * + * @handbook [Templates - Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) + * @author Jeongho Nam + */ +declare namespace samchon.templates.distributed { + /** + * Master of Distributed Processing System. + * + * The {@link DistributedSystemArray} is an abstract class containing and managing remote distributed **slave** system + * drivers, {@link DistributedSystem} objects. Within framework of network, {@link DistributedSystemArray} represents + * your system, a **Master** of *Distributed Processing System* that requesting *distributed process* to **slave** + * systems and the children {@link DistributedSystem} objects represent the remote **slave** systems, who is being + * requested the *distributed processes*. + * + * You can specify this {@link DistributedSystemArray} class to be *a server accepting distributed clients* or + * *a client connecting to distributed servers*. Even both of them is possible. Extends one of them below and overrides + * abstract factory method(s) creating the child {@link DistributedSystem} object. + * + * - {@link DistributedClientArray}: A server accepting {@link DistributedSystem distributed clients}. + * - {@link DistributedServerArray}: A client connecting to {@link DistributedServer distributed servers}. + * - {@link DistributedServerClientArray}: Both of them. Accepts {@link DistributedSystem distributed clients} and + * connects to {@link DistributedServer distributed servers} at the same time. + * + * The {@link DistributedSystemArray} contains {@link DistributedProcess} objects directly. You can request a + * **distributed process** through the {@link DistributedProcess} object. You can access the + * {@link DistributedProcess} object(s) with those methods: + * + * - {@link hasProcess} + * - {@link getProcess} + * - {@link insertProcess} + * - {@link eraseProcess} + * - {@link getProcessMap} + * + * When you need the **distributed process**, call the {@link DistributedProcess.sendData} method. Then the + * {@link DistributedProcess} will find the most idle {@link DistributedSystem} object who represents a distributed + * **slave **system. The {@link Invoke} message will be sent to the most idle {@link DistributedSystem} object. When + * the **distributed process** has completed, then {@link DistributedSystem.getPerformance performance index} and + * {@link DistributedProcess.getResource resource index} of related objects will be revaluated. + * + * + * + * + * + * #### Parallel Process + * This {@link DistributedSystemArray} class is derived from the {@link ParallelSystemArray} class, so you can request + * a **parallel process**, too. + * + * When you need the **parallel process**, then call one of them: {@link sendSegmentData} or {@link sendPieceData}. + * When the **parallel process** has completed, {@link ParallelSystemArray} estimates each {@link ParallelSystem}'s + * {@link ParallelSystem.getPerformance performance index} basis on their execution time. Those performance indices will + * be reflected to the next **parallel process**, how much pieces to allocate to each {@link ParallelSystem}. + * + * #### Proxy Pattern + * This class {@link DistributedSystemArray} is derived from the {@link ExternalSystemArray} class. Thus, you can take + * advantage of the *Proxy Pattern* in the {@link DistributedSystemArray} class. If a process to request is not the + * *parallel process* (to be distrubted to all slaves), but the **exclusive process** handled in a system, then it + * may better to utilizing the *Proxy Pattern*: + * + * The {@link ExternalSystemArray} class can use *Proxy Pattern*. In framework within user, which + * {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not + * important. Only interested in user's perspective is *which can be done*. + * + * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged + * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. + * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. + * + *
    + *
  • + * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring + * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. + *
  • + *
  • + * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call + * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the + * external system. + *
  • + *
  • Those strategy is called *Proxy Pattern*.
  • + *
+ * + * @handbook [Templates - Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) + * @author Jeongho Nam + */ + abstract class DistributedSystemArray extends parallel.ParallelSystemArray { + /** + * @hidden + */ + private process_map_; + /** + * Default Constructor. + */ + constructor(); + /** + * @inheritdoc + */ + construct(xml: library.XML): void; + /** + * Factory method creating a child {@link DistributedProcess process} object. + * + * @param xml {@link XML} represents the {@link DistributedProcess child} object. + * @return A new {@link DistributedProcess} object. + */ + protected abstract createProcess(xml: library.XML): DistributedProcess; + /** + * Get process map. + * + * Gets an {@link HashMap} containing {@link DistributedProcess} objects with their *key*. + * + * @return An {@link HasmMap> containing pairs of string and {@link DistributedProcess} object. + */ + getProcessMap(): std.HashMap; + /** + * Test whether the process exists. + * + * @param name Name, identifier of target {@link DistributedProcess process}. + * + * @return Whether the process has or not. + */ + hasProcess(name: string): boolean; + /** + * Get a process. + * + * @param name Name, identifier of target {@link DistributedProcess process}. + * + * @return The specified process. + */ + getProcess(name: string): DistributedProcess; + /** + * Insert a process. + * + * @param process A process to be inserted. + * @return Success flag. + */ + insertProcess(process: DistributedProcess): boolean; + /** + * Erase a process. + * + * @param name Name, identifier of target {@link DistributedProcess process}. + */ + eraseProcess(name: string): boolean; + /** + * @hidden + */ + protected _Complete_history(history: slave.InvokeHistory): boolean; + /** + * @hidden + */ + private estimate_process_resource(history); + /** + * @hidden + */ + private estimate_system_performance(history); + /** + * @hidden + */ + protected _Normalize_performance(): void; + /** + * @inheritdoc + */ + toXML(): library.XML; + } +} +declare namespace samchon.templates.distributed { + /** + * Mediator of Distributed Processing System. + * + * The {@link DistributedSystemArrayMediator} class be a master for its slave systems, and be a slave to its master + * system at the same time. This {@link DistributedSystemArrayMediator} be a master system, containing and managing + * {@link DistributedSystem} objects, which represent distributed slave systems, by extending + * {@link DistributedSystemArray} class. Also, be a slave system through {@link getMediator mediator} object, which is + * derived from the {@link SlaveSystem} class. + * + * As a master, you can specify this {@link DistributedSystemArrayMediator} class to be a master server accepting + * slave clients or a master client to connecting slave servers. Even both of them is possible. Extends one + * of them below and overrides abstract factory method(s) creating the child {@link DistributedSystem} object. + * + * - {@link DistributedClientArrayMediator}: A server accepting {@link DistributedSystem distributed clients}. + * - {@link DistributedServerArrayMediator}: A client connecting to {@link DistributedServer distributed servers}. + * - {@link DistributedServerClientArrayMediator}: Both of them. Accepts {@link DistributedSystem distributed clients} and + * connects to {@link DistributedServer distributed servers} at the same time. + * + * As a slave, you can specify this {@link DistributedSystemArrayMediator} to be a client slave connecting to master + * server or a server slave accepting master client by overriding the {@link createMediator} method. + * Overrides the {@link createMediator createMediator()} method and return one of them: + * + * - A client slave connecting to master server: + * - {@link MediatorClient} + * - {@link MediatorWebClient} + * - {@link MediatorSharedWorkerClient} + * - A server slave accepting master client: + * - {@link MediatorServer} + * - {@link MediatorWebServer} + * - {@link MediatorDedicatedWorkerServer} + * - {@link MediatorSharedWorkerServer} + * + * #### [Inherited] {@link DistributedSystemArray} + * @copydoc DistributedSystemArray + */ + abstract class DistributedSystemArrayMediator extends DistributedSystemArray { + /** + * @hidden + */ + private mediator_; + /** + * Default Constructor. + */ + constructor(); + /** + * Factory method creating a {@link MediatorSystem} object. + * + * The {@link createMediator createMediator()} is an abstract method creating the {@link MediatorSystem} object. + * + * You know what? this {@link DistributedSystemArrayMediator} class be a master for its slave systems, and be a + * slave to its master system at the same time. The {@link MediatorSystem} object makes it possible; be a slave + * system. This {@link createMediator} determines specific type of the {@link MediatorSystem}. + * + * Overrides the {@link createMediator createMediator()} method to create and return one of them following which + * protocol and which type of remote connection (server or client) will be used: + * + * - A client slave connecting to master server: + * - {@link MediatorClient} + * - {@link MediatorWebClient} + * - {@link MediatorSharedWorkerClient} + * - A server slave accepting master client: + * - {@link MediatorServer} + * - {@link MediatorWebServer} + * - {@link MediatorDedicatedWorkerServer} + * - {@link MediatorSharedWorkerServer} + * + * @return A newly created {@link MediatorSystem} object. + */ + protected abstract createMediator(): parallel.MediatorSystem; + /** + * Start mediator. + * + * If the {@link getMediator mediator} is a type of server, then opens the server accepting master client. + * Otherwise, the {@link getMediator mediator} is a type of client, then connects the master server. + */ + protected startMediator(): void; + /** + * Get {@link MediatorSystem} object. + * + * When you need to send an {@link Invoke} message to the master system of this + * {@link DistributedSystemArrayMediator}, then send to the {@link MediatorSystem} through this + * {@link getMediator}. + * + * ```typescript + * this.getMediator().sendData(...); + * ``` + * + * @return The {@link MediatorSystem} object. + */ + getMediator(): parallel.MediatorSystem; + /** + * @hidden + */ + protected _Complete_history(history: slave.InvokeHistory): boolean; + } +} +declare namespace samchon.protocol { + /** + * @hidden + */ + namespace socket { + type socket = any; + type server = any; + type http_server = any; + } + /** + * @hidden + */ + namespace websocket { + type connection = any; + type request = any; + type IMessage = any; + type ICookie = any; + type client = any; + } +} +declare namespace samchon.protocol { + /** + * @hidden + */ + abstract class _CommunicatorBase implements ICommunicator { + /** + * @hidden + */ + protected listener_: IProtocol; + /** + * @inheritdoc + */ + onClose: Function; + /** + * @hidden + */ + protected connected_: boolean; + /** + * @hidden + */ + private binary_invoke_; + /** + * @hidden + */ + private binary_parameters_; + /** + * @hidden + */ + private unhandled_invokes_; + /** + * Default Constructor. + */ + constructor(); + /** + * Construct from *listener*. + * + * @param listener An {@link IProtocol} object to listen {@link Invoke} messages. + */ + constructor(listener: IProtocol); + /** + * @inheritdoc + */ + abstract close(): void; + /** + * @inheritdoc + */ + isConnected(): boolean; + /** + * @hidden + */ + protected _Is_binary_invoke(): boolean; + /** + * @inheritdoc + */ + abstract sendData(invoke: Invoke): void; + /** + * @inheritdoc + */ + replyData(invoke: Invoke): void; + /** + * @hidden + */ + protected _Handle_string(str: string): void; + /** + * @hidden + */ + protected _Handle_binary(binary: Uint8Array): void; + } +} +declare namespace samchon.protocol { + /** + * A communicator following Samchon Framework's own protocol. + * + * {@link Communicator} is an abstract class following Samchon Framework's own protocol. This {@link Communicator} + * class is specified to {@link ServerConnector} and {@link ClientDriver} whether the remote system is a server (that + * my system is connecting to) or a client (a client conneting to to my server). + * + * Note that, if one of this or remote system is web-browser based, then you don't have to use this + * {@link Communicator} class who follows Samchon Framework's own protocol. Web-browser supports only Web-socket + * protocol. Thus in that case, you have to use {@link WebCommunicator} instead. + * + * #### [Inherited] {@link ICommunicator} + * @copydoc ICommunicator + */ + abstract class Communicator extends _CommunicatorBase { + /** + * @hidden + */ + protected socket_: socket.socket; + /** + * @hidden + */ + private header_bytes_; + /** + * @hidden + */ + private data_; + /** + * @hidden + */ + private data_index_; + /** + * @hidden + */ + private listening_; + /** + * @inheritdoc + */ + close(): void; + /** + * @hidden + */ + protected _Start_listen(): void; + /** + * @hidden + */ + private _Handle_error(); + /** + * @hidden + */ + private _Handle_close(); + /** + * @inheritdoc + */ + sendData(invoke: Invoke): void; + /** + * @hidden + */ + private _Listen_piece(piece); + /** + * @hidden + */ + private _Listen_header(piece, piece_index); + /** + * @hidden + */ + private _Listen_data(piece, piece_index); + } +} +declare namespace samchon.protocol { + /** + * Communicator with remote client. + * + * {@link ClientDriver} is a class taking full charge of network communication with remote client who follows Samchon + * Framework's own protocol. This {@link ClientDriver} object is always created by {@link Server} class. When you got + * this {@link ClientDriver} object from the {@link Server.addClient Server.addClient()}, then specify + * {@link IProtocol listener} with the {@link ClientDriver.listen ClientDriver.listen()} method. + * + * #### [Inherited] {@link IClientDriver} + * @copydoc IClientDriver + */ + class ClientDriver extends Communicator implements IClientDriver { + /** + * Construct from a socket. + */ + constructor(socket: socket.socket); + /** + * @inheritdoc + */ + listen(listener: IProtocol): void; + } +} +declare namespace samchon.protocol { + /** + * A communicator for shared worker. + * + * {@link DedicatedWorkerCommunicator} is an abstract class for communication between DedicatedWorker and Web-browser. + * This {@link DedicatedWorkerCommunicator} is specified to {@link DedicatedWorkerServerConnector} and + * {@link DedicatedWorkerClientDriver} whether the remote system is a server (that my system is connecting to) or a + * client (a client conneting to to my server). + * + * #### Why DedicatedWorker be a server? + * In JavaScript environment, there's no way to implement multi-threading function. Instead, JavaScript supports the + * **Worker**, creating a new process. However, the **Worker** does not shares memory addresses. To integrate the + * **Worker** with its master, only communication with string or binary data is allowed. Doesn't it seem like a network + * communication? Furthermore, there's not any difference between the worker communication and network communication. + * It's the reason why Samchon Framework considers the **Worker** as a network node. + * + * The class {@link DedicatedWorkerCommunicator} is designed make such relationship. From now on, DedicatedWorker is a + * {@link DedicatedWorkerServer server} and {@link DedicatedWorkerServerConnector browser} is a client. Integrate the + * server and clients with this {@link DedicatedWorkerCommunicator}. + * + * #### [Inherited] {@link ICommunicator} + * @copydoc ICommunicator + */ + abstract class DedicatedWorkerCommunicator extends _CommunicatorBase { + /** + * @hidden + */ + protected _Handle_message(event: MessageEvent): void; + } +} +declare namespace samchon.protocol { + /** + * Communicator with master web-browser. + * + * {@link DedicatedWorkerClientDriver} is a class taking full charge of network communication with web browsers. This + * {@link DedicatedWorkerClientDriver} object is always created by {@link DedicatedWorkerServer} class. When you got + * this {@link DedicatedWorkerClientDriver} object from + * {@link DedicatedWorkerServer.addClient DedicatedWorkerServer.addClient()}, then specify {@link IProtocol listener} + * with the {@link DedicatedWorkerClientDriver.listen DedicatedWorkerClientDriver.listen()} method. + * + * #### Why DedicatedWorker be a server? + * In JavaScript environment, there's no way to implement multi-threading function. Instead, JavaScript supports the + * **Worker**, creating a new process. However, the **Worker** does not shares memory addresses. To integrate the + * **Worker** with its master, only communication with string or binary data is allowed. Doesn't it seem like a network + * communication? Furthermore, there's not any difference between the worker communication and network communication. + * It's the reason why Samchon Framework considers the **Worker** as a network node. + * + * The class {@link DedicatedWorkerCommunicator} is designed make such relationship. From now on, DedicatedWorker is a + * {@link DedicatedWorkerServer server} and {@link DedicatedWorkerServerConnector browser} is a client. Integrate the + * server and clients with this {@link DedicatedWorkerCommunicator}. + * + * #### [Inherited] {@link IClientDriver} + * @copydoc IClientDriver + */ + class DedicatedWorkerClientDriver extends DedicatedWorkerCommunicator implements IClientDriver { + /** + * Default Constructor. + */ + constructor(); + /** + * @inheritdoc + */ + listen(listener: IProtocol): void; + /** + * @inheritdoc + */ + close(): void; + /** + * @inheritdoc + */ + sendData(invoke: Invoke): void; + } +} +declare namespace samchon.protocol { + /** + * A communicator for shared worker. + * + * {@link SharedWorkerCommunicator} is an abstract class for communication between SharedWorker and Web-browser. This + * {@link SharedWorkerCommunicator} is specified to {@link SharedWorkerServerConnector} and + * {@link SharedWorkerClientDriver} whether the remote system is a server (that my system is connecting to) or a client + * (a client conneting to to my server). + * + * Note that, SharedWorker is a conception only existed in web-browser. This {@link SharedWorkerCommunicator} is not + * supported in NodeJS. Only web-browser environment can utilize this {@link SharedWorkerCommunicator}. + * + * #### Why SharedWorker be a server? + * SharedWorker, it allows only an instance (process) to be created whether the SharedWorker is declared in a browser + * or multiple browsers. To integrate them, messages are being sent and received. Doesn't it seem like a relationship + * between a server and clients? Thus, Samchon Framework consider the SharedWorker as a server and browsers as + * clients. + * + * The class {@link SharedWorkerCommunicator} is designed make such relationship. From now on, SharedWorker is a + * {@link SharedWorkerServer server} and {@link SharedWorkerServerConnector browsers} are clients. Integrate the + * server and clients with this {@link SharedWorkerCommunicator}. + * + * #### [Inherited] {@link ICommunicator} + * @copydoc ICommunicator + */ + abstract class SharedWorkerCommunicator extends _CommunicatorBase { + /** + * @hidden + */ + protected port_: MessagePort; + /** + * @inheritdoc + */ + close(): void; + /** + * @inheritdoc + */ + sendData(invoke: Invoke): void; + /** + * @hidden + */ + protected _Handle_message(event: MessageEvent): void; + } +} +declare namespace samchon.protocol { + /** + * Communicator with remote web-browser. + * + * {@link SharedWorkerClientDriver} is a class taking full charge of network communication with web browsers. This + * {@link SharedWorkerClientDriver} object is always created by {@link SharedWorkerServer} class. When you got this + * {@link SharedWorkerClientDriver} object from {@link SharedWorkerServer.addClient SharedWorkerServer.addClient()}, + * then specify {@link IProtocol listener} with the + * {@link SharedWorkerClientDriver.listen SharedWorkerClientDriver.listen()} method. + * + * #### Why SharedWorker be a server? + * SharedWorker, it allows only an instance (process) to be created whether the SharedWorker is declared in a browser + * or multiple browsers. To integrate them, messages are being sent and received. Doesn't it seem like a relationship + * between a server and clients? Thus, Samchon Framework consider the SharedWorker as a server and browsers as + * clients. + * + * The class {@link SharedWorkerCommunicator} is designed make such relationship. From now on, SharedWorker is a + * {@link SharedWorkerServer server} and {@link SharedWorkerServerConnector browsers} are clients. Integrate the + * server and clients with this {@link SharedWorkerCommunicator}. + * + * #### [Inherited] {@link IClientDriver} + * @copydoc IClientDriver + */ + class SharedWorkerClientDriver extends SharedWorkerCommunicator implements IClientDriver { + /** + * @hidden + */ + private listening_; + /** + * Construct from a MessagePort object. + */ + constructor(port: MessagePort); + /** + * @inheritdoc + */ + listen(listener: IProtocol): void; + } +} +declare namespace samchon.protocol { + /** + * A communicator following Web-socket protocol. + * + * {@link WebCommunicator} is an abstract class following Web-socket protocol. This {@link WebCommunicator} class is + * specified to {@link WebServerConnector} and {@link WebClientDriver} whether the remote system is a server (that my + * system is connecting to) or a client (a client conneting to to my server). + * + * Note that, one of this or remote system is web-browser based, then there's not any alternative choice. Web browser + * supports only Web-socket protocol. In that case, you've use this {@link WebCommunicator} class. + * + * #### [Inherited] {@link ICommunicator} + * @copydoc ICommunicator + */ + abstract class WebCommunicator extends _CommunicatorBase { + /** + * @hidden + */ + protected connection_: websocket.connection; + /** + * @inheritdoc + */ + close(): void; + /** + * @inheritdoc + */ + sendData(invoke: Invoke): void; + /** + * @hidden + */ + protected _Handle_message(message: websocket.IMessage): void; + /** + * @hidden + */ + protected _Handle_close(): void; + } +} +declare namespace samchon.protocol { + /** + * Communicator with remote web-client. + * + * {@link WebClientDriver} is a class taking full charge of network communication with remote client who follows + * Web-socket protocol. This {@link WebClientDriver} object is always created by {@link WebServer} class. When you + * got this {@link WebClientDriver} object from the {@link WebServer.addClient WebServer.addClient()}, then specify + * {@link IProtocol listener} with the {@link WebClientDriver.listen WebClientDriver.listen()} method. + * + * Unlike other protocol, Web-socket protocol's clients notify two parameters on their connection; + * {@link getSessionID session-id} and {@link getPath path}. The {@link getSessionID session-id} can be used to + * identify *user* of each client, and the {@link getPath path} can be used which type of *service* that client wants. + * In {@link service} module, you can see the best utilization case of them. + * - {@link service.User}: utlization of the {@link getSessionID session-id}. + * - {@link service.Service}: utilization of the {@link getPath path}. + * + * #### [Inherited] {@link IClientDriver} + * @copydoc IClientDriver + */ + class WebClientDriver extends WebCommunicator implements IClientDriver { + /** + * @hidden + */ + private path_; + /** + * @hidden + */ + private session_id_; + /** + * @hidden + */ + private listening_; + /** + * Initialization Constructor. + * + * @param connection Connection driver, a socket for web-socket. + * @param path Requested path. + * @param session_id Session ID, an identifier of the remote client. + */ + constructor(connection: websocket.connection, path: string, session_id: string); + /** + * @inheritdoc + */ + listen(listener: IProtocol): void; + /** + * Get requested path. + */ + getPath(): string; + /** + * Get session ID, an identifier of the remote client. + */ + getSessionID(): string; + } +} +declare namespace samchon.protocol { + /** + * An interface for communicator with remote client. + * + * {@link IClientDriver} is a type of {@link ICommunicator}, specified for communication with remote client who has + * connected in a {@link IServer server}. It takes full charge of network communication with the remote client. + * + * The {@link IClientDriver} object is created and delivered from {@link IServer} and + * {@link IServer.addClient IServer.addClient()}. Those are derived types from this {@link IClientDriver}, being + * created by the matched {@link IServer} object. + * + * Protocol | Derived Type | Created By + * ------------------------|-------------------------------------|---------------------------- + * Samchon Framework's own | {@link ClientDriver} | {@link Server} + * Web-socket protocol | {@link WebClientDriver} | {@link WebServer} + * DedicatedWorker | {@link DedicatedWorkerClinetDriver} | {@link DedicatedWorkerServer} + * SharedWorker | {@link SharedWorkerClientDriver} | {@link SharedWorkerServer} + * + * When you've got an {@link IClientDriver} object from the {@link IServer.addClient IServer.addClient()}, then + * specify {@link IProtocol listener} with {@link IClient.listen IClient.listen()}. Whenever a replied message comes + * from the remote system, the message will be converted to an {@link Invoke} class and the {@link Invoke} object + * will be shifted to the {@link IProtocol listener}'s {@link IProtocol.replyData IProtocol.replyData()} method. + * Below code is an example specifying and managing the {@link IProtocol listener} objects. + * + * - https://github.com/samchon/framework-examples/blob/master/calculator/calculator-server.ts + * + * + * + * + * + * @see {@link IServer}, {@link IProtocol} + * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#iclientdriver) + * @author Jeongho Nam + */ + interface IClientDriver extends ICommunicator { + /** + * Listen message from the newly connected client. + * + * Starts listening message from the newly connected client. Replied message from the connected client will be + * converted to {@link Invoke} classes and shifted to the *listener*'s {@link IProtocol.replyData replyData()} + * method. + * + * @param listener A listener object to listen replied message from newly connected client in + * {@link IProtocol.replyData replyData()} as an {@link Invoke} object. + */ + listen(listener: IProtocol): void; + } +} +declare namespace samchon.protocol { + /** + * An interface taking full charge of network communication. + * + * {@link ICommunicator} is an interface for communicator classes who take full charge of network communication with + * remote system, without reference to whether the remote system is a server or a client. Type of the + * {@link ICommunicator} is specified to {@link IServerConnector} and {@link IClientDriver} whether the remote system + * is a server (that I've to connect) or a client (a client connected to my server). + * + * Whenever a replied message comes from the remote system, the message will be converted to an {@link Invoke} class + * and the {@link Invoke} object will be shifted to the {@link IProtocol listener}'s + * {@link IProtocol.replyData IProtocol.replyData()} method. + * + * + * + * + * + * @see {@link IClientDriver}, {@link IServerConnector}, {@link IProtocol} + * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#icommunicator) + * @author Jeongho Nam + */ + interface ICommunicator extends IProtocol { + /** + * Callback function for connection closed. + */ + onClose: Function; + /** + * Close connection. + */ + close(): void; + /** + * Test connection. + * + * Test whether this {@link ICommunicator communicator} object is connected with the remote system. If the + * connection is alive, then returns ```true```. Otherwise, the connection is not alive or this + * {@link ICommunicator communicator has not connected with the remote system yet, then returns ```false```. + * + * @return true if connected, otherwise false. + */ + isConnected(): boolean; + /** + * Send message. + * + * Send {@link Invoke} message to remote system. + * + * @param invoke An {@link Invoke} message to send. + */ + sendData(invoke: protocol.Invoke): void; + /** + * Handle replied message. + * + * Handles replied {@link Invoke} message recived from remove system. The {@link Invoke} message will be shifted + * to the {@link IProtocol listener}'s {@link IProtocol.replyData IProtocol.replyData()} by this method. + * + * @param invoke An {@link Invoke} message received from remote system. + */ + replyData(invoke: protocol.Invoke): void; + } +} +declare namespace samchon.protocol { + /** + * An interface for server connector. + * + * {@link IServerConnector} is a type of {@link ICommunicator}, specified for server connector classes who connect to + * the remote server as a client. {@link IServerConnector} provides {@link connect connection method} and takes full + * charge of network communication with the remote server. + * + * Declare specific type of {@link IServerConnector} from {@link IProtocol listener} and call the + * {@link connect connect()} method. Then whenever a replied message comes from the remote system, the message will + * be converted to an {@link Invoke} object and the {@link Invoke} object will be shifted to the + * {@link IProtocol listener}'s {@link IProtocol.replyData IProtocol.replyData()} method. Below code is an example + * connecting to remote server and interacting with it. + * + * - https://github.com/samchon/framework-examples/blob/master/calculator/calculator-application.ts + * + * Note that, protocol of this client and remote server must be matched. Thus, before determining specific type of + * this {@link IServerConnector}, you've to consider which protocol and type the remote server follows. + * + * Protocol | Derived Type | Connect to + * ------------------------|----------------------------------------|------------------------------- + * Samchon Framework's own | {@link ServerConnector} | {@link Server} + * Web-socket protocol | {@link WebServerConnector} | {@link WebServer} + * DedicatedWorker | {@link DedicatedWorkerServerConnector} | {@link DedicatedWorkerServer} + * SharedWorker | {@link SharedWorkerServerConnector} | {@link SharedWorkerServer} + * + * ![Class Diagram](http://samchon.github.io/framework/images/design/ts_class_diagram/protocol_basic_components.png) + * + * @see {@link IServer}, {@link IProtocol} + * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#iserverconnector) + * @author Jeongho Nam + */ + interface IServerConnector extends ICommunicator { + /** + * Callback function for connection completed. + * + * When you call {@link connect connect()} and the connection has completed, then this call back function + * {@link onConnect} will be called. Note that, if the listener of this {@link onConnect} is a member method of + * some class, then you've use the ```bind```. + */ + onConnect: Function; + /** + * Connect to a server. + * + * Connects to a server with specified *host* address and *port* number. After the connection has + * succeeded, callback function {@link onConnect} is called. Listening data from the connected server also begins. + * Replied messages from the connected server will be converted to {@link Invoke} classes and will be shifted to + * the {@link WebCommunicator.listener listener}'s {@link IProtocol.replyData replyData()} method. + * + * If the connection fails immediately, either an event is dispatched or an exception is thrown: an error + * event is dispatched if a host was specified, and an exception is thrown if no host was specified. Otherwise, + * the status of the connection is reported by an event. If the socket is already connected, the existing + * connection is closed first. + * + * @param ip The name or IP address of the host to connect to. + * If no host is specified, the host that is contacted is the host where the calling file resides. + * If you do not specify a host, use an event listener to determine whether the connection was + * successful. + * @param port The port number to connect to. + */ + connect(ip: string, port: number): void; + } +} +declare namespace samchon.protocol { + /** + * A server connector for DedicatedWorker. + * + * {@link DedicatedWorkerServerConnector} is a class connecting to SharedWorker and taking full charge of network + * communication with the SharedWorker. Create an {@link DedicatedWorkerServer} instance from the + * {@IProtocol listener} and call the {@link connect connect()} method. + * + * #### Why DedicatedWorker be a server? + * In JavaScript environment, there's no way to implement multi-threading function. Instead, JavaScript supports the + * **Worker**, creating a new process. However, the **Worker** does not shares memory addresses. To integrate the + * **Worker** with its master, only communication with string or binary data is allowed. Doesn't it seem like a network + * communication? Furthermore, there's not any difference between the worker communication and network communication. + * It's the reason why Samchon Framework considers the **Worker** as a network node. + * + * The class {@link DedicatedWorkerCommunicator} is designed make such relationship. From now on, DedicatedWorker is a + * {@link DedicatedWorkerServer server} and {@link DedicatedWorkerServerConnector browser} is a client. Integrate the + * server and clients with this {@link DedicatedWorkerCommunicator}. + * + * #### [Inherited] {@link IServerConnector} + * @copydoc IServerConnector + */ + class DedicatedWorkerServerConnector extends DedicatedWorkerCommunicator implements IServerConnector { + /** + * @hidden + */ + private worker_; + /** + * @inheritdoc + */ + onConnect: Function; + /** + * Construct from *listener*. + * + * @param listener A listener object to listen replied message from newly connected client in + * {@link IProtocol.replyData replyData()} as an {@link Invoke} object. + */ + constructor(listener: IProtocol); + /** + * @inheritdoc + */ + connect(jsFile: string): void; + /** + * @inheritdoc + */ + close(): void; + /** + * @inheritdoc + */ + sendData(invoke: Invoke): void; + } +} +declare namespace samchon.protocol { + /** + * Server connnector. + * + * {@link ServerConnector} is a class connecting to remote server who follows Samchon Framework's own protocol and + * taking full charge of network communication with the remote server. Create a {@link ServerConnector} instance from + * the {@IProtocol listener} and call the {@link connect connect()} method. + * + * #### [Inherited] {@link IServerConnector} + * @copydoc IServerConnector + */ + class ServerConnector extends Communicator implements IServerConnector { + /** + * @inheritdoc + */ + onConnect: Function; + /** + * Construct from *listener*. + * + * @param listener A listener object to listen replied message from newly connected client in + * {@link IProtocol.replyData replyData()} as an {@link Invoke} object. + */ + constructor(listener: IProtocol); + /** + * @inheritdoc + */ + connect(ip: string, port: number): void; + /** + * @hidden + */ + private _Handle_connect(...arg); + /** + * @hidden + */ + private _Send_dummy_packet_repeatedly(); + } +} +declare namespace samchon.protocol { + /** + * A server connector for SharedWorker. + * + * {@link SharedWorkerServerConnector} is a class connecting to SharedWorker and taking full charge of network + * communication with the SharedWorker. Create an {@link SharedWorkerServerConnector} instance from the + * {@IProtocol listener} and call the {@link connect connect()} method. + * + * #### Why SharedWorker be a server? + * SharedWorker, it allows only an instance (process) to be created whether the SharedWorker is declared in a browser + * or multiple browsers. To integrate them, messages are being sent and received. Doesn't it seem like a relationship + * between a server and clients? Thus, Samchon Framework consider the SharedWorker as a server and browsers as + * clients. + * + * The class {@link SharedWorkerCommunicator} is designed make such relationship. From now on, SharedWorker is a + * {@link SharedWorkerServer server} and {@link SharedWorkerServerConnector browsers} are clients. Integrate the + * server and clients with this {@link SharedWorkerCommunicator}. + * + * #### [Inherited] {@link IServerConnector} + * @copydoc IServerConnector + */ + class SharedWorkerServerConnector extends SharedWorkerCommunicator implements IServerConnector { + /** + * @inheritdoc + */ + onConnect: Function; + /** + * Construct from *listener*. + * + * @param listener A listener object to listen replied message from newly connected client in + * {@link IProtocol.replyData replyData()} as an {@link Invoke} object. + */ + constructor(listener: IProtocol); + /** + * Connect to a SharedWorker. + * + * Connects to a server with specified *jstFile* path. If a SharedWorker instance of the *jsFile* is not + * constructed yet, then the SharedWorker will be newly constructed. Otherwise the SharedWorker already exists, + * then connect to the SharedWorker. After those processes, callback function {@link onConnect} is called. + * Listening data from the connected server also begins. Replied messages from the connected server will be + * converted to {@link Invoke} classes and will be shifted to the {@link WebCommunicator.listener listener}'s + * {@link IProtocol.replyData replyData()} method. + * + * If the connection fails immediately, either an event is dispatched or an exception is thrown: an error + * event is dispatched if a host was specified, and an exception is thrown if no host was specified. Otherwise, + * the status of the connection is reported by an event. If the socket is already connected, the existing + * connection is closed first. + * + * @param jsFile Path of JavaScript file to execute who defines SharedWorker. + */ + connect(jsFile: string): void; + } +} +declare namespace samchon.protocol { + /** + * A server connector for web-socket protocol. + * + * {@link WebServerConnector} is a class connecting to remote server who follows Web-socket protocol and taking full + * charge of network communication with the remote server. Create an {@link WebServerConnector} instance from the + * {@IProtocol listener} and call the {@link connect connect()} method. + * + * #### [Inherited] {@link IServerConnector} + * @copydoc IServerConnector + */ + class WebServerConnector extends WebCommunicator implements IServerConnector { + /** + * @hidden + */ + private browser_socket_; + /** + * @hidden + */ + private node_client_; + /** + * @inheritdoc + */ + onConnect: Function; + /** + * Construct from *listener*. + * + * @param listener A listener object to listen replied message from newly connected client in + * {@link IProtocol.replyData replyData()} as an {@link Invoke} object. + */ + constructor(listener: IProtocol); + /** + * Connect to a web server. + * + * Connects to a server with specified *host* address, *port* number and *path*. After the connection has + * succeeded, callback function {@link onConnect} is called. Listening data from the connected server also begins. + * Replied messages from the connected server will be converted to {@link Invoke} classes and will be shifted to + * the {@link WebCommunicator.listener listener}'s {@link IProtocol.replyData replyData()} method. + * + * If the connection fails immediately, either an event is dispatched or an exception is thrown: an error + * event is dispatched if a host was specified, and an exception is thrown if no host was specified. Otherwise, + * the status of the connection is reported by an event. If the socket is already connected, the existing + * connection is closed first. + * + * @param ip The name or IP address of the host to connect to. + * If no host is specified, the host that is contacted is the host where the calling file resides. + * If you do not specify a host, use an event listener to determine whether the connection was + * successful. + * @param port The port number to connect to. + * @param path Path of service which you want. + */ + connect(ip: string, port: number, path?: string): void; + /** + * @inheritdoc + */ + close(): void; + /** + * @inheritdoc + */ + sendData(invoke: Invoke): void; + /** + * @hidden + */ + private _Handle_browser_connect(event); + /** + * @hidden + */ + private _Handle_browser_message(event); + /** + * @hidden + */ + private _Handle_node_connect(connection); + } +} +declare namespace samchon.protocol { + /** + * A container of entity, and it's a type of entity, too. + * + * ![Class Diagram](http://samchon.github.io/framework/images/design/ts_class_diagram/protocol_message_protocol.png) + * + * @handbook [Protocol - Standard Message](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Standard_Message) + * @author Jeongho Nam + */ + interface IEntityGroup extends IEntity, std.base.Container { + /** + * Construct data of the Entity from an XML object. + * + * Constructs the EntityArray's own member variables only from the input XML object. + * + * Do not consider about constructing children Entity objects' data in EntityArray::construct(). + * Those children Entity objects' data will constructed by their own construct() method. Even insertion + * of XML objects representing children are done by abstract method of EntityArray::toXML(). + * + * Constructs only data of EntityArray's own. + */ + construct(xml: library.XML): void; + /** + * Factory method of a child Entity. + * + * EntityArray::createChild() is a factory method creating a new child Entity which is belonged + * to the EntityArray. This method is called by EntityArray::construct(). The children construction + * methods Entity::construct() will be called by abstract method of the EntityArray::construct(). + * + * @return A new child Entity belongs to EntityArray. + */ + createChild(xml: library.XML): T; + /** + * Get iterator to element. + * + * Searches the container for an element with a identifier equivalent to *key* and returns an + * iterator to it if found, otherwise it returns an iterator to {@link end end()}. + * + * Two keys are considered equivalent if the container's comparison object returns false reflexively + * (i.e., no matter the order in which the elements are passed as arguments). + * + * Another member functions, {@link has has()} and {@link count count()}, can be used to just check + * whether a particular *key* exists. + * + * @param key Key to be searched for + * @return An iterator to the element, if an element with specified *key* is found, or + * {@link end end()} otherwise. + */ + /** + * Whether have the item or not. + * + * Indicates whether a map has an item having the specified identifier. + * + * @param key Key value of the element whose mapped value is accessed. + * + * @return Whether the map has an item having the specified identifier. + */ + has(key: any): boolean; + /** + * Count elements with a specific key. + * + * Searches the container for elements whose key is *key* and returns the number of elements found. + * + * @param key Key value to be searched for. + * + * @return The number of elements in the container with a *key*. + */ + count(key: any): number; + /** + * Get an element + * + * Returns a reference to the mapped value of the element identified with *key*. + * + * @param key Key value of the element whose mapped value is accessed. + * + * @throw exception out of range + * + * @return A reference object of the mapped value (_Ty) + */ + get(key: any): T; + /** + * A tag name of children objects. + */ + CHILD_TAG(): string; + /** + * Get an XML object represents the EntityArray. + * + * Archives the EntityArray's own member variables only to the returned XML object. + * + * Do not consider about archiving children Entity objects' data in EntityArray::toXML(). + * Those children Entity objects will converted to XML object by their own toXML() method. The + * insertion of XML objects representing children are done by abstract method of + * EntityArray::toXML(). + * + * Archives only data of EntityArray's own. + */ + toXML(): library.XML; + } + /** + * @hidden + */ + namespace IEntityGroup { + /** + * @hidden + */ + function construct(entityGroup: IEntityGroup, xml: library.XML, ...prohibited_names: string[]): void; + /** + * @hidden + */ + function toXML(group: IEntityGroup, ...prohibited_names: string[]): library.XML; + function has(entityGroup: IEntityGroup, key: any): boolean; + function count(entityGroup: IEntityGroup, key: any): number; + function get(entityGroup: IEntityGroup, key: any): T; + } +} +declare namespace samchon.protocol { + /** + * @inheritdoc + */ + abstract class EntityArray extends std.Vector implements IEntityGroup { + /** + * @inheritdoc + */ + construct(xml: library.XML): void; + /** + * @inheritdoc + */ + abstract createChild(xml: library.XML): T; + /** + * @inheritdoc + */ + key(): any; + /** + * @inheritdoc + */ + has(key: any): boolean; + /** + * @inheritdoc + */ + count(key: any): number; + /** + * @inheritdoc + */ + get(key: any): T; + /** + * @inheritdoc + */ + abstract TAG(): string; + /** + * @inheritdoc + */ + abstract CHILD_TAG(): string; + /** + * @inheritdoc + */ + toXML(): library.XML; + } +} +declare namespace samchon.protocol { + /** + * @inheritdoc + */ + abstract class EntityList extends std.List implements IEntityGroup { + /** + * @inheritdoc + */ + construct(xml: library.XML): void; + /** + * @inheritdoc + */ + abstract createChild(xml: library.XML): T; + /** + * @inheritdoc + */ + key(): any; + /** + * @inheritdoc + */ + has(key: any): boolean; + /** + * @inheritdoc + */ + count(key: any): number; + /** + * @inheritdoc + */ + get(key: any): T; + /** + * @inheritdoc + */ + abstract TAG(): string; + /** + * @inheritdoc + */ + abstract CHILD_TAG(): string; + /** + * @inheritdoc + */ + toXML(): library.XML; + } +} +declare namespace samchon.protocol { + /** + * @inheritdoc + */ + abstract class EntityDeque extends std.Deque implements IEntityGroup { + /** + * @inheritdoc + */ + construct(xml: library.XML): void; + /** + * @inheritdoc + */ + abstract createChild(xml: library.XML): T; + /** + * @inheritdoc + */ + key(): any; + /** + * @inheritdoc + */ + has(key: any): boolean; + /** + * @inheritdoc + */ + count(key: any): number; + /** + * @inheritdoc + */ + get(key: any): T; + /** + * @inheritdoc + */ + abstract TAG(): string; + /** + * @inheritdoc + */ + abstract CHILD_TAG(): string; + /** + * @inheritdoc + */ + toXML(): library.XML; + } +} +declare namespace samchon.protocol { + /** + * Standard message of network I/O. + * + * {@link Invoke} is a class used in network I/O in protocol package of Samchon Framework. + * + * The Invoke message has an XML structure like the result screen of provided example in below. + * We can enjoy lots of benefits by the normalized and standardized message structure used in + * network I/O. + * + * The greatest advantage is that we can make any type of network system, even how the system + * is enourmously complicated. As network communication message is standardized, we only need to + * concentrate on logical relationships between network systems. We can handle each network system + * like a object (class) in OOD. And those relationships can be easily designed by using design + * pattern. + * + * In Samchon Framework, you can make any type of network system with basic componenets + * (IProtocol, IServer and ICommunicator) by implemens or inherits them, like designing + * classes of S/W architecture. + * + * ![Class Diagram](http://samchon.github.io/framework/images/design/ts_class_diagram/protocol_message_protocol.png) + * + * @see {@link IProtocol} + * @author Jeongho Nam + */ + class Invoke extends EntityArray { + /** + * Listener, represent function's name. + */ + private listener; + /** + * Default Constructor. + */ + constructor(); + constructor(listener: string); + /** + * Copy Constructor. + * + * @param invoke + */ + constructor(invoke: Invoke); + /** + * Construct from listener and parametric values. + * + * @param listener + * @param parameters + */ + constructor(listener: string, ...parameters: Array); + /** + * @inheritdoc + */ + createChild(xml: library.XML): InvokeParameter; + /** + * Get listener. + */ + getListener(): string; + /** + * Get arguments for Function.apply(). + * + * @return An array containing values of the contained parameters. + */ + getArguments(): Array; + /** + * Apply to a matched function. + * + * @param obj Target object to find matched function. + * @return Whether succeded to find matched function. + */ + apply(obj: Object): boolean; + /** + * Apply to a function. + * + * @param thisArg Owner of the function. + * @param func Function to call. + */ + apply(thisArg: Object, func: Function): void; + /** + * @inheritdoc + */ + TAG(): string; + /** + * @inheritdoc + */ + CHILD_TAG(): string; + } +} +declare namespace samchon.protocol { + /** + * A parameter belongs to an Invoke. + * + * ![Class Diagram](http://samchon.github.io/framework/images/design/ts_class_diagram/protocol_message_protocol.png) + * + * @author Jeongho Nam + */ + class InvokeParameter extends Entity { + /** + * Name of the parameter. + * + * @details Optional property, can be omitted. + */ + protected name: string; + /** + * Type of the parameter. + */ + protected type: string; + /** + * Value of the parameter. + */ + protected value: boolean | number | string | library.XML | Uint8Array; + /** + * Default Constructor. + */ + constructor(); + constructor(val: boolean); + constructor(val: number); + constructor(val: string); + constructor(val: library.XML); + constructor(val: Uint8Array); + /** + * Construct from variable name and number value. + * + * @param name + * @param val + */ + constructor(name: string, val: boolean); + constructor(name: string, val: number); + constructor(name: string, val: string); + constructor(name: string, val: library.XML); + constructor(name: string, val: Uint8Array); + /** + * @inheritdoc + */ + construct(xml: library.XML): void; + setValue(value: boolean): void; + setValue(value: number): void; + setValue(value: string): void; + setValue(value: library.XML): void; + setValue(value: Uint8Array): void; + /** + * @inheritdoc + */ + key(): any; + /** + * Get name. + */ + getName(): string; + /** + * Get type. + */ + getType(): string; + /** + * Get value. + */ + getValue(): any; + /** + * @inheritdoc + */ + TAG(): string; + /** + * @inheritdoc + */ + toXML(): library.XML; + } +} +declare namespace samchon.protocol { + /** + * An interface for {@link Invoke} message chain. + * + * {@link IProtocol} is an interface for {@link Invoke} message, which is standard message of network I/O in + * *Samchon Framework*, chain. The {@link IProtocol} interface is used to network drivers and some classes which are + * in a relationship of *Chain of Responsibility Pattern* with those network drivers. + * + * Implements {@link IProtocol} if the class sends and handles {@link Invoke} messages. Looking around source codes of + * the *Samchon Framework*, especially *Templates*, you can find out that all the classes and modules handling + * {@link Invoke} messages are always implementing this {@link IProtocol}. + * + * + * + * + * + * @see {@link Invoke} + * @handbook https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#iprotocol + * @author Jeongho Nam + */ + interface IProtocol { + /** + * Sending message. + * + * Sends message to related system or shifts the responsibility to chain. + * + * @param invoke Invoke message to send + */ + replyData(invoke: Invoke): void; + /** + * Handling replied message. + * + * Handles replied message or shifts the responsibility to chain. + * + * @param invoke An {@link Invoke} message has received. + */ + sendData(invoke: Invoke): void; + } +} +declare namespace samchon.protocol { + /** + * A DeidcatedWorker server. + * + * The {@link DedicatedWorkerServer} is an abstract class is realized to open a DedicatedWorker server and accept + * web-browser client (master). Extends this {@link DedicatedWorkerServer} class and overrides + * {@link addClient addClient()} method to define what to do with a newly connected + * {@link DedicatedWorkerClientDriver remote client}. + * + * #### Why DedicatedWorker be a server? + * In JavaScript environment, there's no way to implement multi-threading function. Instead, JavaScript supports the + * **Worker**, creating a new process. However, the **Worker** does not shares memory addresses. To integrate the + * **Worker** with its master, only communication with string or binary data is allowed. Doesn't it seem like a network + * communication? Furthermore, there's not any difference between the worker communication and network communication. + * It's the reason why Samchon Framework considers the **Worker** as a network node. + * + * The class {@link DedicatedWorkerCommunicator} is designed make such relationship. From now on, DedicatedWorker is a + * {@link DedicatedWorkerServer server} and {@link DedicatedWorkerServerConnector browser} is a client. Integrate the + * server and clients with this {@link DedicatedWorkerCommunicator}. + * + * #### [Inherited] {@link IServer} + * @copydoc IServer + */ + abstract class DedicatedWorkerServer implements IServer { + /** + * @inheritdoc + */ + abstract addClient(driver: DedicatedWorkerClientDriver): void; + /** + * @inheritdoc + */ + open(): void; + /** + * @inheritdoc + */ + close(): void; + } +} +declare namespace samchon.protocol { + /** + * A substitute {@link DedicatedWorkerServer}. + * + * The {@link DedicatedWorkerServerBase} is a substitute class who subrogates {@link DedicatedWorkerServer}'s + * responsibility. + * + * #### [Inherited] {@link IServerBase} + * @copydoc IServerBase + */ + class DedicatedWorkerServerBase extends DedicatedWorkerServer implements IServerBase { + /** + * @hidden + */ + private hooker_; + /** + * Construct from a *hooker*. + * + * @param hooker A hooker throwing responsibility of server's role. + */ + constructor(hooker: IServer); + /** + * @inheritdoc + */ + addClient(driver: IClientDriver): void; + } +} +declare namespace samchon.protocol { + /** + * An interface for substitute server classes. + * + * {@link IServerBase} is an interface for substitue server classes who subrogate server's role. + * + * The easiest way to defining a server class is to extending one of them below, who implemented the {@link IServer}. + * However, it is impossible (that is, if the class is already extending another class), you can instead implement + * the {@link IServer} interface, create an {@link IServerBase} member, and write simple hooks to route calls into + * the aggregated {@link IServerBase}. + * + * Protocol | {@link IServer} | {@link IServerBase} | {@link IClientDriver} + * ------------------------|-------------------------------|-----------------------------------|------------------------------------- + * Samchon Framework's own | {@link Server} | {@link ServerBase} | {@link ClientDriver} + * Web-socket protocol | {@link WebServer} | {@link WebServerBase} | {@link WebClientDriver} + * DedicatedWorker | {@link DedicatedWorkerServer} | {@link DedicatedWorkerServerBase} | {@link DedicatedWorkerClientDriver} + * SharedWorker | {@link SharedWorkerServer} | {@link SharedWorkerServerBase} | {@link SharedWorkerClientDriver} + * + * After the hooking to aggregated {@link IServerBase} object, overrides {@link addClient addClient()} method who + * accepts a newly connected client as an {@link IClientDriver} object. At last, call {@link open open()} method with + * specified port number. + * + * ```typescript + * class MyServer extends Something implements IServer + * { + * private server_base_: IServerBase = new WebServerBase(this); + * + * public addClient(driver: IClientDriver): void + * { + * // WHAT TO DO WHEN A CLIENT HAS CONNECTED + * } + * + * public open(port: number): void + * { + * this.server_base_.open(); + * } + * public close(): void + * { + * this.server_base_.close(); + * } + * } + * ``` + * + * + * + * + * + * @see {@link IServer}, {@link IClientDriver} + * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#iserverbase) + * @author Jeongho Nam + */ + interface IServerBase extends IServer { + } +} +declare namespace samchon.protocol { + /** + * A server. + * + * The {@link Server} is an abstract class designed to open a server and accept clients who are following Samchon + * Framework's own protocol. Extends this {@link Server} class and overrides {@link addClient addClient()} method to + * define what to do with newly connected {@link ClientDriver remote clients}. + * + * #### [Inherited] {@link IServer} + * @copydoc Server + */ + abstract class Server implements IServer { + /** + * @hidden + */ + private net_driver_; + /** + * @inheritdoc + */ + abstract addClient(driver: ClientDriver): void; + /** + * @inheritdoc + */ + open(port: number): void; + /** + * @inheritdoc + */ + close(): void; + /** + * @hidden + */ + private _Handle_connect(socket); + } +} +declare namespace samchon.protocol { + /** + * A substitute {@link Server}. + * + * The {@link ServerBase} is a substitute class who subrogates {@link Server}'s responsibility. + * + * #### [Inherited] {@link IServerBase} + * @copydoc IServerBase + */ + class ServerBase extends Server implements IServerBase { + /** + * @hidden + */ + private hooker_; + /** + * Construct from a *hooker*. + * + * @param hooker A hooker throwing responsibility of server's role. + */ + constructor(hooker: IServer); + /** + * @inheritdoc + */ + addClient(driver: IClientDriver): void; + } +} +declare namespace samchon.protocol { + /** + * A SharedWorker server. + * + * The {@link SharedWorker} is an abstract class is realized to open a SharedWorker server and accept web-browser + * clients. Extends this {@link SharedWorkerServer} class and overrides {@link addClient addClient()} method to + * define what to do with newly connected {@link SharedWorkerClientDriver remote clients}. + * + * #### Why SharedWorker be a server? + * SharedWorker, it allows only an instance (process) to be created whether the SharedWorker is declared in a browser + * or multiple browsers. To integrate them, messages are being sent and received. Doesn't it seem like a relationship + * between a server and clients? Thus, Samchon Framework consider the SharedWorker as a server and browsers as + * clients. + * + * The class {@link SharedWorkerCommunicator} is designed make such relationship. From now on, SharedWorker is a + * {@link SharedWorkerServer server} and {@link SharedWorkerServerConnector browsers} are clients. Integrate the + * server and clients with this {@link SharedWorkerCommunicator}. + * + * #### [Inherited] {@link IServer} + * @copydoc IServer + */ + abstract class SharedWorkerServer implements IServer { + /** + * @inheritdoc + */ + abstract addClient(driver: SharedWorkerClientDriver): void; + /** + * @inheritdoc + */ + open(): void; + /** + * @inheritdoc + */ + close(): void; + /** + * @hidden + */ + private _Handle_connect(event); + } +} +declare namespace samchon.protocol { + /** + * A substitute {@link SharedWorkerServer}. + * + * The {@link SharedWorkerServerBase} is a substitute class who subrogates {@link SharedWorkerServer}'s + * responsibility. + * + * #### [Inherited] {@link IServerBase} + * @copydoc IServerBase + */ + class SharedWorkerServerBase extends SharedWorkerServer implements IServerBase { + /** + * @hidden + */ + private hooker_; + /** + * Construct from a *hooker*. + * + * @param hooker A hooker throwing responsibility of server's role. + */ + constructor(hooker: IServer); + /** + * @inheritdoc + */ + addClient(driver: IClientDriver): void; + } +} +declare namespace samchon.protocol { + /** + * A web server. + * + * The {@link WebServer} is an abstract class designed to open a server and accept clients who are following + * web-socket protocol. Extends this {@link WebServer} class and overrides {@link addClient addClient()} method to + * define what to do with newly connected {@link WebClientDriver remote clients}. + * + * #### [Inherited] {@link IServer} + * @copydoc IServer + */ + abstract class WebServer implements IServer { + /** + * @hidden + */ + private http_server_; + /** + * @hidden + */ + private sequence_; + /** + * @hidden + */ + private my_port_; + /** + * Default Constructor. + */ + constructor(); + /** + * @inheritdoc + */ + abstract addClient(driver: WebClientDriver): void; + /** + * @inheritdoc + */ + open(port: number): void; + /** + * @inheritdoc + */ + close(): void; + /** + * @hidden + */ + private _Handle_request(request); + /** + * @hidden + */ + private _Fetch_session_id(cookies); + /** + * @hidden + */ + private _Issue_session_id(); + } +} +declare namespace samchon.protocol { + /** + * A substitute {@link WebServer}. + * + * The {@link WebServerBase} is a substitute class who subrogates {@link WebServer}'s responsibility. + * + * #### [Inherited] {@link IServerBase} + * @copydoc IServerBase + */ + class WebServerBase extends WebServer implements IServerBase { + /** + * @hidden + */ + private hooker_; + /** + * Construct from a *hooker*. + * + * @param hooker A hooker throwing responsibility of server's role. + */ + constructor(hooker: IServer); + /** + * @inheritdoc + */ + addClient(driver: IClientDriver): void; + } +} +declare namespace samchon.protocol { + /** + * An interface for a server. + * + * {@link IServer} is an interfaec for server classes who are providing methods for {@link open opening a server} and + * {@link IClientDriver accepting clients}. + * + * To open a server, extends one of derived class under below considedring which protocol to follow first. At next, + * overrides {@link addClient addClient()} method who accepts a newly connected client as an {@link IClientDriver} + * object. Then at last, call {@link open open()} method with specified port number. + * + * Protocol | Derived Type | Related {@link IClientDriver} + * ------------------------|-------------------------------|------------------------------------- + * Samchon Framework's own | {@link Server} | {@link ClientDriver} + * Web-socket protocol | {@link WebServer} | {@link WebClientDriver} + * DedicatedWorker | {@link DedicatedWorkerServer} | {@link DedicatedWorkerClientDriver} + * SharedWorker | {@link SharedWorkerServer} | {@link SharedWorkerClientDriver} + * + * Below codes and classes will be good examples for comprehending how to open a server and handle remote clients. + * - https://github.com/samchon/framework-examples/blob/master/calculator/calculator-server.ts + * - https://github.com/samchon/framework-examples/blob/master/chat-server/server.ts + * - {@link service.Server} + * - {@link external.ExternalClientArray} + * - {@link slave.SlaveServer} + * + * If you're embarrased because your class already extended another one, then use {@link IServerBase}. + * + * + * + * + * + * @see {@link IClientDriver}, {@link IServerBase} + * @handbook [Protocol - Basic Components](https://github.com/samchon/framework/wiki/TypeScript-Protocol-Basic_Components#iserver) + * @author Jeongho Nam + */ + interface IServer { + /** + * Open server. + * + * @param port Port number to open. + */ + open(port: number): void; + /** + * Close server. + * + * Close opened server. All remote clients, have connected with this server, are also closed and their call back + * functions, for closed connection, {@link IClientDriver.onClose} are also called. + */ + close(): void; + /** + * Add a newly connected remote client. + * + * The {@link addClient addClient()} is an abstract method being called when a remote client is newly connected + * with {@link IClientDriver} object who communicates with the remote system. Overrides this method and defines + * what to do with the *driver*, a newly connected remote client. + * + * Below methods and example codes may be good for comprehending how to utilize this {@link addClient} method. + * + * - https://github.com/samchon/framework-examples/blob/master/calculator/calculator-server.ts + * - https://github.com/samchon/framework-examples/blob/master/chat-server/server.ts + * - {@link service.Server.addClient} + * - {@link external.ExternalClientArray.addClient} + * - {@link slave.SlaveServer.addClient} + * + * @param driver A {@link ICommunicator communicator} with (newly connected) remote client. + */ + addClient(driver: IClientDriver): void; + } +} +declare namespace samchon.templates.distributed { + /** + * Master of Distributed Processing System, a server accepting slave clients. + * + * The {@link DistributedClientArray} is an abstract class, derived from the {@link DistributedSystemArray} class, + * opening a server accepting {@link DistributedSystem distributed clients}. + * + * Extends this {@link DistributedClientArray}, overrides {@link createServerBase createServerBase()} to determine + * which protocol to follow and {@link createExternalClient createExternalClient()} creating child + * {@link DistributedSystem} object. After the extending and overridings, open this server using the + * {@link open open()} method. + * + * #### [Inherited] {@link DistributedSystemArray} + * @copydoc DistributedSystemArray + */ + abstract class DistributedClientArray extends DistributedSystemArray implements external.IExternalClientArray { + /** + * @hidden + */ + private server_base_; + /** + * Default Constructor. + */ + constructor(); + /** + * Factory method creating {@link IServerBase} object. + * + * This method {@link createServerBase createServerBase()} determines which protocol is used in this server, + * {@link ExternalClientArray}. If the protocol is determined, then {@link ExternalSystem external clients} who + * may connect to {@link ExternalClientArray this server} must follow the specified protocol. + * + * Overrides the {@link createServerBase createServerBase()} method to create and return one of them: + * + * - {@link ServerBase} + * - {@link WebServerBase} + * - {@link SharedWorkerServerBase} + * + * @return A new {@link IServerBase} object. + */ + protected abstract createServerBase(): protocol.IServerBase; + /** + * Add a newly connected remote client. + * + * When a {@link IClientDriver remote client} connects to this *master server of parallel processing system*, + * then this {@link ParallelClientArray} creates a child {@link ParallelSystem parallel client} object through + * the {@link createExternalClient createExternalClient()} method and {@link insert inserts} it. + * + * @param driver A communicator for external client. + */ + addClient(driver: protocol.IClientDriver): void; + /** + * (Deprecated) Factory method creating child object. + * + * The method {@link createChild createChild()} is deprecated. Don't use and override this. + * + * Note that, the {@link ParallelClientArray} is a server accepting {@link ParallelSystem parallel clients}. + * There's no way to creating the {@link ParallelSystem parallel clients} in advance before opening the server. + * + * @param xml An {@link XML} object represents the child {@link ParallelSystem} object. + * @return ```null``` + */ + createChild(xml: library.XML): System; + /** + * Factory method creating {@link DistributedSystem} object. + * + * The method {@link createExternalClient createExternalClient()} is a factory method creating a child + * {@link ParallelSystem} object, that is called whenever a parallel client has connected, by + * {@link addClient addClient()}. + * + * Overrides this {@link createExternalClient} method and creates a type of {@link DistributedSystem} object with + * the *driver* that communicates with the parallel client. After the creation, returns the object. Then whenever + * a parallel client has connected, matched {@link DistributedSystem} object will be constructed and + * {@link insert inserted} into this {@link DistributedSystemArray} object. + * + * @param driver A communicator with the parallel client. + * @return A newly created {@link ParallelSystem} object. + */ + protected abstract createExternalClient(driver: protocol.IClientDriver): System; + /** + * @inheritdoc + */ + open(port: number): void; + /** + * @inheritdoc + */ + close(): void; + } +} +declare namespace samchon.templates.distributed { + /** + * Mediator of Distributed Processing System, a server accepting slave clients. + * + * The {@link DistributedClientArrayMediator} is an abstract class, derived from {@link DistributedSystemArrayMediator} + * class, opening a server accepting {@link DistributedSystem distributed clients} as a **master**. + * + * Extends this {@link DistributedClientArrayMediator}, overrides {@link createServerBase createServerBase()} to + * determine which protocol to follow and {@link createExternalClient createExternalClient()} creating child + * {@link DistributedSystem} object. After the extending and overridings, open this server using the + * {@link open open()} method. + * + * #### [Inherited] {@link DistributedSystemArrayMediator} + * @copydoc DistributedSystemArrayMediator + */ + abstract class DistributedClientArrayMediator extends DistributedSystemArrayMediator implements external.IExternalClientArray { + /** + * A subrogator of {@link IServer server}'s role instead of this {@link ExternalClientArray}. + */ + private server_base_; + /** + * Default Constructor. + */ + constructor(); + /** + * Factory method creating {@link IServerBase} object. + * + * This method {@link createServerBase createServerBase()} determines which protocol is used in this + * {@link DistributedClientArrayMediator} object as a **master**. If the protocol is determined, then + * {@link DistributedSystem distributed clients} who may connect to {@link DistributedClientArrayMediator this + * server} must follow the specified protocol. + * + * Overrides the {@link createServerBase createServerBase()} method to create and return one of them: + * + * - {@link ServerBase} + * - {@link WebServerBase} + * - {@link SharedWorkerServerBase} + * + * @return A new {@link IServerBase} object. + */ + protected abstract createServerBase(): protocol.IServerBase; + /** + * Add a newly connected remote client. + * + * When a {@link IClientDriver remote client} connects to this *master server of distributed processing system*, + * then this {@link DistributedClientArrayMediator} creates a child {@link Distributed distributed client} object + * through the {@link createExternalClient createExternalClient()} method. + * + * @param driver A communicator for external client. + */ + addClient(driver: protocol.IClientDriver): void; + /** + * (Deprecated) Factory method creating child object. + * + * The method {@link createChild createChild()} is deprecated. Don't use and override this. + * + * Note that, the {@link DistributedClientArrayMediator} is a server accepting {@link DistributedSystem distributed + * clients} as a master. There's no way to creating the {@link DistributedSystem distributed clients} in advance + * before opening the server. + * + * @param xml An {@link XML} object represents the child {@link DistributedSystem} object. + * @return null + */ + createChild(xml: library.XML): System; + /** + * Factory method creating {@link DistributedSystem} object. + * + * The method {@link createExternalClient createExternalClient()} is a factory method creating a child + * {@link DistributedSystem} object, that is called whenever a distributed client has connected, by + * {@link addClient addClient()}. + * + * Overrides this {@link createExternalClient} method and creates a type of {@link DistributedSystem} object with + * the *driver* that communicates with the distributed client. After the creation, returns the object. Then whenever + * a distributed client has connected, matched {@link DistributedSystem} object will be constructed and + * {@link insert inserted} into this {@link DistributedClientArrayMediator} object. + * + * @param driver A communicator with the distributed client. + * @return A newly created {@link DistributedSystem} object. + */ + protected abstract createExternalClient(driver: protocol.IClientDriver): System; + /** + * @inheritdoc + */ + open(port: number): void; + /** + * @inheritdoc + */ + close(): void; + } +} +declare namespace samchon.templates.external { + /** + * An external system driver. + * + * The {@link ExternalSystem} class represents an external system, connected and interact with this system. + * {@link ExternalSystem} takes full charge of network communication with the remote, external system have connected. + * Replied {@link Invoke} messages from the external system is shifted to and processed in, children elements of this + * class, {@link ExternalSystemRole} objects. + * + * + * + * + * + * #### Bridge & Proxy Pattern + * The {@link ExternalSystem} class can be a *bridge* for *logical proxy*. In framework within user, + * which {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not + * important. Only interested in user's perspective is *which can be done*. + * + * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged + * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. + * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. + * + *
    + *
  • + * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring + * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. + *
  • + *
  • + * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call + * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the + * external system. + *
  • + *
  • Those strategy is called *Bridge Pattern* and *Proxy Pattern*.
  • + *
+ * + * @handbook [Templates - External System](https://github.com/samchon/framework/wiki/TypeScript-Templates-External_System) + * @author Jeongho Nam + */ + abstract class ExternalSystem extends protocol.EntityDequeCollection implements protocol.IProtocol { + /** + * The name represents external system have connected. + */ + protected name: string; + /** + * @hidden + */ + private system_array_; + /** + * @hidden + */ + private communicator_; + /** + * Construct from parent {@link ExternalSystemArray}. + * + * @param systemArray The parent {@link ExternalSystemArray} object. + */ + constructor(systemArray: ExternalSystemArray); + /** + * Constrct from parent {@link ExternalSystemArray} and communicator. + * + * @param systemArray The parent {@link ExternalSystemArray} object. + * @param communicator Communicator with the remote, external system. + */ + constructor(systemArray: ExternalSystemArray, communicator: protocol.IClientDriver); + /** + * Default Destructor. + * + * This {@link destructor destructor()} method is called when the {@link ExternalSystem} object is destructed and + * the {@link ExternalSystem} object is destructed when connection with the remote system is closed or this + * {@link ExternalSystem} object is {@link ExternalSystemArray.erase erased} from its parent + * {@link ExternalSystemArray} object. + * + * Note that, don't call this {@link destructor destructor()} method by yourself. It must be called automatically + * by those *destruction* cases. Also, if your derived {@link ExternalSystem} class has something to do on the + * *destruction*, then overrides this {@link destructor destructor()} method and defines the something to do. + * Overriding this {@link destructor destructor()}, don't forget to calling ```super.destructor();``` on tail. + * + * ```typescript + * class SomeSystem extends templates.external.ExternalSystem + * { + * protected destructor(): void + * { + * // DO SOMETHING + * this.do_something(); + * + * // CALL SUPER.DESTRUCTOR() ON TAIL. DON'T FORGET THIS + * super.destructor(); + * } + * } + * ``` + */ + protected destructor(): void; + /** + * @hidden + */ + private _Handle_close(); + /** + * Get parent {@link ExternalSystemArray} object. + */ + getSystemArray(): ExternalSystemArray; + /** + * Get parent {@link ExternalSystemArray} object. + */ + getSystemArray>(): SystemArray; + /** + * Identifier of {@link ExternalSystem} is its {@link name}. + * + * @return name. + */ + key(): string; + /** + * Get {@link name}. + */ + getName(): string; + /** + * @hidden + */ + /** + * @hidden + */ + protected communicator: protocol.ICommunicator; + /** + * Close connection. + */ + close(): void; + /** + * Send {@link Invoke} message to external system. + * + * @param invoke An {@link Invoke} message to send. + */ + sendData(invoke: protocol.Invoke): void; + /** + * Handle an {@Invoke} message has received. + * + * @param invoke An {@link Invoke} message have received. + */ + replyData(invoke: protocol.Invoke): void; + /** + * Tag name of the {@link ExternalSystem} in {@link XML}. + * + * @return *system*. + */ + TAG(): string; + /** + * Tag name of {@link ExternalSystemRole children elements} belonged to the {@link ExternalSystem} in {@link XML}. + * + * @return *role*. + */ + CHILD_TAG(): string; + } +} +declare namespace samchon.templates.parallel { + /** + * A driver for a parallel slave system. + * + * The {@link ParallelSystem} is an abstract class represents a **slave** system in *Parallel Processing System*, + * connected with this **master** system. This {@link ParallelSystem} takes full charge of network communication with + * the remote, parallel **slave** system has connected. + * + * When a *parallel process* is requested (by {@link ParallelSystemArray.sendSegmentData} or + * {@link ParallelSystemArray.sendPieceData}), the number of pieces to be allocated to a {@link ParallelSystem} is + * turn on its {@link getPerformance performance index}. Higher {@link getPerformance performance index}, then + * more pieces are requested. The {@link getPerformance performance index} is revaluated whenever a *parallel process* + * has completed, basic on the execution time and number of pieces. You can sugguest or enforce the + * {@link getPerformance performance index} with {@link setPerformance} or {@link enforcePerformance}. + * + * + * + * + * + * #### Bridge & Proxy Pattern + * This class {@link ParallelSystem} is derived from the {@link ExternalSystem} class. Thus, you can take advantage + * of the *Bridge & Proxy Pattern* in this {@link ParallelSystem} class. If a process to request is not the + * *parallel process* (to be distrubted to all slaves), but the **exclusive process** handled in a system, then it + * may better to utilizing the *Bridge & Proxy Pattern*: + * + * The {@link ExternalSystem} class can be a *bridge* for *logical proxy*. In framework within user, + * which {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not + * important. Only interested in user's perspective is *which can be done*. + * + * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged + * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. + * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. + * + *
    + *
  • + * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring + * from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}. + *
  • + *
  • + * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call + * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the + * external system. + *
  • + *
  • Those strategy is called *Bridge Pattern* and *Proxy Pattern*.
  • + *
+ * + * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System) + * @author Jeongho Nam + */ + abstract class ParallelSystem extends external.ExternalSystem { + /** + * @hidden + */ + private progress_list_; + /** + * @hidden + */ + private history_list_; + /** + * @hidden + */ + private exclude_; + /** + * @hidden + */ + private performance; + /** + * @hidden + */ + private enforced_; + /** + * Construct from parent {@link ParallelSystemArray}. + * + * @param systemArray The parent {@link ParallelSystemArray} object. + */ + constructor(systemArray: ParallelSystemArray); + /** + * Construct from parent {@link ParallelSystemArray} and communicator. + * + * @param systemArray The parent {@link ParallelSystemArray} object. + * @param communicator A communicator communicates with remote, the external system. + */ + constructor(systemArray: ParallelSystemArray, communicator: protocol.IClientDriver); + /** + * Default Destructor. + * + * This {@link destructor destructor()} method is called when the {@link ParallelSystem} object is destructed and + * the {@link ParallelSystem} object is destructed when connection with the remote system is closed or this + * {@link ParallelSystem} object is {@link ParallelSystemArray.erase erased} from its parent + * {@link ParallelSystemArray} object. + * + * You may think if there're some *parallel processes* have requested but not completed yet, then it would be a + * critical problem because the *parallel processes* will not complete forever. Do not worry. The critical problem + * does not happen. After the destruction, the remained *parallel processes* will be shifted to and proceeded in + * other {@link ParallelSystem} objects. + * + * Note that, don't call this {@link destructor destructor()} method by yourself. It must be called automatically + * by those *destruction* cases. Also, if your derived {@link ParallelSystem} class has something to do on the + * *destruction*, then overrides this {@link destructor destructor()} method and defines the something to do. + * Overriding this {@link destructor destructor()}, don't forget to calling ```super.destructor();``` on tail. + * + * ```typescript + * class SomeSystem extends protocol.external.ExternalSystem + * { + * protected destructor(): void + * { + * // DO SOMETHING + * this.do_something(); + * + * // CALL SUPER.DESTRUCTOR() ON TAIL. DON'T FORGET THIS + * super.destructor(); + * } + * } + * ``` + */ + protected destructor(): void; + /** + * Get manager of this object. + * + * @return The parent {@link ParallelSystemArray} object. + */ + getSystemArray(): ParallelSystemArray; + /** + * Get manager of this object. + * + * @return The parent {@link ParallelSystemArray} object. + */ + getSystemArray>(): SystemArray; + /** + * Get performance index. + * + * Get *performance index* that indicates how much fast the remote system is. + * + * If this {@link ParallelSystem parallel system} does not have any {@link Invoke} message had handled, then the + * *performance index* will be ```1.0```, which means default and average value between all {@link ParallelSystem} + * instances (that are belonged to a same {@link ParallelSystemArray} object). + * + * You can specify this *performance index* by yourself but notice that, if the *performance index* is higher + * than other {@link ParallelSystem} objects, then this {@link ParallelSystem parallel system} will be ordered to + * handle more processes than other {@link ParallelSystem} objects. Otherwise, the *performance index* is lower + * than others, of course, less processes will be delivered. + * + * - {@link setPerformance setPerformance()} + * - {@link enforcePerformance enforcePerformance()} + * + * Unless {@link enforcePerformance enforcePerformance()} is called, This *performance index* is **revaluated** + * whenever user calls one of them below. + * + * - {@link ParallelSystemArray.sendSegmentData ParallelSystemArray.sendSegmentData()} + * - {@link ParallelSystemArray.sendPieceData ParallelSystemArray.sendPieceData()} + * - {@link DistributedProcess.sendData DistributedProcess.sendData()}. + * + * @return Performance index. + */ + getPerformance(): number; + /** + * Set performance index. + * + * Set *performance index* that indicates how much fast the remote system is. This *performance index* can be + * **revaulated**. + * + * Note that, initial and average *performance index* of {@link ParallelSystem} objects are ```1.0```. If the + * *performance index* is higher than other {@link ParallelSystem} objects, then this {@link ParallelSystem} will + * be ordered to handle more processes than other {@link ParallelSystem} objects. Otherwise, the + * *performance index* is lower than others, of course, less processes will be delivered. + * + * Unlike {@link enforcePerformance}, configuring *performance index* by this {@link setPerformance} allows + * **revaluation**. This **revaluation** prevents wrong valuation from user. For example, you *mis-valuated* the + * *performance index*. The remote system is much faster than any other, but you estimated it to the slowest one. + * It looks like a terrible case that causes {@link ParallelSystemArray entire parallel systems} to be slower, + * however, don't mind. The system will direct to the *propriate performance index* eventually with the + * **revaluation** by following methods. + * + * - {@link ParallelSystemArray.sendSegmentData ParallelSystemArray.sendSegmentData()} + * - {@link ParallelSystemArray.sendPieceData ParallelSystemArray.sendPieceData()} + * - {@link DistributedProcess.sendData DistributedProcess.sendData()}. + * + * @param val New performance index, but can be revaluated. + */ + setPerformance(val: number): void; + /** + * Enforce performance index. + * + * Enforce *performance index* that indicates how much fast the remote system is. The *performance index* will be + * fixed, never be **revaluated**. + * + * Note that, initial and average *performance index* of {@link ParallelSystem} objects are ```1.0```. If the + * *performance index* is higher than other {@link ParallelSystem} objects, then this {@link ParallelSystem} will + * be ordered to handle more processes than other {@link ParallelSystem} objects. Otherwise, the + * *performance index* is lower than others, of course, less processes will be delivered. + * + * The difference between {@link setPerformance} and this {@link enforcePerformance} is allowing **revaluation** + * or not. This {@link enforcePerformance} does not allow the **revaluation**. The *performance index* is clearly + * fixed and never be changed by the **revaluation**. But you've to keep in mind that, you can't avoid the + * **mis-valuation** with this {@link enforcePerformance}. + * + * For example, there's a remote system much faster than any other, but you **mis-estimated** it to the slowest. + * In that case, there's no way. The {@link ParallelSystemArray entire parallel systems} will be slower by the + * **mis-valuation**. By the reason, using {@link enforcePerformance}, it's recommended only when you can clearly + * certain the *performance index*. If you can't certain the *performance index* but want to recommend, then use + * {@link setPerformance} instead. + * + * @param val New performance index to be fixed. + */ + enforcePerformance(val: number): void; + /** + * @hidden + */ + private _Send_piece_data(invoke, first, last); + /** + * @hidden + */ + private _Reply_data(invoke); + /** + * @hidden + */ + protected _Report_history(xml: library.XML): void; + /** + * @hidden + */ + protected _Send_back_history(invoke: protocol.Invoke, history: slave.InvokeHistory): void; + } +} +declare namespace samchon.templates.distributed { + /** + * A driver for a distributed slave system. + * + * The {@link DistributedSystem} is an abstract class represents a **slave** system in *Distributed Processing System*, + * connected with this **master** system. This {@link DistributedSystem} takes full charge of network communication + * with the remote, distributed **slave** system has connected. + * + * This {@link DistributedSystem} has a {@link getPerformance performance index} that indicates how much the **slave** + * system is fast. The {@link getPerformance performance index} is referenced and revaluated whenever those methods + * are called: + * + * - Requesting a *parallel process* + * - {@link DistributedSystemArray.sendSegmentData} + * - {@link DistributedSystemArray.sendPieceData} + * - Requesting a *distributed process*: {@link DistributedProcess.sendData} + * + * Note that, this {@link DistributedSystem} class derived from the {@link ExternalSystem} class. Thus, this + * {@link DistributedSystem} can also have children {@link ExternalSystemRole} objects exclusively. However, the + * children {@link ExternalSystemRole roles} objects are different with the {@link DistributedProcess}. The + * domestic {@link ExternalSystemRole roles} are belonged to only a specific {@link DistributedSystem} object. + * Otherwise, the {@link DistributedProcess} objects are belonged to a {@link DistributedSystemArray} object. + * Furthermore, the relationship between this {@link DistributedSystem} and {@link DistributedProcess} classes are + * **M: N Associative**. + * + * Articles | {@link DistributedProcess} | {@link ExternalSystemRole} + * -------------|--------------------------------|---------------------------- + * Belonged to | {@link DistributedSystemArray} | {@link DistributedSystem} + * Relationship | M: N Associative | 1: N Composite + * Ownership | References | Exclusive possession + * + * + * + * + * + * @handbook [Templates - Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) + * @author Jeongho Nam + */ + abstract class DistributedSystem extends parallel.ParallelSystem { + /** + * Construct from parent {@link DistributedSystemArray}. + * + * @param systemArray The parent {@link DistributedSystemArray} object. + */ + constructor(systemArray: DistributedSystemArray); + /** + * Constrct from parent {@link DistributedSystemArray} and communicator. + * + * @param systemArray The parent {@link DistributedSystemArray} object. + * @param communicator A communicator communicates with remote, the external system. + */ + constructor(systemArray: DistributedSystemArray, communicator: protocol.IClientDriver); + /** + * Factory method creating a {@link ExternalSystemRole child} object. + * + * In {@link distributed} module, the process class {@link DistributedProcess} is not belonged to a specific + * {@link DistributedSystem} object. It only belongs to a {@link DistributedSystemArray} object and has a + * **M: N Associative Relationship** between this {@link DistributedSystem} class. + * + * By that reason, it's the normal case that the {@link DistributedSystem} object does not have any children + * {@link ExternalSystemRole} object. Thus, default {@link createChild} returns ```null```. + * + * However, if you want a {@link DistributedSystem} to have its own domestic {@link ExternalSystemRole} objects + * without reference to the {@link DistributedProcess} objects, it is possible. Creates and returns the + * domestic {@link ExternalSystemRole} object. + * + * @param xml {@link XML} represents the {@link ExternalSystemRole child} object. + * @return A newly created {@link ExternalSystemRole} object or ```null```. + */ + createChild(xml: library.XML): external.ExternalSystemRole; + /** + * Get manager of this object. + * + * @return The parent {@link DistributedSystemArray} object. + */ + getSystemArray(): DistributedSystemArray; + /** + * Get manager of this object. + * + * @return The parent {@link DistributedSystemArray} object. + */ + getSystemArray>(): SystemArray; + /** + * @hidden + */ + private _Compute_average_elapsed_time(); + /** + * @inheritdoc + */ + replyData(invoke: protocol.Invoke): void; + /** + * @hidden + */ + protected _Report_history(xml: library.XML): void; + /** + * @hidden + */ + protected _Send_back_history(invoke: protocol.Invoke, history: slave.InvokeHistory): void; + } +} +declare namespace samchon.templates.distributed { + /** + * A driver for distributed slave server. + * + * The {@link DistributedServer} is an abstract class, derived from the {@link DistributedSystem} class, connecting to + * remote, distributed **slave** server. Extends this {@link DistributedServer} class and overrides the + * {@link createServerConnector createServerConnector()} method following which protocol the **slave** server uses. + * + * #### [Inheritdoc] {@link DistributedSystem} + * @copydoc DistributedSystem + */ + abstract class DistributedServer extends DistributedSystem implements external.IExternalServer { + /** + * IP address of target external system to connect. + */ + protected ip: string; + /** + * Port number of target external system to connect. + */ + protected port: number; + /** + * Construct from parent {@link DistributedSystemArray}. + * + * @param systemArray The parent {@link DistributedSystemArray} object. + */ + constructor(systemArray: DistributedSystemArray); + /** + * Factory method creating {@link IServerConnector} object. + * + * The {@link createServerConnector createServerConnector()} is an abstract method creating + * {@link IServerConnector} object. Overrides and returns one of them, considering which protocol the slave server + * follows: + * + * - {@link ServerConnector} + * - {@link WebServerConnector} + * - {@link DedicatedWorkerServerConnector} + * - {@link SharedWorkerServerConnector} + * + * @return A newly created {@link IServerConnector} object. + */ + protected abstract createServerConnector(): protocol.IServerConnector; + /** + * @inheritdoc + */ + connect(): void; + } +} +declare namespace samchon.templates.distributed { + /** + * Master of Distributed Processing System, a client connecting to slave servers. + * + * The {@link DistributedServerArray} is an abstract class, derived from the {@link DistributedSystemArray} class, + * connecting to {@link IDistributedServer distributed servers}. + * + * Extends this {@link DistributedServerArray} and overrides {@link createChild createChild()} method creating child + * {@link IDistributedServer} object. After the extending and overriding, construct children {@link IDistributedServer} + * objects and call the {@link connect connect()} method. + * + * #### [Inherited] {@link DistributedSystemArray} + * @copydoc DistributedSystemArray + */ + abstract class DistributedServerArray extends DistributedSystemArray implements external.IExternalServerArray { + /** + * Default Constructor. + */ + constructor(); + /** + * @inheritdoc + */ + connect(): void; + } +} +declare namespace samchon.templates.distributed { + /** + * Mediator of Distributed Processing System, a client connecting to slave servers. + * + * The {@link DistributedServerArrayMediator} is an abstract class, derived from {@link DistributedSystemArrayMediator} + * class, connecting to {@link IDistributedServer distributed servers}. + * + * Extends this {@link DistributedServerArrayMediator} and overrides {@link createChild createChild()} method creating + * child {@link IDistributedServer} object. After the extending and overriding, construct children + * {@link IDistributedServer} objects and call the {@link connect connect()} method. + * + * #### [Inherited] {@link DistributedSystemArrayMediator} + * @copydoc DistributedSystemArrayMediator + */ + abstract class DistributedServerArrayMediator extends DistributedSystemArrayMediator implements external.IExternalServerArray { + /** + * Default Constructor. + */ + constructor(); + /** + * @inheritdoc + */ + connect(): void; + } +} +declare namespace samchon.templates.distributed { + /** + * Master of Distributed Processing System, be a server and client at the same time. + * + * The {@link DistributedServerClientArray} is an abstract class, derived from the {@link DistributedSystemArray} + * class, opening a server accepting {@link Distributed distributed clients} and being a client connecting to + * {@link IDistributedServer distributed servers} at the same time. + * + * Extends this {@link DistributedServerClientArray} and overrides below methods. After the overridings, open server + * with {@link open open()} method and connect to {@link IDistributedServer distributed servers} through the + * {@link connect connect()} method. + * + * - {@link createServerBase createServerBase()} + * - {@link createExternalClient createExternalClient()} + * - {@link createExternalServer createExternalServer()} + * + * #### [Inherited] {@link DistributedSystemArray} + * @copydoc DistributedSystemArray + */ + abstract class DistributedServerClientArray extends DistributedClientArray implements external.IExternalServerClientArray { + /** + * Default Constructor. + */ + constructor(); + /** + * Factory method of a child Entity. + * + * This method is migrated to {@link createExternalServer}. Override the {@link createExternalServer} method. + * + * @param xml An {@link XML} object represents child element, so that can identify the type of child to create. + * @return A new child Entity via {@link createExternalServer createExternalServer()}. + */ + createChild(xml: library.XML): System; + /** + * Factory method creating an {@link IDistributedServer} object. + * + * @param xml An {@link XML} object represents child element, so that can identify the type of child to create. + * @return A newly created {@link IDistributedServer} object. + */ + protected abstract createExternalServer(xml: library.XML): System; + /** + * @inheritdoc + */ + connect(): void; + } +} +declare namespace samchon.templates.distributed { + /** + * Mediator of Distributed Processing System, be a server and client at the same time as a **master**. + * + * The {@link DistributedServerClientArrayMediator} is an abstract class, derived from the + * {@link DistributedSystemArrayMediator} class, opening a server accepting {@link DistributedSystem distributed + * clients} and being a client connecting to {@link IDistributedServer distributed servers} at the same time. + * + * Extends this {@link DistributedServerClientArrayMediator} and overrides below methods. After the overridings, open + * server with {@link open open()} method and connect to {@link IDistributedServer distributed servers} through the + * {@link connect connect()} method. + * + * - {@link createServerBase createServerBase()} + * - {@link createExternalClient createExternalClient()} + * - {@link createExternalServer createExternalServer()} + * + * #### [Inherited] {@link DistributedSystemArrayMediator} + * @copydoc DistributedSystemArrayMediator + */ + abstract class DistributedServerClientArrayMediator extends DistributedClientArrayMediator implements external.IExternalServerClientArray { + /** + * Default Constructor. + */ + constructor(); + /** + * Factory method of a child Entity. + * + * This method is migrated to {@link createExternalServer}. Override the {@link createExternalServer} method. + * + * @param xml An {@link XML} object represents child element, so that can identify the type of child to create. + * @return A new child Entity via {@link createExternalServer createExternalServer()}. + */ + createChild(xml: library.XML): System; + /** + * Factory method creating an {@link IDistributedServer} object. + * + * @param xml An {@link XML} object represents child element, so that can identify the type of child to create. + * @return A newly created {@link IDistributedServer} object. + */ + protected abstract createExternalServer(xml: library.XML): System; + /** + * @inheritdoc + */ + connect(): void; + } +} +declare namespace samchon.templates.distributed { + /** + * A process of Distributed Processing System. + * + * The {@link DistributedProcess} is an abstract class who represents a **process**, *SOMETHING TO DISTRIBUTE* in a Distributed + * Processing System. Overrides the {@link DistributedProcess} and defines the *SOMETHING TO DISTRIBUTE*. + * + * Relationship between {@link DistributedSystem} and {@link DistributedProcess} objects are **M: N Associative**. + * Unlike {@link ExternalSystemRole}, the {@link DistributedProcess} objects are not belonged to a specific + * {@link DistributedSystem} object. The {@link DistributedProcess} objects are belonged to the + * {@link DistributedSystemArrayMediator} directly. + * + * When you need the **distributed process**, then call {@link sendData sendData()}. The {@link sendData} will find + * the most idle {@link DistributedSystem slave system} considering not only number of processes on progress, but also + * {@link DistributedSystem.getPerformance performance index} of each {@link DistributedSystem} object and + * {@link getResource resource index} of this {@link DistributedProcess} object. The {@link Invoke} message + * requesting the **distributed process** will be sent to the most idle {@link DistributedSystem slave system}. + * + * Those {@link DistributedSystem.getPerformance performance index} and {@link getResource resource index} are + * revaluated whenever the **distributed process** has completed basis on the execution time. + * + * + * + * + * + * @handbook [Templates - Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) + * @author Jeongho Nam + */ + abstract class DistributedProcess extends protocol.Entity implements protocol.IProtocol { + /** + * @hidden + */ + private system_array_; + /** + * A name, represents and identifies this {@link DistributedProcess process}. + * + * This {@link name} is an identifier represents this {@link DistributedProcess process}. This {@link name} is + * used in {@link DistributedSystemArray.getProcess} and {@link DistributedSystemArray.getProcess}, as a key elements. + * Thus, this {@link name} should be unique in its parent {@link DistributedSystemArray} object. + */ + protected name: string; + /** + * @hidden + */ + private progress_list_; + /** + * @hidden + */ + private history_list_; + /** + * @hidden + */ + private resource; + /** + * @hidden + */ + private enforced_; + /** + * Constrct from parent {@link DistributedSystemArray} object. + * + * @param systemArray The parent {@link DistributedSystemArray} object. + */ + constructor(systemArray: DistributedSystemArray); + /** + * Identifier of {@link ParallelProcess} is its {@link name}. + */ + key(): string; + /** + * Get parent {@link DistributedSystemArray} object. + * + * @return The parent {@link DistributedSystemArray} object. + */ + getSystemArray(): DistributedSystemArray; + /** + * Get parent {@link DistributedSystemArray} object. + * + * @return The parent {@link DistributedSystemArray} object. + */ + getSystemArray>(): SystemArray; + /** + * Get name, who represents and identifies this process. + */ + getName(): string; + /** + * Get resource index. + * + * Get *resource index* that indicates how much this {@link DistributedProcess process} is heavy. + * + * If this {@link DistributedProcess process} does not have any {@link Invoke} message had handled, then the + * *resource index* will be ```1.0```, which means default and average value between all + * {@link DistributedProcess} instances (that are belonged to a same {@link DistributedSystemArray} object). + * + * You can specify the *resource index* by yourself, but notice that, if the *resource index* is higher than + * other {@link DistributedProcess} objects, then this {@link DistributedProcess process} will be ordered to + * handle less processes than other {@link DistributedProcess} objects. Otherwise, the *resource index* is + * lower than others, of course, much processes will be requested. + * + * - {@link setResource setResource()} + * - {@link enforceResource enforceResource()} + * + * Unless {@link enforceResource enforceResource()} is called, This *resource index* is **revaluated** whenever + * {@link sendData sendData()} is called. + * + * @return Resource index. + */ + getResource(): number; + /** + * Set resource index. + * + * Set *resource index* that indicates how much this {@link DistributedProcess process} is heavy. This + * *resource index* can be **revaulated**. + * + * Note that, initial and average *resource index* of {@link DistributedProcess} objects are ```1.0```. If the + * *resource index* is higher than other {@link DistributedProcess} objects, then this + * {@link DistributedProcess} will be ordered to handle more processes than other {@link DistributedProcess} + * objects. Otherwise, the *resource index* is lower than others, of course, less processes will be requested. + * + * Unlike {@link enforceResource}, configuring *resource index* by this {@link setResource} allows the + * **revaluation**. This **revaluation** prevents wrong valuation from user. For example, you *mis-valuated* the + * *resource index*. The {@link DistributedProcess process} is much heavier than any other, but you estimated it + * to the lightest one. It looks like a terrible case that causes + * {@link DistributedSystemArray entire distributed processing system} to be slower, however, don't mind. The + * {@link DistributedProcess process} will the direct to the *propriate resource index* eventually with the + * **revaluation**. + * + * - The **revaluation** is caused by the {@link sendData sendData()} method. + * + * @param val New resource index, but can be revaluated. + */ + setResource(val: number): void; + /** + * Enforce resource index. + * + * Enforce *resource index* that indicates how much heavy the {@link DistributedProcess process is}. The + * *resource index* will be fixed, never be **revaluated**. + * + * Note that, initial and average *resource index* of {@link DistributedProcess} objects are ```1.0```. If the + * *resource index* is higher than other {@link DistributedProcess} objects, then this + * {@link DistributedProcess} will be ordered to handle more processes than other {@link DistributedProcess} + * objects. Otherwise, the *resource index* is lower than others, of course, less processes will be requested. + * + * The difference between {@link setResource} and this {@link enforceResource} is allowing **revaluation** or not. + * This {@link enforceResource} does not allow the **revaluation**. The *resource index* is clearly fixed and + * never be changed by the **revaluation**. But you've to keep in mind that, you can't avoid the **mis-valuation** + * with this {@link enforceResource}. + * + * For example, there's a {@link DistributedProcess process} much heavier than any other, but you + * **mis-estimated** it to the lightest. In that case, there's no way. The + * {@link DistributedSystemArray entire distributed processing system} will be slower by the **mis-valuation**. + * By the reason, using {@link enforceResource}, it's recommended only when you can clearly certain the + * *resource index*. If you can't certain the *resource index* but want to recommend, then use {@link setResource} + * instead. + * + * @param val New resource index to be fixed. + */ + enforceResource(val: number): void; + /** + * @hidden + */ + private _Compute_average_elapsed_time(); + /** + * @inheritdoc + */ + abstract replyData(invoke: protocol.Invoke): void; + /** + * Send an {@link Invoke} message. + * + * Sends an {@link Invoke} message requesting a **distributed process**. The {@link Invoke} message will be sent + * to the most idle {@link DistributedSystem} object, which represents a slave system, and the most idle + * {@link DistributedSystem} object will be returned. + * + * When the **distributed process** has completed, then the {@link DistributedSystemArray} object will revaluate + * {@link getResource resource index} and {@link DistributedSystem.getPerformance performance index} of this + * {@link DistributedSystem} and the most idle {@link DistributedSystem} objects basis on the execution time. + * + * @param invoke An {@link Invoke} message requesting distributed process. + * @return The most idle {@link DistributedSystem} object who may send the {@link Invoke} message. + */ + sendData(invoke: protocol.Invoke): DistributedSystem; + /** + * Send an {@link Invoke} message. + * + * Sends an {@link Invoke} message requesting a **distributed process**. The {@link Invoke} message will be sent + * to the most idle {@link DistributedSystem} object, which represents a slave system, and the most idle + * {@link DistributedSystem} object will be returned. + * + * When the **distributed process** has completed, then the {@link DistributedSystemArray} object will revaluate + * {@link getResource resource index} and {@link DistributedSystem.getPerformance performance index} of this + * {@link DistributedSystem} and the most idle {@link DistributedSystem} objects basis on the execution time. + * + * @param invoke An {@link Invoke} message requesting distributed process. + * @param weight Weight of resource which indicates how heavy this {@link Invoke} message is. Default is 1. + * + * @return The most idle {@link DistributedSystem} object who may send the {@link Invoke} message. + */ + sendData(invoke: protocol.Invoke, weight: number): DistributedSystem; + /** + * @hidden + */ + private _Complete_history(history); + /** + * @inheritdoc + */ + TAG(): string; + } +} +declare namespace samchon.templates.slave { + /** + * History of an {@link Invoke} message. + * + * The {@link InvokeHistory} is a class archiving history log of an {@link Invoke} message with elapsed time. This + * {@link InvokeHistory} class is used to report elapsed time of handling a requested process from **slave** to + * **master** system. + * + * The **master** system utilizes derived {@link InvokeHistory} objects to compute performance indices. + * - {@link ParallelSytem.getPerformance} + * - {@link DistributedProcess.getResource} + * + * @author Jeongho Nam + */ + class InvokeHistory extends protocol.Entity { + /** + * @hidden + */ + private uid; + /** + * @hidden + */ + private listener; + /** + * @hidden + */ + private start_time_; + /** + * @hidden + */ + private end_time_; + /** + * Default Constructor. + */ + constructor(); + /** + * Construct from an {@link Invoke} message. + * + * @param invoke An {@link Invoke} message requesting a *parallel or distributed process*. + */ + constructor(invoke: protocol.Invoke); + /** + * @inheritdoc + */ + construct(xml: library.XML): void; + /** + * Complete the history. + * + * Completes the history and determines the {@link getEndTime end time}. + */ + complete(): void; + key(): number; + /** + * Get unique ID. + */ + getUID(): number; + /** + * Get {@link Invoke.getListener listener} of the {@link Invoke} message. + */ + getListener(): string; + /** + * Get start time. + */ + getStartTime(): Date; + /** + * Get end time. + */ + getEndTime(): Date; + /** + * Compute elapsed time. + * + * @return nanoseconds. + */ + computeElapsedTime(): number; + /** + * @inheritdoc + */ + TAG(): string; + /** + * @inheritdoc + */ + toXML(): library.XML; + /** + * Convert to an {@link Invoke} message. + * + * Creates and returns an {@link Invoke} message that is used to reporting to the **master**. + */ + toInvoke(): protocol.Invoke; + } +} +declare namespace samchon.templates.distributed { + /** + * History of an {@link Invoke} message. + * + * The {@link PRInvokeHistory} is a class archiving history log of an {@link Invoke} message which requests the + * *distributed process*, created whenever {@link DistributedProcess.sendData} is called. + * + * When the *distributed process* has completed, then {@link complete complete()} is called and the *elapsed time* is + * determined. The elapsed time is utilized for computation of {@link DistributedSystem.getPerformance performance index} + * and {@link DistributedProcess.getResource resource index} of related objects. + * + * + * + * + * + * @handbook [Templates - Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) + * @author Jeongho Nam + */ + class DSInvokeHistory extends slave.InvokeHistory { + /** + * @hidden + */ + private system_; + /** + * @hidden + */ + private process_; + /** + * @hidden + */ + private weight_; + /** + * Construct from a DistributedSystem. + * + * @param system The {@link DistributedSystem} object who sent the {@link Invoke} message. + */ + constructor(system: DistributedSystem); + /** + * Initilizer Constructor. + * + * @param system The {@link DistributedSystem} object who sent the {@link Invoke} message. + * @param process The {@link DistributedProcess} object who sent the {@link Invoke} message. + * @param invoke An {@link Invoke} message requesting the *distributed process*. + * @param weight Weight of resource which indicates how heavy this {@link Invoke} message is. + */ + constructor(system: DistributedSystem, process: DistributedProcess, invoke: protocol.Invoke, weight: number); + /** + * @inheritdoc + */ + construct(xml: library.XML): void; + /** + * Get the related {@link DistributedSystem} object. + */ + getSystem(): DistributedSystem; + /** + * Get the related {@link DistributedProcess} object. + */ + getProcess(): DistributedProcess; + /** + * Get weight. + * + * Gets weight of resource which indicates how heavy this {@link Invoke} message is. Default is 1. + */ + getWeight(): number; + /** + * @inheritdoc + */ + toXML(): library.XML; + } +} +declare namespace samchon.templates.distributed { + /** + * An interface for a distributed slave server driver. + * + * The easiest way to defining a driver for distributed **slave** server is extending {@link DistributedServer} class. + * However, if you've to interact with a prallel **slave** system who can be both server and client, them make a class + * (let's name it **BaseSystem**) extending the {@link DistributedServer} class. At next, make a new class (now, I name + * it **BaseServer**) extending the **BaseSystem** and implements this interface {@link IParallelServer}. Define the + * **BaseServer** following those codes on below: + * + * + * + * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System) + * @author Jeongho Nam + */ + interface IDistributedServer extends DistributedSystem { + /** + * Connect to external server. + */ + connect(): void; + } +} +declare namespace samchon.templates.external { + /** + * An array and manager of {@link ExternalSystem external clients} as a server. + * + * The {@link ExternalClientArray} is an abstract class, derived from the {@link ExternalSystemArray} class, opening + * a server accepting {@link ExternalSystem external clients}. + * + * Extends this {@link ExternalClientArray}, overrides {@link createServerBase createServerBase()} to determine which + * protocol to follow and {@link createExternalClient createExternalClient()} creating child {@link ExternalSystem} + * object. After the extending and overridings, open this server using the {@link open open()} method. + * + * #### [Inherited] {@link ExternalSystemArray} + * @copydoc ExternalSystemArray + */ + abstract class ExternalClientArray extends ExternalSystemArray implements IExternalClientArray { + /** + * @hidden + */ + private server_base_; + /** + * Default Constructor. + */ + constructor(); + /** + * Factory method creating {@link IServerBase} object. + * + * This method {@link createServerBase createServerBase()} determines which templates is used in this server, + * {@link ExternalClientArray}. If the templates is determined, then {@link ExternalSystem external clients} who + * may connect to {@link ExternalClientArray this server} must follow the specified templates. + * + * Creates and returns one of them: + * + * - {@link ServerBase} + * - {@link WebServerBase} + * - {@link SharedWorkerServerBase} + * + * @return A new {@link IServerBase} object. + */ + protected abstract createServerBase(): protocol.IServerBase; + /** + * Add a newly connected remote client. + * + * When a {@link IClientDriver remote client} connects to this *server* {@link ExternalClientArray} object, + * then this {@link ExternalClientArray} creates a child {@link ExternalSystem external client} object through + * the {@link createExternalClient createExternalClient()} method and {@link insert inserts} it. + * + * @param driver A communicator for external client. + */ + addClient(driver: protocol.IClientDriver): void; + /** + * (Deprecated) Factory method creating child object. + * + * The method {@link createChild createChild()} is deprecated. Don't use and override this. + * + * Note that, the {@link ExternalClientArray} is a server accepting {@link ExternalSystem external clients}. + * There's no way to creating the {@link ExternalSystem external clients} in advance before opening the server. + * + * @param xml An {@link XML} object represents the child {@link ExternalSystem} object. + * @return null + */ + createChild(xml: library.XML): T; + /** + * Factory method creating a child {@link ExternalSystem} object. + * + * @param driver A communicator with connected client. + * @return A newly created {@link ExternalSystem} object. + */ + protected abstract createExternalClient(driver: protocol.IClientDriver): T; + /** + * @inheritdoc + */ + open(port: number): void; + /** + * @inheritdoc + */ + close(): void; + } +} +declare namespace samchon.templates.external { + /** + * An external server driver. + * + * The {@link ExternalServer} is an abstract class, derived from the {@link ExternalSystem} class, connecting to + * remote, external server. Extends this {@link ExternalServer} class and overrides the + * {@link createServerConnector createServerConnector()} method following which protocol the external server uses. + * + * #### [Inherited] {@link ExternalSystem} + * @copydoc ExternalSystem + */ + abstract class ExternalServer extends ExternalSystem implements IExternalServer { + /** + * IP address of target external system to connect. + */ + protected ip: string; + /** + * Port number of target external system to connect. + */ + protected port: number; + /** + * Construct from parent {@link ExternalSystemArray}. + * + * @param systemArray The parent {@link ExternalSystemArray} object. + */ + constructor(systemArray: ExternalSystemArray); + /** + * Factory method creating {@link IServerConnector} object. + * + * The {@link createServerConnector createServerConnector()} is an abstract method creating + * {@link IServerConnector} object. Overrides and returns one of them, considering which templates the external + * system follows: + * + * - {@link ServerConnector} + * - {@link WebServerConnector} + * - {@link DedicatedWorkerServerConnector} + * - {@link SharedWorkerServerConnector} + * + * @return A newly created {@link IServerConnector} object. + */ + protected abstract createServerConnector(): protocol.IServerConnector; + /** + * @inheritdoc + */ + connect(): void; + } +} +declare namespace samchon.templates.external { + /** + * An array and manager of {@link IExternalServer external servers}. + * + * The {@link ExternalServerArray} is an abstract class, derived from the {@link ExternalSystemArray} class, + * connecting to {@link IExternalServer external servers}. + * + * Extends this {@link ExternalServerArray} and overrides {@link createChild createChild()} method creating child + * {@link IExternalServer} object. After the extending and overriding, construct children {@link IExternalServer} + * objects and call the {@link connect connect()} method. + * + * #### [Inherited] {@link ExternalSystemArray} + * @copydoc ExternalSystemArray + */ + abstract class ExternalServerArray extends ExternalSystemArray implements IExternalServerArray { + /** + * Default Constructor. + */ + constructor(); + /** + * @inheritdoc + */ + connect(): void; + } +} +declare namespace samchon.templates.external { + /** + * An array and manager of {@link IExternalServer external servers} and {@link ExternalSystem external clients}. + * + * The {@link ExternalServerClientArray} is an abstract class, derived from the {@link ExternalSystemArray} class, + * opening a server accepting {@link ExternalSystem external clients} and being a client connecting to + * {@link IExternalServer external servers} at the same time. + * + * Extends this {@link ExternalServerClientArray} and overrides below methods. After the overridings, open server + * with {@link open open()} method and connect to {@link IExternalServer external servers} through the + * {@link connect connect()} method. + * + * - {@link createServerBase createServerBase()} + * - {@link createExternalClient createExternalClient()} + * - {@link createExternalServer createExternalServer()} + * + * #### [Inherited] {@link ExternalSystemArray} + * @copydoc ExternalSystemArray + */ + abstract class ExternalServerClientArray extends ExternalClientArray implements IExternalServerClientArray { + /** + * Default Constructor. + */ + constructor(); + /** + * Factory method of a child Entity. + * + * This method is migrated to {@link createExternalServer}. Override the {@link createExternalServer} method. + * + * @param xml An {@link XML} object represents child element, so that can identify the type of child to create. + * @return A new child Entity via {@link createExternalServer createExternalServer()}. + */ + createChild(xml: library.XML): T; + /** + * Factory method creating an {@link IExternalServer} object. + * + * @param xml An {@link XML} object represents child element, so that can identify the type of child to create. + * @return A newly created {@link IExternalServer} object. + */ + protected abstract createExternalServer(xml: library.XML): T; + /** + * @inheritdoc + */ + connect(): void; + } +} +declare namespace samchon.templates.external { + /** + * A role of an external system. + * + * The {@link ExternalSystemRole} class represents a role, *WHAT TO DO*. Extends the {@link ExternalSystemRole} class + * and overrides {@link replyData replyData()} to define the *WHAT TO DO*. And assign this {@link ExternalSystemRole} + * object to related {@link ExternalSystem} object. + * + * + * + * + * + * #### Proxy Pattern + * The {@link ExternalSystemRole} class can be an *logical proxy*. In framework within user, which + * {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not + * important. Only interested in user's perspective is *which can be done*. + * + * By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged + * to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}. + * Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}. + * + *
    + *
  • + * {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring + * from {@link ExternalSystem} object, via {@link ExternalSystemArray.getRole ExternalSystemArray.getRole()}. + *
  • + *
  • + * When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call + * {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the + * external system. + *
  • + *
  • Those strategy is called *Proxy Pattern*.
  • + *
+ * + * @handbook [Templates - External System](https://github.com/samchon/framework/wiki/TypeScript-Templates-External_System) + * @author Jeongho Nam + */ + abstract class ExternalSystemRole extends protocol.Entity implements protocol.IProtocol { + /** + * @hidden + */ + private system; + /** + * A name, represents and identifies this {@link ExternalSystemRole role}. + * + * This {@link name} is an identifier represents this {@link ExternalSystemRole role}. This {@link name} is + * used in {@link ExternalSystemArray.getRole} and {@link ExternalSystem.get}, as a key elements. Thus, this + * {@link name} should be unique in an {@link ExternalSystemArray}. + */ + protected name: string; + /** + * Constructor from a system. + * + * @param system An external system containing this role. + */ + constructor(system: ExternalSystem); + /** + * Identifier of {@link ExternalSystemRole} is its {@link name}. + */ + key(): string; + /** + * Get grandparent {@link ExternalSystemArray}. + * + * Get the grandparent {@link ExternalSystemArray} object through this parent {@link ExternalSystem}, + * {@link ExternalSystem.getSystemArray ExternalSystem.getSystemArray()}. + * + * @return The grandparent {@link ExternalSystemArray} object. + */ + getSystemArray(): ExternalSystemArray; + /** + * Get parent {@link ExternalSystemRole} object. + */ + getSystem(): ExternalSystem; + /** + * Get name, who represents and identifies this role. + */ + getName(): string; + /** + * Send an {@link Invoke} message. + * + * Sends an {@link Invoke} message to remote system through the parent {@link ExternalSystem} object. + * + * @param invoke An {@link Invoke} message to send to the external system. + */ + sendData(invoke: protocol.Invoke): void; + /** + * Handle replied {@link Invoke} message. + * + * {@link ExternalSystemRole.replyData ExternalSystemRole.replyData()} is an abstract method handling a replied + * {@link Invoke message} gotten from remote system via parent {@link ExternalSystem} object. Overrides this + * method and defines the *WHAT TO DO* with the {@link Invoke message}. + * + * @param invoke An {@link Invoke} message received from the {@link ExternalSystem external system}. + */ + abstract replyData(invoke: protocol.Invoke): void; + /** + * Tag name of the {@link ExternalSytemRole} in {@link XML}. + * + * @return *role*. + */ + TAG(): string; + } +} +declare namespace samchon.templates.external { + /** + * An interface for an {@link ExternalSystemArray} accepts {@link ExternalSystem external clients} as a + * {@link IServer server}. + * + * The easiest way to defining an {@link ExternalSystemArray} who opens server and accepts + * {@link ExternalSystem external clients} is to extending one of below, who are derived from this interface + * {@link IExternalClientArray}. However, if you can't specify an {@link ExternalSystemArray} to be whether server or + * client, then make a class (let's name it as **BaseSystemArray**) extending {@link ExternalSystemArray} and make + * a new class (now, I name it **BaseClientArray**) extending **BaseSystemArray** and implementing this + * interface {@link IExternalClientArray}. Define the **BaseClientArray** following those codes on below: + * + * + * + * @handbook [Templates - External System](https://github.com/samchon/framework/wiki/TypeScript-Templates-External_System) + * @author Jeongho Nam + */ + interface IExternalClientArray extends ExternalSystemArray, protocol.IServer { + } +} +declare namespace samchon.templates.external { + /** + * An interface for an external server driver. + * + * The easiest way to defining an external server driver is to extending one of below, who are derived from this + * interface {@link IExternalServer}. However, if you've to interact with an external system who can be both server + * and client, then make a class (let's name it as **BaseSystem**) extending {@link ExternalSystem} and make a + * new class (now, I name it **BaseServer**) extending **BaseSystem** and implementing this interface + * {@link IExternalServer}. Define the **BaseServer** following those codes on below: + * + * + * + * @handbook [Templates - External System](https://github.com/samchon/framework/wiki/TypeScript-Templates-External_System) + * @author Jeongho Nam + */ + interface IExternalServer extends ExternalSystem { + /** + * Connect to the external server. + */ + connect(): void; + } +} +declare namespace samchon.templates.external { + /** + * An interface for an {@link ExternalSystemArray} connects to {@link IExternalServer external servers} as a + * **client**. + * + * The easiest way to defining an {@link ExternalSystemArray} who connects to + * {@link IExternalServer external servers} is to extending one of below, who are derived from this interface + * {@link IExternalServerArray}. However, if you can't specify an {@link ExternalSystemArray} to be whether server or + * client, then make a class (let's name it as **BaseSystemArray**) extending {@link ExternalSystemArray} and make + * a new class (now, I name it **BaseServerArray**) extending **BaseSystemArray** and implementing this + * interface {@link IExternalServerArray}. Define the **BaseServerArray** following those codes on below: + * + * + * + * @handbook [Templates - External System](https://github.com/samchon/framework/wiki/TypeScript-Templates-External_System) + * @author Jeongho Nam + */ + interface IExternalServerArray extends ExternalSystemArray { + /** + * Connect to {@link IExternalServer external servers}. + * + * This method calls children elements' method {@link IExternalServer.connect} gradually. + */ + connect(): void; + } +} +declare namespace samchon.templates.external { + /** + * An interface for an {@link ExternalSystemArray} accepts {@link ExternalSystem external clients} as a + * {@link IServer server} and connects to {@link IExternalServer} as **client**, at the same time. + * + * The easiest way to defining an {@link IExternalServerClientArray} who opens server, accepts + * {@link ExternalSystem external clients} and connects to {@link IExternalServer external servers} is to extending + * one of below, who are derived from this interface {@link IExternalServerClientArray}. However, if you can't + * specify an {@link ExternalSystemArray} to be whether server or client or even can both them, then make a class + * (let's name it as **BaseSystemArray**) extending {@link ExternalSystemArray} and make a new class (now, I name + * it **BaseServerClientArray**) extending **BaseSystemArray** and implementing this interface + * {@link IExternalServerClientArray}. Define the **BaseServerClientArray** following those codes on below: + * + * + * + * @handbook [Templates - External System](https://github.com/samchon/framework/wiki/TypeScript-Templates-External_System) + * @author Jeongho Nam + */ + interface IExternalServerClientArray extends IExternalClientArray { + /** + * Connect to {@link IExternalServer external servers}. + * + * This method calls children elements' method {@link IExternalServer.connect} gradually. + */ + connect(): void; + } +} +declare namespace samchon.templates.slave { + /** + * A slave system. + * + * @author Jeongho Nam + */ + abstract class SlaveSystem implements protocol.IProtocol { + /** + * @hidden + */ + protected communicator_: protocol.ICommunicator; + /** + * Default Constructor. + */ + constructor(); + sendData(invoke: protocol.Invoke): void; + abstract replyData(invoke: protocol.Invoke): void; + /** + * @hidden + */ + protected _Reply_data(invoke: protocol.Invoke): void; + } +} +declare namespace samchon.templates.parallel { + /** + * A mediator, the master driver. + * + * The {@link MediatorSystem} is an abstract class helping {@link ParallelSystemArrayMediator} can be a **slave** + * system. The {@link MediatorSystem} interacts and communicates with the **master** system as a role of **slave**. + * + * This {@link MediatorSystem} object is created in {@link ParallelSystemArrayMediator.createMediator}. Override the + * method and return one of them, which are derived from this {@link MediatorSystem} class, considering which + * type and protocol the **master** system follows: + * + * - A client slave connecting to master server: + * - {@link MediatorClient} + * - {@link MediatorWebClient} + * - {@link MediatorSharedWorkerClient} + * - A server slave accepting master client: + * - {@link MediatorServer} + * - {@link MediatorWebServer} + * - {@link MediatorDedicatedWorkerServer} + * - {@link MediatorSharedWorkerServer} + * + * When the **master** orders a *parallel process* to this **slave**, then the {@link MediatorSystem} delivers the + * *parallel process* to its parent {@link ParallelSystemArrayMediator} object. The + * {@link ParallelSystemArrayMediator} object distributes the *parallel process* to its slaves system, + * {@link ParallelSystem} objects. When the *parallel process* has completed, then {@link MediatorSystem} reports the + * result to its **master**. + * + * + * + * + * + * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System), + * [Distributed System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Distributed_System) + * @author Jeongho Nam + */ + abstract class MediatorSystem extends slave.SlaveSystem { + /** + * @hidden + */ + private system_array_; + /** + * @hidden + */ + private progress_list_; + /** + * Construct from parent {@link ParallelSystemArrayMediator} object. + * + * @param systemArray The parent {@link ParallelSystemArrayMediator} object. + */ + constructor(systemArray: ParallelSystemArrayMediator); + /** + * Construct from parent {@link DistributedSystemArrayMediator} object. + * + * @param systemArray The parent {@link DistributedSystemArrayMediator} object. + */ + constructor(systemArray: distributed.DistributedSystemArrayMediator); + /** + * Start interaction. + * + * The {@link start start()} is an abstract method starting interaction with the **master** system. If the + * **master** is a server, then connects to the **master**. Otherwise, the **master** is client, then this + * {@link MediatorSystem} object wil open a server accepting the **master**. + */ + abstract start(): void; + /** + * Get parent {@link ParallelSystemArrayMediator} or {@link DistributedSystemArrayMediator} object. + */ + getSystemArray(): ParallelSystemArrayMediator | distributed.DistributedSystemArrayMediator; + /** + * Get parent {@link ParallelSystemArrayMediator} object. + */ + getSystemArray>(): SystemArray; + /** + * Get parent {@link DistributedSystemArrayMediator} object. + */ + getSystemArray>(): SystemArray; + /** + * @hidden + */ + private _Complete_history(uid); + /** + * @hidden + */ + protected _Reply_data(invoke: protocol.Invoke): void; + /** + * @inheritdoc + */ + replyData(invoke: protocol.Invoke): void; + } +} +declare namespace samchon.templates.parallel { + /** + * A mediator client, driver for the master server. + * + * The {@link MediatorServer} is a class being a client connecting to the **master** server, following the protocol + * of Samchon Framework's own. + * + * #### [Inherited] {@link MediatorSystem} + * @copydoc MediatorSystem + */ + class MediatorClient extends MediatorSystem implements slave.ISlaveClient { + /** + * @hidden + */ + private ip; + /** + * @hidden + */ + private port; + /** + * Initializer Constructor. + * + * @param systemArray The parent {@link ParallelSystemArrayMediator} object. + * @param ip IP address to connect. + * @param port Port number to connect. + */ + constructor(systemArray: ParallelSystemArrayMediator, ip: string, port: number); + /** + * Initializer Constructor. + * + * @param systemArray The parent {@link DistributedSystemArrayMediator} object. + * @param ip IP address to connect. + * @param port Port number to connect. + */ + constructor(systemArray: distributed.DistributedSystemArrayMediator, ip: string, port: number); + /** + * Factory method creating {@link IServerConnector} object. + * + * The {@link createServerConnector createServerConnector()} is an abstract method creating + * {@link IServerConnector} object. Overrides and returns one of them, considering which protocol the **master** + * server follows: + * + * - {@link ServerConnector} + * - {@link WebServerConnector} + * - {@link SharedWorkerServerConnector} + * + * @return A newly created {@link IServerConnector} object. + */ + protected createServerConnector(): protocol.IServerConnector; + /** + * @inheritdoc + */ + start(): void; + /** + * @inheritdoc + */ + connect(): void; + } + /** + * A mediator client, driver for the master server. + * + * The {@link MediatorWebClient} is a class being a client connecting to the **master** server, following the + * web-socket protocol. + * + * #### [Inherited] {@link MediatorSystem} + * @copydoc MediatorSystem + */ + class MediatorWebClient extends MediatorClient { + /** + * @inheritdoc + */ + protected createServerConnector(): protocol.IServerConnector; + } + /** + * A mediator client, driver for the master server. + * + * The {@link MediatorSharedWorkerClient} is a class being a client connecting to the **master** server, following + * the SharedWorker's protocol. + * + * #### [Inherited] {@link MediatorSystem} + * @copydoc MediatorSystem + */ + class MediatorSharedWorkerClient extends MediatorClient { + /** + * @inheritdoc + */ + protected createServerConnector(): protocol.IServerConnector; + } +} +declare namespace samchon.templates.parallel { + /** + * A mediator server, driver for the master client. + * + * The {@link MediatorServer} is a class opening a server accepting the **master** client, following the protocol of + * Samchon Framework's own. + * + * #### [Inherited] {@link MediatorSystem} + * @copydoc MediatorSystem + */ + class MediatorServer extends MediatorSystem implements slave.ISlaveServer { + /** + * @hidden + */ + private server_base_; + /** + * @hidden + */ + private port; + /** + * Initializer Constructor. + * + * @param systemArray The parent {@link ParallelSystemArrayMediator} object. + * @param port Port number of server to open. + */ + constructor(systemArray: ParallelSystemArrayMediator, port: number); + /** + * Initializer Constructor. + * + * @param systemArray The parent {@link DistributedSystemArrayMediator} object. + * @param port Port number of server to open. + */ + constructor(systemArray: distributed.DistributedSystemArrayMediator, port: number); + /** + * Factory method creating {@link IServerBase} object. + * + * This method {@link createServerBase createServerBase()} determines which protocol is used in this server, + * {@link MediatorServer}. Note that, **slave** (this {@link MediatorServer} object) must follow the **master**'s + * protocol. + * + * Overrides and return one of them considering the which protocol to follow: + * + * - {@link ServerBase} + * - {@link WebServerBase} + * - {@link SharedWorkerServerBase} + */ + protected createServerBase(): protocol.IServerBase; + /** + * Add a newly connected remote client. + * + * {@link MediatorServer} represents a **slave** dedicating to its **master**. In that reason, the + * {@link MediatorServer} does not accept multiple **master** clients. It accepts only one. Thus, *listener* of + * the *communicator* is {@link MediatorSystem} object, itself. + * + * @param driver A communicator with remote client. + */ + addClient(driver: protocol.IClientDriver): void; + /** + * @inheritdoc + */ + start(): void; + /** + * @inheritdoc + */ + open(port: number): void; + /** + * @inheritdoc + */ + close(): void; + } + /** + * A mediator server, driver for the master client. + * + * The {@link MediatorWebServer} is a class opening a server accepting the **master** client, following the + * web-socket protocol. + * + * #### [Inherited] {@link MediatorSystem} + * @copydoc MediatorSystem + */ + class MediatorWebServer extends MediatorServer { + /** + * @inheritdoc + */ + protected createServerBase(): protocol.IServerBase; + } + /** + * A mediator server, driver for the master client. + * + * The {@link MediatorDedicatedWorkerServer} is a class opening a server accepting the **master** client, following + * the DedicatedWorker's protocol. + * + * #### [Inherited] {@link MediatorSystem} + * @copydoc MediatorSystem + */ + class MediatorDedicatedWorkerServer extends MediatorServer { + /** + * @inheritdoc + */ + protected createServerBase(): protocol.IServerBase; + } + /** + * A mediator server, driver for the master client. + * + * The {@link MediatorSharedWorkerServer} is a class opening a server accepting the **master** client, following the + * SharedWorker's protocol. + * + * #### [Inherited] {@link MediatorSystem} + * @copydoc MediatorSystem + */ + class MediatorSharedWorkerServer extends MediatorServer { + /** + * @inheritdoc + */ + protected createServerBase(): protocol.IServerBase; + } +} +declare namespace samchon.templates.parallel { + /** + * Master of Parallel Processing System, a server accepting slave clients. + * + * The {@link ParallelClientArray} is an abstract class, derived from the {@link ParallelSystemArray} class, opening + * a server accepting {@link ParallelSystem parallel clients}. + * + * Extends this {@link ParallelClientArray}, overrides {@link createServerBase createServerBase()} to determine which + * protocol to follow and {@link createExternalClient createExternalClient()} creating child {@link ParallelSystem} + * object. After the extending and overridings, open this server using the {@link open open()} method. + * + * #### [Inherited] {@link ParallelSystemArray} + * @copydoc ParallelSystemArray + */ + abstract class ParallelClientArray extends ParallelSystemArray implements external.IExternalClientArray { + /** + * @hidden + */ + private server_base_; + /** + * Default Constructor. + */ + constructor(); + /** + * Factory method creating {@link IServerBase} object. + * + * This method {@link createServerBase createServerBase()} determines which protocol is used in this server, + * {@link ExternalClientArray}. If the protocol is determined, then {@link ExternalSystem external clients} who + * may connect to {@link ExternalClientArray this server} must follow the specified protocol. + * + * Overrides the {@link createServerBase createServerBase()} method to create and return one of them: + * + * - {@link ServerBase} + * - {@link WebServerBase} + * - {@link SharedWorkerServerBase} + * + * @return A new {@link IServerBase} object. + */ + protected abstract createServerBase(): protocol.IServerBase; + /** + * Add a newly connected remote client. + * + * When a {@link IClientDriver remote client} connects to this *master server of parallel processing system*, + * then this {@link ParallelClientArray} creates a child {@link ParallelSystem parallel client} object through + * the {@link createExternalClient createExternalClient()} method and {@link insert inserts} it. + * + * @param driver A communicator for external client. + */ + addClient(driver: protocol.IClientDriver): void; + /** + * (Deprecated) Factory method creating child object. + * + * The method {@link createChild createChild()} is deprecated. Don't use and override this. + * + * Note that, the {@link ParallelClientArray} is a server accepting {@link ParallelSystem parallel clients}. + * There's no way to creating the {@link ParallelSystem parallel clients} in advance before opening the server. + * + * @param xml An {@link XML} object represents the child {@link ParallelSystem} object. + * @return ```null``` + */ + createChild(xml: library.XML): System; + /** + * Factory method creating {@link ParallelSystem} object. + * + * The method {@link createExternalClient createExternalClient()} is a factory method creating a child + * {@link ParallelSystem} object, that is called whenever a parallel client has connected, by + * {@link addClient addClient()}. + * + * Overrides this {@link createExternalClient} method and creates a type of {@link ParallelSystem} object with + * the *driver* that communicates with the parallel client. After the creation, returns the {@link ParallelSystem} + * object. Then whenever a parallel client has connected, matched {@link ParallelSystem} object will be + * constructed and {@link insert inserted} into this {@link ParallelClientArray} object. + * + * @param driver A communicator with the parallel client. + * @return A newly created {@link ParallelSystem} object. + */ + protected abstract createExternalClient(driver: protocol.IClientDriver): System; + /** + * @inheritdoc + */ + open(port: number): void; + /** + * @inheritdoc + */ + close(): void; + } +} +declare namespace samchon.templates.parallel { + /** + * Mediator of Parallel Processing System. + * + * The {@link ParallelSystemArrayMediator} class be a **master** for its slave systems, and be a **slave** to its + * master system at the same time. This {@link ParallelSystemArrayMediator} be a **master **system, containing and + * managing {@link ParallelSystem} objects, which represent parallel slave systems, by extending + * {@link ParallelSystemArray} class. Also, be a **slave** system through {@link getMediator mediator} object, which is + * derived from the {@link SlaveSystem} class. + * + * As a **master**, you can specify this {@link ParallelSystemArrayMediator} class to be a master server accepting + * slave clients or a master client to connecting slave servers. Even both of them is possible. Extends one + * of them below and overrides abstract factory method(s) creating the child {@link ParallelSystem} object. + * + * - {@link ParallelClientArrayMediator}: A server accepting {@link ParallelSystem parallel clients}. + * - {@link ParallelServerArrayMediator}: A client connecting to {@link ParallelServer parallel servers}. + * - {@link ParallelServerClientArrayMediator}: Both of them. Accepts {@link ParallelSystem parallel clients} and + * connects to {@link ParallelServer parallel servers} at the same time. + * + * As a **slave**, you can specify this {@link ParallelSystemArrayMediator} to be a client slave connecting to + * master server or a server slave accepting master client by overriding the {@link createMediator} method. + * Overrides the {@link createMediator createMediator()} method and return one of them: + * + * - A client slave connecting to master server: + * - {@link MediatorClient} + * - {@link MediatorWebClient} + * - {@link MediatorSharedWorkerClient} + * - A server slave accepting master client: + * - {@link MediatorServer} + * - {@link MediatorWebServer} + * - {@link MediatorDedicatedWorkerServer} + * - {@link MediatorSharedWorkerServer} + * + * #### [Inherited] {@link ParallelSystemArray} + * @copydoc ParallelSystemArray + */ + abstract class ParallelSystemArrayMediator extends ParallelSystemArray { + /** + * @hidden + */ + private mediator_; + /** + * Default Constructor. + */ + constructor(); + /** + * Factory method creating a {@link MediatorSystem} object. + * + * The {@link createMediator createMediator()} is an abstract method creating the {@link MediatorSystem} object. + * + * You know what? this {@link ParallelSystemArrayMediator} class be a **master** for its slave systems, and be a + * **slave** to its master system at the same time. The {@link MediatorSystem} object makes it possible; be a + * **slave** system. This {@link createMediator} determines specific type of the {@link MediatorSystem}. + * + * Overrides the {@link createMediator createMediator()} method to create and return one of them following which + * protocol and which type of remote connection (server or client) will be used: + * + * - A client slave connecting to master server: + * - {@link MediatorClient} + * - {@link MediatorWebClient} + * - {@link MediatorSharedWorkerClient} + * - A server slave accepting master client: + * - {@link MediatorServer} + * - {@link MediatorWebServer} + * - {@link MediatorDedicatedWorkerServer} + * - {@link MediatorSharedWorkerServer} + * + * @return A newly created {@link MediatorSystem} object. + */ + protected abstract createMediator(): MediatorSystem; + /** + * Start mediator. + * + * If the {@link getMediator mediator} is a type of server, then opens the server accepting master client. + * Otherwise, the {@link getMediator mediator} is a type of client, then connects the master server. + */ + protected startMediator(): void; + /** + * Get {@link MediatorSystem} object. + * + * When you need to send an {@link Invoke} message to the master system of this + * {@link ParallelSystemArrayMediator}, then send to the {@link MediatorSystem} through this {@link getMediator}. + * + * ```typescript + * this.getMediator().sendData(...); + * ``` + * + * @return The {@link MediatorSystem} object. + */ + getMediator(): MediatorSystem; + /** + * @hidden + */ + protected _Complete_history(history: slave.InvokeHistory): boolean; + } +} +declare namespace samchon.templates.parallel { + /** + * Mediator of Parallel Processing System, a server accepting slave clients. + * + * The {@link ParallelClientArrayMediator} is an abstract class, derived from the {@link ParallelSystemArrayMediator} + * class, opening a server accepting {@link ParallelSystem parallel clients} as a **master**. + * + * Extends this {@link ParallelClientArrayMediator}, overrides {@link createServerBase createServerBase()} to + * determine which protocol to follow and {@link createExternalClient createExternalClient()} creating child + * {@link ParallelSystem} object. After the extending and overridings, open this server using the + * {@link open open()} method. + * + * #### [Inherited] {@link ParallelSystemArrayMediator} + * @copydoc ParallelSystemArrayMediator + */ + abstract class ParallelClientArrayMediator extends ParallelSystemArrayMediator implements external.IExternalClientArray { + /** + * @hidden + */ + private server_base_; + /** + * Default Constructor. + */ + constructor(); + /** + * Factory method creating {@link IServerBase} object. + * + * This method {@link createServerBase createServerBase()} determines which protocol is used in this server, + * {@link ParallelClientArrayMediator}. If the protocol is determined, then + * {@link ParallelSystem parallel clients} who may connect to {@link ParallelClientArrayMediator this server} + * must follow the specified protocol. + * + * Overrides the {@link createServerBase createServerBase()} method to create and return one of them: + * + * - {@link ServerBase} + * - {@link WebServerBase} + * - {@link SharedWorkerServerBase} + * + * @return A new {@link IServerBase} object. + */ + protected abstract createServerBase(): protocol.IServerBase; + /** + * Add a newly connected remote client. + * + * When a {@link IClientDriver remote client} connects to this *master server of parallel processing system*, + * then this {@link ParallelClientArrayMediator} creates a child {@link ParallelSystem parallel client} object + * through the {@link createExternalClient createExternalClient()} method and {@link insert inserts} it. + * + * @param driver A communicator for parallel client. + */ + addClient(driver: protocol.IClientDriver): void; + /** + * (Deprecated) Factory method creating child object. + * + * The method {@link createChild createChild()} is deprecated. Don't use and override this. + * + * Note that, the {@link ParallelClientArrayMediator} is a server accepting {@link ParallelSystem parallel + * clients} as a master. There's no way to creating the {@link ParallelSystem parallel clients} in advance before + * opening the server. + * + * @param xml An {@link XML} object represents the child {@link ParallelSystem} object. + * @return null + */ + createChild(xml: library.XML): System; + /** + * Factory method creating {@link ParallelSystem} object. + * + * The method {@link createExternalClient createExternalClient()} is a factory method creating a child + * {@link ParallelSystem} object, that is called whenever a parallel client has connected, by + * {@link addClient addClient()}. + * + * Overrides this {@link createExternalClient} method and creates a type of {@link ParallelSystem} object with + * the *driver* that communicates with the parallel client. After the creation, returns the {@link ParallelSystem} + * object. Then whenever a parallel client has connected, matched {@link ParallelSystem} object will be + * constructed and {@link insert inserted} into this {@link ParallelClientArrayMediator} object. + * + * @param driver A communicator with the parallel client. + * @return A newly created {@link ParallelSystem} object. + */ + protected abstract createExternalClient(driver: protocol.IClientDriver): System; + /** + * @inheritdoc + */ + open(port: number): void; + /** + * @inheritdoc + */ + close(): void; + } +} +declare namespace samchon.templates.parallel { + /** + * A driver for parallel slave server. + * + * The {@link ParallelServer} is an abstract class, derived from the {@link ParallelSystem} class, connecting to + * remote, parallel **slave** server. Extends this {@link ParallelServer} class and overrides the + * {@link createServerConnector createServerConnector()} method following which protocol the **slave** server uses. + * + * #### [Inherited] {@link ParallelSystem} + * @copydoc ParallelSystem + */ + abstract class ParallelServer extends ParallelSystem implements IParallelServer { + /** + * IP address of target external system to connect. + */ + protected ip: string; + /** + * Port number of target external system to connect. + */ + protected port: number; + /** + * Construct from parent {@link ParallelSystemArray}. + * + * @param systemArray The parent {@link ParallelSystemArray} object. + */ + constructor(systemArray: ParallelSystemArray); + /** + * Factory method creating {@link IServerConnector} object. + * + * The {@link createServerConnector createServerConnector()} is an abstract method creating + * {@link IServerConnector} object. Overrides and returns one of them, considering which protocol the slave server + * follows: + * + * - {@link ServerConnector} + * - {@link WebServerConnector} + * - {@link DedicatedWorkerServerConnector} + * - {@link SharedWorkerServerConnector} + * + * @return A newly created {@link IServerConnector} object. + */ + protected abstract createServerConnector(): protocol.IServerConnector; + /** + * @inheritdoc + */ + connect(): void; + } +} +declare namespace samchon.templates.parallel { + /** + * Master of Parallel Processing System, a client connecting to slave servers. + * + * The {@link ParallelServerArray} is an abstract class, derived from the {@link ParallelSystemArray} class, + * connecting to {@link IParallelServer parallel servers}. + * + * Extends this {@link ParallelServerArray} and overrides {@link createChild createChild()} method creating child + * {@link IParallelServer} object. After the extending and overriding, construct children {@link IParallelServer} + * objects and call the {@link connect connect()} method. + * + * #### [Inherited] {@link ParallelSystemArray} + * @copydoc ParallelSystemArray + */ + abstract class ParallelServerArray extends ParallelSystemArray implements external.IExternalServerArray { + /** + * Default Constructor. + */ + constructor(); + /** + * @inheritdoc + */ + connect(): void; + } +} +declare namespace samchon.templates.parallel { + /** + * Mediator of Parallel Processing System, a client connecting to slave servers. + * + * The {@link ParallelServerArrayMediator} is an abstract class, derived from the {@link ParallelSystemArrayMediator} + * class, connecting to {@link IParallelServer parallel servers}. + * + * Extends this {@link ParallelServerArrayMediator} and overrides {@link createChild createChild()} method creating + * child {@link IParallelServer} object. After the extending and overriding, construct children + * {@link IParallelServer} objects and call the {@link connect connect()} method. + * + * #### [Inherited] {@link ParallelSystemArrayMediator} + * @copydoc ParallelSystemArrayMediator + */ + abstract class ParallelServerArrayMediator extends ParallelSystemArrayMediator implements external.IExternalServerArray { + /** + * Default Constructor. + */ + constructor(); + /** + * @inheritdoc + */ + connect(): void; + } +} +declare namespace samchon.templates.parallel { + /** + * Master of Parallel Processing System, be a server and client at the same time. + * + * The {@link ParallelServerClientArray} is an abstract class, derived from the {@link ParallelSystemArray} class, + * opening a server accepting {@link ParallelSystem parallel clients} and being a client connecting to + * {@link IParallelServer parallel servers} at the same time. + * + * Extends this {@link ParallelServerClientArray} and overrides below methods. After the overridings, open server + * with {@link open open()} method and connect to {@link IParallelServer parallel servers} through the + * {@link connect connect()} method. + * + * - {@link createServerBase createServerBase()} + * - {@link createExternalClient createExternalClient()} + * - {@link createExternalServer createExternalServer()} + * + * #### [Inherited] {@link ParallelSystemArray} + * @copydoc ParallelClientArray + */ + abstract class ParallelServerClientArray extends ParallelClientArray implements external.IExternalServerClientArray { + /** + * Default Constructor. + */ + constructor(); + /** + * Factory method of a child Entity. + * + * This method is migrated to {@link createExternalServer}. Override the {@link createExternalServer} method. + * + * @param xml An {@link XML} object represents child element, so that can identify the type of child to create. + * @return A new child Entity via {@link createExternalServer createExternalServer()}. + */ + createChild(xml: library.XML): System; + /** + * Factory method creating an {@link IParallelServer} object. + * + * @param xml An {@link XML} object represents child element, so that can identify the type of child to create. + * @return A newly created {@link IParallelServer} object. + */ + protected abstract createExternalServer(xml: library.XML): System; + /** + * @inheritdoc + */ + connect(): void; + } +} +declare namespace samchon.templates.parallel { + /** + * Mediator of Parallel Processing System, be a server and client at the same time as a **master**. + * + * The {@link ParallelServerClientArrayMediator} is an abstract class, derived from the + * {@link ParallelSystemArrayMediator} class, opening a server accepting {@link ParallelSystem parallel clients} and + * being a client connecting to {@link IParallelServer parallel servers} at the same time. + * + * Extends this {@link ParallelServerClientArrayMediator} and overrides below methods. After the overridings, open + * server with {@link open open()} method and connect to {@link IParallelServer parallel servers} through the + * {@link connect connect()} method. + * + * - {@link createServerBase createServerBase()} + * - {@link createExternalClient createExternalClient()} + * - {@link createExternalServer createExternalServer()} + * + * #### [Inherited] {@link ParallelSystemArrayMediator} + * @copydoc ParallelClientArrayMediator + */ + abstract class ParallelServerClientArrayMediator extends ParallelClientArrayMediator implements external.IExternalServerClientArray { + /** + * Default Constructor. + */ + constructor(); + /** + * Factory method of a child Entity. + * + * This method is migrated to {@link createExternalServer}. Override the {@link createExternalServer} method. + * + * @param xml An {@link XML} object represents child element, so that can identify the type of child to create. + * @return A new child Entity via {@link createExternalServer createExternalServer()}. + */ + createChild(xml: library.XML): System; + /** + * Factory method creating an {@link IParallelServer} object. + * + * @param xml An {@link XML} object represents child element, so that can identify the type of child to create. + * @return A newly created {@link IParallelServer} object. + */ + protected abstract createExternalServer(xml: library.XML): System; + /** + * @inheritdoc + */ + connect(): void; + } +} +declare namespace samchon.templates.parallel { + /** + * An interface for a parallel slave server driver. + * + * The easiest way to defining a driver for parallel **slave** server is extending {@link ParallelServer} class. + * However, if you've to interact with a prallel **slave** system who can be both server and client, them make a class + * (let's name it **BaseSystem**) extending the {@link ParallelSystem} class. At next, make a new class (now, I name it + * **BaseServer**) extending the **BaseSystem** and implements this interface {@link IParallelServer}. Define the + * **BaseServer** following those codes on below: + * + * + * + * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System) + * @author Jeongho Nam + */ + interface IParallelServer extends ParallelSystem { + /** + * Connect to slave server. + */ + connect(): void; + } +} +declare namespace samchon.templates.parallel { + /** + * History of an {@link Invoke} message. + * + * The {@link PRInvokeHistory} is a class archiving history log of an {@link Invoke} message which requests the + * *parallel process*, created whenever {@link ParallelSystemArray.sendSegmentData} or + * {@link ParallelSystemArray.sendSegmentData} is called. + * + * When the *parallel process* has completed, then {@link complete complete()} is called and the *elapsed time* is + * determined. The elapsed time is utilized for computation of {@link ParallelSystem.getPerformance performance index} + * of each {@link ParallelSystem parallel slave system}. + * + * + * + * + * + * @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System) + * @author Jeongho Nam + */ + class PRInvokeHistory extends slave.InvokeHistory { + /** + * @hidden + */ + private first; + /** + * @hidden + */ + private last; + /** + * Default Constructor. + */ + constructor(); + /** + * Construct from an {@link Invoke} message. + * + * @param invoke An {@link Invoke} message requesting a *parallel process*. + */ + constructor(invoke: protocol.Invoke); + /** + * Get initial piece's index. + * + * Returns initial piece's index in the section of requested *parallel process*. + * + * @return The initial index. + */ + getFirst(): number; + /** + * Get final piece's index. + * + * Returns initial piece's index in the section of requested *parallel process*. The range used is + * [*first*, *last*), which contains all the pieces' indices between *first* and *last*, including the piece + * pointed by index *first*, but not the piece pointed by the index *last*. + * + * @return The final index. + */ + getLast(): number; + /** + * Compute number of allocated pieces. + */ + computeSize(): number; + } +} +declare namespace samchon.templates.service { + /** + * A driver of remote client. + * + * The {@link Client} is an abstract class representing and interacting with a remote client. It deals the network + * communication with the remote client and shifts {@link Invoke} message to related {@link User} and {@link Service} + * objects. + * + * Extends this {@link Client} class and override the {@link createService} method, a factory method creating a child + * {@link Service} object. Note that, {@link Client} represents a remote client, not *an user*, a specific *web page* + * or *service*. Do not define logics about user or account information. It must be declared in the parent + * {@link User} class. Also, don't define processes of a specific a web page or service. Defines them in the child + * {@link Service} class. + * + * + * + * + * + * @handbook [Templates - Cloud Service](https://github.com/samchon/framework/wiki/TypeScript-Templates-Cloud_Service) + * @author Jeongho Nam + */ + abstract class Client implements protocol.IProtocol { + /** + * @hidden + */ + private user_; + /** + * @hidden + */ + private no_; + /** + * @hidden + */ + private communicator_; + /** + * @hidden + */ + private service_; + /** + * Construct from parent {@link User} and communicator. + * + * @param user Parent {@link User} object. + * @param driver Communicator with remote client. + */ + constructor(user: User, driver: protocol.WebClientDriver); + /** + * Default Destructor. + * + * This {@link destructor destructor()} method is called when the {@link Client} object is destructed and this + * {@link Client} object is destructed when connection with the remote client is closed or this {@link Client} + * object is {@link User.erase erased} from its parent {@link User} object. + * + * Note that, don't call this {@link destructor destructor()} method by yourself. It must be called automatically + * by those *destruction* cases. Also, if your derived {@link Client} class has something to do on the + * *destruction*, then overrides this {@link destructor destructor()} method and defines the something to do. + * Overriding this {@link destructor destructor()}, don't forget to calling ```super.destructor();``` on tail. + * + * ```typescript + * class MyUser extends protocol.service.Client + * { + * protected destructor(): void + * { + * // DO SOMETHING + * this.do_something(); + * + * // CALL SUPER.DESTRUCTOR() ON TAIL. DON'T FORGET THIS + * super.destructor(); + * } + * } + * ``` + */ + protected destructor(): void; + /** + * Factory method creating {@link Service} object. + * + * @param path Requested path. + * @return A newly created {@link Service} object or ```null```. + */ + protected abstract createService(path: string): Service; + /** + * Close connection. + */ + close(): void; + /** + * Get parent {@link User} object. + * + * Get the parent {@link User} object, who is groupping {@link Client} objects with same session id. + * + * @return The parent {@link User} object. + */ + getUser(): User; + /** + * Get child {@link Service} object. + * + * @return The child {@link Service} object. + */ + getService(): Service; + /** + * Get sequence number. + * + * Get sequence number of this {@link Client} object in the parent {@link User} object. This sequence number also + * be a *key* in the parent {@link User} object, who extended the ```std.HashMap```. + * + * @return Sequence number. + */ + getNo(): number; + /** + * Change related {@link Service} object. + * + * @param path Requested, identifier path. + */ + protected changeService(path: string): void; + /** + * Change {@link Service} to another. + * + * @param service {@link service} object to newly assigned. + */ + protected changeService(service: Service): void; + /** + * Send an {@link Invoke} message. + * + * Sends an {@link Invoke} message to remote client. + * + * @param invoke An {@link Invoke} messgae to send to remote client. + */ + sendData(invoke: protocol.Invoke): void; + /** + * Handle a replied {@link Invoke} message. + * + * The default {@link Client.replyData Client.replyData()} shifts chain to its parent {@link User} and belonged + * {@link Service} objects, by calling the the {@link User.replyData User.replyData()} and + * {@link Service.replyData Service.replyData()} methods. + * + * Note that, {@link Client} represents a remote client, not *an user*, a specific *web page* or *service*. Do not + * define logics about user or account information. It must be declared in the parent {@link User} class. Also, + * don't define processes of a specific a web page or service. Defines them in the child {@link Service} class. + * + * ```typescript + * class protocol.service.Client + * { + * public replyData(invoke: protocol.Invoke): void + * { + * // SHIFT TO PARENT USER + * // THE PARENT USER ALSO MAY SHIFT TO ITS PARENT SERVER + * this.getUser().replyData(invoke); + * + * // SHIFT TO BELOGED SERVICE + * if (this.getService() != null) + * this.getService().replyData(invoke); + * } + * } + * + * class MyClient extends protocol.service.Client + * { + * public replyData(invoke: protocol.Invoke): void + * { + * if (invoke.getListener() == "do_something_in_client_level") + * this.do_something_in_client_level(); + * else + * super.replyData(invoke); + * } + * } + * ``` + * + * @param invoke An {@link Invoke invoke} message to be handled in {@link Client} level. + */ + replyData(invoke: protocol.Invoke): void; + } +} +/** + * A system template for Cloud Service. + * + * @handbook [Templates - Cloud Service](https://github.com/samchon/framework/wiki/TypeScript-Templates-Cloud_Service) + * @author Jeongho Nam + */ +declare namespace samchon.templates.service { + /** + * A cloud server. + * + * The {@link Server} is an abstract server class, who can build a real-time cloud server, that is following the + * web-socket protocol. Extends this {@link Server} and related classes and overrides abstract methods under below. + * After the overridings, open this {@link Server cloud server} using the {@link open open()} method. + * + * - Objects in composite relationship and their factory methods + * - {@link User}: {@link Server.createUser Server.createUser()} + * - {@link Client}: {@link User.createClient User.createClient()} + * - {@link Service}: {@link Client.createService Client.createService()} + * - {@link Invoke} message chains; {@link IProtocol.replyData replyData} + * - {@link Server.replyData} + * - {@link User.replyData} + * - {@link Client.replyData} + * - {@link Service.replyData} + * + * + * + * + * + * @handbook [Templates - Cloud Service](https://github.com/samchon/framework/wiki/TypeScript-Templates-Cloud_Service) + * @author Jeongho Nam + */ + abstract class Server extends protocol.WebServer implements protocol.IProtocol { + /** + * @hidden + */ + private session_map_; + /** + * @hidden + */ + private account_map_; + /** + * Default Constructor. + */ + constructor(); + /** + * Factory method creating {@link User} object. + * + * @return A newly created {@link User} object. + */ + protected abstract createUser(): User; + /** + * Test wheter an {@link User} exists with the *accountID*. + * + * @param accountID Account id of {@link User} to find. + * @return Exists or not. + */ + has(accountID: string): boolean; + /** + * Get an {@link User} object by its *accountID*. + * + * @param accountID Account id of {@link User} to get. + * @return An {@link User} object. + */ + get(accountID: string): User; + /** + * Send an {@link Invoke} message. + * + * Sends an {@link Invoke} message to all remote clients through the belonged {@link User} and {@link Client} + * objects. Sending the {@link Invoke} message to all remote clients, it's came true by passing through + * {@link User.sendData User.sendData()}. And the {@link User.sendData} also pass through the + * {@link Client.sendData Client.sendData()}. + * + * ```typescript + * class protocol.service.Server + * { + * public sendData(invoke: Invoke): void + * { + * for (user: User in this) + * for (client: Client in user) + * client.sendData(invoke); + * } + * } + * ``` + * + * @param invoke {@link Invoke} message to send to all remote clients. + */ + sendData(invoke: protocol.Invoke): void; + /** + * Handle a replied {@link Invoke} message. + * + * The {@link Server.replyData Server.replyData()} is an abstract method that handling {@link Invoke} message + * that should be handled in the {@link Server} level. Overrides this {@link replyData replyData()} method and + * defines what to do with the {@link Invoke} message in this {@link Server} level. + * + * @param invoke An {@link Invoke invoke} message to be handled in {@link Server} level. + */ + abstract replyData(invoke: protocol.Invoke): void; + /** + * Add a newly connected remote client. + * + * When a {@link WebClientDriver remote client} connects to this cloud server, then {@link Server} queries the + * {WebClientDriver.getSessionID session id} of the {@link WebClientDriver remote client}. If the + * {WebClientDriver.getSessionID session id} is new one, then creates a new {@link User} object. + * + * At next, creates a {@link Client} object who represents the newly connected remote client and insert the + * {@link Client} object to the matched {@link User} object which is new or ordinary one following the + * {WebClientDriver.getSessionID session id}. At last, a {@link Service} object can be created with referencing + * the {@link WebClientDriver.getPath path}. + * + * List of objects can be created by this method. + * - {@link User} by {@link createUser createUser()}. + * - {@link Client} by {@link User.createClient User.createClient()}. + * - {@link Service} by {@link Client.createService Client.createService()}. + * + * @param driver A web communicator for remote client. + */ + addClient(driver: protocol.WebClientDriver): void; + /** + * @hidden + */ + private _Erase_user(user); + } +} +declare namespace samchon.templates.service { + /** + * A service. + * + * The {@link Service} is an abstract class who represents a service, that is providing functions a specific page. + * + * Extends the {@link Service} class and defines its own service, which to be provided for the specific weg page, + * by overriding the {@link replyData replyData()} method. Note that, the service, functions for the specific page + * should be defined in this {@link Service} class, not its parent {@link Client} class who represents a remote client + * and takes communication responsibility. + * + * + * + * + * + * @handbook [Templates - Cloud Service](https://github.com/samchon/framework/wiki/TypeScript-Templates-Cloud_Service) + * @author Jeongho Nam + */ + abstract class Service implements protocol.IProtocol { + /** + * @hidden + */ + private client_; + /** + * @hidden + */ + private path_; + /** + * Construct from parent {@link Client} and requested path. + * + * @param client Driver of remote client. + * @param path Requested path that identifies this {@link Service}. + */ + constructor(client: Client, path: string); + /** + * Default Destructor. + * + * This {@link destructor destructor()} method is call when the {@link Service} object is destructed and the + * {@link Service} object is destructed when its parent {@link Client} object has + * {@link Client.destructor destructed} or the {@link Client} object {@link Client.changeService changed} its + * child {@link Service service} object to another one. + * + * Note that, don't call this {@link destructor destructor()} method by yourself. It must be called automatically + * by those *destruction* cases. Also, if your derived {@link Service} class has something to do on the + * *destruction*, then overrides this {@link destructor destructor()} method and defines the something to do. + */ + protected destructor(): void; + /** + * Get client. + */ + getClient(): Client; + /** + * Get requested path. + */ + getPath(): string; + /** + * Send an {@link Invoke} message. + * + * Sends an {@link Invoke} message to remote system through parent {@link Client} object ({@link Client.sendData}). + * + * @param invoke An {@link Invoke} message to send to the remte system. + */ + sendData(invoke: protocol.Invoke): void; + /** + * @inheritdoc + */ + abstract replyData(invoke: protocol.Invoke): void; + } +} +declare namespace samchon.templates.service { + /** + * An user. + * + * The {@link User} is an abstract class groupping {@link Client} objects, who communicates with remote client, with + * same *session id*. This {@link User} represents a *remote user* literally. Within framework of remote system, + * an {@link User} corresponds to a web-browser and a {@link Client} represents a window in the web-browser. + * + * Extends this {@link User} class and override the {@link createClient} method, a factory method creating a child + * {@link Client} object. I repeat, the {@link User} class represents a *remote user*, groupping {@link Client} + * objects with same *session id*. If your cloud server has some processes to be handled in the **user level**, then + * defines method in this {@link User} class. Methods managing **account** under below are some of them: + * + * - {@link setAccount setAccount()} + * - {@link getAccountID getAccountID()} + * - {@link getAuthority getAuthority()} + * + * The children {@link Client} objects, they're contained with their key, the {@link Client.getNo sequence number}. + * If you {@link User.erase erase} the children {@link Client} object by yourself, then their connection with the + * remote clients will be {@link Client.close closed} and their {@link Client.destructor destruction method} will be + * called. If you remove {@link clear all children}, then this {@link User} object will be also + * {@link destructor destructed} and erased from the parent {@link Server} object. + * + * + * + * + * + * @handbook [Templates - Cloud Service](https://github.com/samchon/framework/wiki/TypeScript-Templates-Cloud_Service) + * @author Jeongho Nam + */ + abstract class User extends collections.HashMapCollection implements protocol.IProtocol { + /** + * @hidden + */ + private server_; + /** + * @hidden + */ + private session_id_; + /** + * @hidden + */ + private sequence_; + /** + * @hidden + */ + private account_id_; + /** + * @hidden + */ + private authority_; + /** + * Construct from its parent {@link Server}. + * + * @param server The parent {@link Server} object. + */ + constructor(server: Server); + /** + * Default Destructor. + * + * This {@link destructor destructor()} method is called when the {@link User} object is destructed. The + * {@link User} object is destructed when connections with the remote clients are all closed, that is all the + * children {@link Client} objects are all removed, and 30 seconds has left. If some remote client connects + * within the 30 seconds, then the {@link User} object doesn't be destructed. + * + * Note that, don't call this {@link destructor destructor()} method by yourself. It must be called automatically + * by those *destruction* cases. Also, if your derived {@link User} class has something to do on the + * *destruction*, then overrides this {@link destructor destructor()} method and defines the something to do. + * Overriding this {@link destructor destructor()}, don't forget to calling ```super.destructor();``` on tail. + * + * ```typescript + * class MyUser extends protocol.service.User + * { + * protected destructor(): void + * { + * // DO SOMETHING + * this.do_something(); + * + * // CALL SUPER.DESTRUCTOR() ON TAIL. DON'T FORGET THIS + * super.destructor(); + * } + * } + * ``` + */ + protected destructor(): void; + /** + * Factory method creating a {@link Client} object. + * + * @param driver A web communicator for remote client. + * @return A newly created {@link Client} object. + */ + protected abstract createClient(driver: protocol.WebClientDriver): Client; + /** + * @hidden + */ + private _Handle_erase_client(event); + /** + * Get parent {@lin Server} object. + * + * @return Parent {@link Server} object. + */ + getServer(): Server; + /** + * Get account id. + * + * @return Account ID. + */ + getAccountID(): string; + /** + * Get authority. + * + * @return Authority + */ + getAuthority(): number; + /** + * Set *account id* and *authority*. + * + * The {@link setAccount setAccount()} is a method configuring *account id* and *authority* of this {@link User}. + * + * After the configuring, the {@link getAccountID account id} is enrolled into the parent {@link Server} as a + * **key** for this {@link User} object. You can test existence and access this {@link User} object from + * {@link Server.has Server.has()} and {@link Server.get Server.get()} with the {@link getAccountID account id}. + * Of course, if ordinary {@link getAccountID account id} had existed, then the ordinary **key** will be + * replaced. + * + * As you suggest, this {@link setAccount setAccount()} is something like a **log-in** function. If what you want + * is not **logging-in**, but **logging-out**, then configure the *account id* to empty string ``""```` or call + * the {@link lgout logout()} method. + * + * @param id To be account id. + * @param authority To be authority. + */ + setAccount(id: string, authority: number): void; + /** + * Log-out. + * + * This {@link logout logout()} method configures {@link getAccountID account id} to empty string and + * {@link getAuthority authority} to zero. + * + * The ordinary {@link getAccountID account id} will be also erased from the parent {@link Server} object. You + * can't access this {@link User} object from {@link Server.has Server.has()} and {@link Server.get Server.get()} + * with the ordinary {@link getAccountID account id} more. + */ + logout(): void; + /** + * Send an {@link Invoke} message. + * + * Sends an {@link Invoke} message to all remote clients through the belonged {@link Client} objects. Sending the + * {@link Invoke} message to all remote clients, it's came true by passing through the + * {@link Client.sendData Client.sendData()} methods. + * + * ```typescript + * class protocol.service.User + * { + * public sendData(invoke: Invoke): void + * { + * for (let it = this.begin(); !it.equals(this.end()); it = it.next()) + * it.second.sendData(invoke); + * } + * } + * ``` + * + * @param invoke {@link Invoke} message to send to all remote clients. + */ + sendData(invoke: protocol.Invoke): void; + /** + * Handle a replied {@link Invoke} message. + * + * The default {@link User.replyData User.replyData()} shifts chain to its parent {@link Server} object, by + * calling the {@link Server.replyData Server.replyData()} method. If there're some {@link Invoke} message to be + * handled in this {@link User} level, then override this method and defines what to do with the {@link Invoke} + * message in this {@link User} level. + * + * ```typescript + * class protocol.service.User + * { + * public replyData(invoke: protocol.Invoke): void + * { + * this.getServer().replyData(invoke); + * } + * } + * + * class MyUser extends protocol.service.User + * { + * public replyData(invoke: protocol.Invoke): void + * { + * if (invoke.apply(this) == false) // IS TARGET TO BE HANDLED IN THIS USER LEVEL + * super.replyData(invoke); // SHIFT TO SERVER + * } + * } + * ``` + * + * @param invoke An {@link Invoke invoke} message to be handled in {@link User} level. + */ + replyData(invoke: protocol.Invoke): void; + } +} +declare namespace samchon.templates.slave { + /** + * An {@link Invoke} message which represents a **process**. + * + * + * + * #### [Inherited] {@link Invoke} + * @copydoc Invoke + */ + class PInvoke extends protocol.Invoke { + /** + * @hidden + */ + private history_; + /** + * @hidden + */ + private slave_system_; + /** + * @hidden + */ + private hold_; + /** + * Initializer Constructor. + * + * @param invoke Original {@link Invoke} message. + * @param history {@link InvokeHistory} object archiving execution time. + * @param slaveSystem Related {@link SlaveSystem} object who gets those processes from its master. + */ + constructor(invoke: protocol.Invoke, history: InvokeHistory, slaveSystem: SlaveSystem); + /** + * Get history object. + * + * Get {@link InvokeHistory} object who is archiving execution time of this process. + */ + getHistory(): InvokeHistory; + /** + * Is the reporting hold? + */ + isHold(): boolean; + /** + * Hold reporting completion to master. + */ + hold(): void; + /** + * Report completion. + */ + complete(): void; + } +} +declare namespace samchon.templates.slave { + interface ISlaveClient extends SlaveSystem { + connect(ip: string, port: number): void; + } + abstract class SlaveClient extends SlaveSystem implements ISlaveClient { + /** + * Default Constructor. + */ + constructor(); + /** + * @inheritdoc + */ + protected abstract createServerConnector(): protocol.IServerConnector; + /** + * @inheritdoc + */ + connect(ip: string, port: number): void; + } +} +declare namespace samchon.templates.slave { + interface ISlaveServer extends SlaveSystem, protocol.IServer { + } + abstract class SlaveServer extends SlaveSystem implements ISlaveServer { + /** + * @hidden + */ + private server_base_; + /** + * Default Constructor. + */ + constructor(); + /** + * @inheritdoc + */ + protected abstract createServerBase(): protocol.IServerBase; + /** + * @inheritdoc + */ + open(port: number): void; + /** + * @inheritdoc + */ + close(): void; + /** + * @inheritdoc + */ + addClient(driver: protocol.IClientDriver): void; + } +} diff --git a/samchon/samchon-tests.ts b/samchon/samchon-tests.ts new file mode 100644 index 0000000000..3c805025ac --- /dev/null +++ b/samchon/samchon-tests.ts @@ -0,0 +1,2 @@ +import samchon = require("samchon"); +console.log(samchon); \ No newline at end of file diff --git a/samchon/tsconfig.json b/samchon/tsconfig.json new file mode 100644 index 0000000000..ec6c511b01 --- /dev/null +++ b/samchon/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": false, + "noImplicitThis": true, + "strictNullChecks": false, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "samchon-tests.ts" + ] +} \ No newline at end of file diff --git a/tstl/index.d.ts b/tstl/index.d.ts new file mode 100644 index 0000000000..c1bd7d7aeb --- /dev/null +++ b/tstl/index.d.ts @@ -0,0 +1,11136 @@ +// Type definitions for TSTL v1.3.10 +// Project: https://github.com/samchon/tstl +// Definitions by: Jeongho Nam +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module "tstl" +{ + export = std; +} + +/** + * # TypeScript-STL + * + * + * + * + * STL (Standard Template Library) Containers and Algorithms for TypeScript. + * + * **T**ypeScript-**STL** is a TypeScript's Standard Template Library who is migrated from C++ STL. Most of classes + * and functions of STL have implemented. Just enjoy it. + * + * @git https://github.com/samchon/tstl + * @author Jeongho Nam + */ +declare namespace std { +} +/** + * Base classes composing STL in background. + * + * @author Jeongho Nam + */ +declare namespace std.base { +} +declare namespace std { + /** + * Apply function to range. + * + * Applies function fn to each of the elements in the range [first, last). + * + * @param first An {@link Iterator} to the initial position in a sequence. + * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), + * which contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + * @param fn Unary function that accepts an element in the range as argument. This can either be a function p + * ointer or a move constructible function object. Its return value, if any, is ignored. + */ + function for_each, Func extends (val: T) => any>(first: InputIterator, last: InputIterator, fn: Func): Func; + /** + * Apply function to range. + * + * Applies function *fn* to each of the elements in the range [*first*, *first + n*). + * + * @param first An {@link Iterator} to the initial position in a sequence. + * @param n the number of elements to apply the function to + * @param fn Unary function that accepts an element in the range as argument. This can either be a function p + * ointer or a move constructible function object. Its return value, if any, is ignored. + * + * @return first + n + */ + function for_each_n>(first: InputIterator, n: number, fn: (val: T) => any): InputIterator; + /** + * Test condition on all elements in range. + * + * Returns true if pred returns true for all the elements in the range + * [first, last) or if the range is {@link Container.empty empty}, and false otherwise. + * + * + * @param first An {@link Iterator} to the initial position in a sequence. + * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), + * which contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + * @param pred Unary function that accepts an element in the range as argument and returns a value convertible to + * boolean. The value returned indicates whether the element fulfills the condition + * checked by this function. The function shall not modify its argument. + * + * @return true if pred returns true for all the elements in the range or if the range is + * {@link Container.empty empty}, and false otherwise. + */ + function all_of>(first: InputIterator, last: InputIterator, pred: (val: T) => boolean): boolean; + /** + * Test if any element in range fulfills condition. + * + * Returns true if pred returns true for any of the elements in the range + * [first, last), and false otherwise. + * + * If [first, last) is an {@link Container.empty empty} range, the function returns + * false. + * + * @param first An {@link Iterator} to the initial position in a sequence. + * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), + * which contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + * @param pred Unary function that accepts an element in the range as argument and returns a value convertible to + * boolean. The value returned indicates whether the element fulfills the condition + * checked by this function. The function shall not modify its argument. + * + * @return true if pred returns true for any of the elements in the range + * [first, last), and false otherwise. If [first, last) is an + * {@link Container.empty empty} range, the function returns false. + */ + function any_of>(first: InputIterator, last: InputIterator, pred: (val: T) => boolean): boolean; + /** + * Test if no elements fulfill condition. + * + * Returns true if pred returns false for all the elements in the range + * [first, last) or if the range is {@link Container.empty empty}, and false otherwise. + * + * @param first An {@link Iterator} to the initial position in a sequence. + * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), + * which contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + * @param pred Unary function that accepts an element in the range as argument and returns a value convertible to + * boolean. The value returned indicates whether the element fulfills the condition + * checked by this function. The function shall not modify its argument. + * + * @return true if pred returns false for all the elements in the range + * [first, last) or if the range is {@link Container.empty empty}, and false + * otherwise. + */ + function none_of>(first: InputIterator, last: InputIterator, pred: (val: T) => boolean): boolean; + /** + * Test whether the elements in two ranges are equal. + * + * Compares the elements in the range [first1, last1) with those in the range beginning at + * first2, and returns true if all of the elements in both ranges match. + * + * @param first1 An {@link Iterator} to the initial position of the first sequence. + * @param last1 An {@link Iterator} to the final position in a sequence. The range used is + * [first1, last1), including the element pointed by first1, but not the element + * pointed by last1. + * @param first2 An {@link Iterator} to the initial position of the second sequence. The comparison includes up to + * as many elements of this sequence as those in the range [first1, last1). + * + * @return true if all the elements in the range [first1, last1) compare equal to those + * of the range starting at first2, and false otherwise. + */ + function equal>(first1: InputIterator, last1: InputIterator, first2: Iterator): boolean; + /** + * Test whether the elements in two ranges are equal. + * + * Compares the elements in the range [first1, last1) with those in the range beginning at + * first2, and returns true if all of the elements in both ranges match. + * + * @param first1 An {@link Iterator} to the initial position of the first sequence. + * @param last1 An {@link Iterator} to the final position in a sequence. The range used is + * [first1, last1), including the element pointed by first1, but not the element + * pointed by last1. + * @param first2 An {@link Iterator} to the initial position of the second sequence. The comparison includes up to + * as many elements of this sequence as those in the range [first1, last1). + * @param pred Binary function that accepts two elements as argument (one of each of the two sequences, in the same + * order), and returns a value convertible to bool. The value returned indicates whether + * the elements are considered to match in the context of this function. + * + * @return true if all the elements in the range [first1, last1) compare equal to those + * of the range starting at first2, and false otherwise. + */ + function equal>(first1: InputIterator, last1: InputIterator, first2: Iterator, pred: (x: T, y: T) => boolean): boolean; + /** + * Lexicographical less-than comparison. + * + * Returns true if the range [first1, last1) compares lexicographically less + * than the range [first2, last2). + * + * A lexicographical comparison is the kind of comparison generally used to sort words alphabetically in + * dictionaries; It involves comparing sequentially the elements that have the same position in both ranges against + * each other until one element is not equivalent to the other. The result of comparing these first non-matching + * elements is the result of the lexicographical comparison. + * + * If both sequences compare equal until one of them ends, the shorter sequence is lexicographically less + * than the longer one. + * + * @param first1 An {@link Iterator} to the initial position of the first sequence. + * @param last1 An {@link Iterator} to the final position in a sequence. The range used is + * [first1, last1), including the element pointed by first1, but not the element + * pointed by last1. + * @param first2 An {@link Iterator} to the initial position of the second sequence. + * @param last2 An {@link Iterator} to the final position of the second sequence. The ranged used is + * [first2, last2). + * + * @return true if the first range compares lexicographically less than than the second. + * false otherwise (including when all the elements of both ranges are equivalent). + */ + function lexicographical_compare, Iterator2 extends Iterator>(first1: Iterator1, last1: Iterator1, first2: Iterator2, last2: Iterator2): boolean; + /** + * Lexicographical comparison. + * + * Returns true if the range [first1, last1) compares lexicographically + * relationship than the range [first2, last2). + * + * A lexicographical comparison is the kind of comparison generally used to sort words alphabetically in + * dictionaries; It involves comparing sequentially the elements that have the same position in both ranges against + * each other until one element is not equivalent to the other. The result of comparing these first non-matching + * elements is the result of the lexicographical comparison. + * + * If both sequences compare equal until one of them ends, the shorter sequence is lexicographically + * relationship than the longer one. + * + * @param first1 An {@link Iterator} to the initial position of the first sequence. + * @param last1 An {@link Iterator} to the final position in a sequence. The range used is + * [first1, last1), including the element pointed by first1, but not the element + * pointed by last1. + * @param first2 An {@link Iterator} to the initial position of the second sequence. + * @param last2 An {@link Iterator} to the final position of the second sequence. The ranged used is + * [first2, last2). + * @param compare Binary function that accepts two arguments of the types pointed by the iterators, and returns a + * value convertible to bool. The value returned indicates whether the first argument is + * considered to go before the second in the specific strict weak ordering it defines. + * + * @return true if the first range compares lexicographically relationship than than the + * second. false otherwise (including when all the elements of both ranges are equivalent). + */ + function lexicographical_compare, Iterator2 extends Iterator>(first1: Iterator1, last1: Iterator1, first2: Iterator2, last2: Iterator2, compare: (x: T, y: T) => boolean): boolean; + /** + * Find value in range. + * + * Returns an iterator to the first element in the range [first, last) that compares equal to + * val. If no such element is found, the function returns last. + * + * The function uses {@link equal_to equal_to} to compare the individual elements to val. + * + * @param first An {@link Iterator} to the initial position in a sequence. + * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), + * which contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + * @param val Value to search for in the range. + * + * @return An {@link Iterator} to the first element in the range that compares equal to val. If no elements + * match, the function returns last. + */ + function find>(first: InputIterator, last: InputIterator, val: T): InputIterator; + /** + * Find element in range. + * + * Returns an iterator to the first element in the range [first, last) for which pred returns + * true. If no such element is found, the function returns last. + * + * @param first An {@link Iterator} to the initial position in a sequence. + * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), + * which contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + * @param pred Unary function that accepts an element in the range as argument and returns a value convertible + * to bool. The value returned indicates whether the element is considered a match in + * the context of this function. The function shall not modify its argument. + * + * @return An {@link Iterator} to the first element in the range for which pred does not return + * false. If pred is false for all elements, the function returns + * last. + */ + function find_if>(first: InputIterator, last: InputIterator, pred: (val: T) => boolean): InputIterator; + /** + * Find element in range. + * + * Returns an iterator to the first element in the range [first, last) for which pred returns + * true. If no such element is found, the function returns last. + * + * @param first An {@link Iterator} to the initial position in a sequence. + * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), + * which contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + * @param pred Unary function that accepts an element in the range as argument and returns a value convertible + * to bool. The value returned indicates whether the element is considered a match in + * the context of this function. The function shall not modify its argument. + * + * @return An {@link Iterator} to the first element in the range for which pred returns false. + * If pred is true for all elements, the function returns last. + */ + function find_if_not>(first: InputIterator, last: InputIterator, pred: (val: T) => boolean): InputIterator; + /** + * Find last subsequence in range. + * + * Searches the range [first1, last1) for the last occurrence of the sequence defined by + * [first2, last2), and returns an {@link Iterator} to its first element, or last1,/i> if no + * occurrences are found. + * + * The elements in both ranges are compared sequentially using {@link equal_to}: A subsequence of + * [first1, last1) is considered a match only when this is true for all the elements of + * [first2, last2). + * + * This function returns the last of such occurrences. For an algorithm that returns the first instead, see + * {@link search}. + * + * @param first1 An {@link Iterator} to the initial position of the first sequence. + * @param last1 An {@link Iterator} to the final position in a sequence. The range used is + * [first1, last1), including the element pointed by first1, but not the element + * pointed by last1. + * @param first2 An {@link Iterator} to the initial position of the element values to be searched for. + * @param last2 An {@link Iterator} to the final position of the element values to be searched for. The range used + * is [first2, last2). + * @param pred Binary function that accepts two elements as arguments (one of each of the two sequences, in the + * same order), and returns a value convertible to bool. The value returned indicates + * whether the elements are considered to match in the context of this function. + * + * @return An {@link Iterator} to the first element of the last occurrence of [first2, last2) in + * [first1, last1). If the sequence is not found, the function returns ,i>last1. Otherwise + * [first2, last2) is an empty range, the function returns last1. + */ + function find_end, Iterator2 extends Iterator>(first1: Iterator1, last1: Iterator1, first2: Iterator2, last2: Iterator2): Iterator1; + /** + * Find last subsequence in range. + * + * Searches the range [first1, last1) for the last occurrence of the sequence defined by + * [first2, last2), and returns an {@link Iterator} to its first element, or last1,/i> if no + * occurrences are found. + * + * The elements in both ranges are compared sequentially using pred: A subsequence of + * [first1, last1) is considered a match only when this is true for all the elements of + * [first2, last2). + * + * This function returns the last of such occurrences. For an algorithm that returns the first instead, see + * {@link search}. + * + * @param first1 An {@link Iterator} to the initial position of the first sequence. + * @param last1 An {@link Iterator} to the final position in a sequence. The range used is + * [first1, last1), including the element pointed by first1, but not the element + * pointed by last1. + * @param first2 An {@link Iterator} to the initial position of the element values to be searched for. + * @param last2 An {@link Iterator} to the final position of the element values to be searched for. The range used + * is [first2, last2). + * @param pred Binary function that accepts two elements as arguments (one of each of the two sequences, in the + * same order), and returns a value convertible to bool. The value returned indicates + * whether the elements are considered to match in the context of this function. + * + * @return An {@link Iterator} to the first element of the last occurrence of [first2, last2) in + * [first1, last1). If the sequence is not found, the function returns ,i>last1. Otherwise + * [first2, last2) is an empty range, the function returns last1. + */ + function find_end, Iterator2 extends Iterator>(first1: Iterator1, last1: Iterator1, first2: Iterator2, last2: Iterator2, pred: (x: T, y: T) => boolean): Iterator1; + /** + * Find element from set in range. + * + * Returns an iterator to the first element in the range [first1, last1) that matches any of the + * elements in [first2, last2). If no such element is found, the function returns last1. + * + * The elements in [first1, last1) are sequentially compared to each of the values in + * [first2, last2) using {@link equal_to}, until a pair matches. + * + * @param first1 An {@link Iterator} to the initial position of the first sequence. + * @param last1 An {@link Iterator} to the final position in a sequence. The range used is + * [first1, last1), including the element pointed by first1, but not the element + * pointed by last1. + * @param first2 An {@link Iterator} to the initial position of the element values to be searched for. + * @param last2 An {@link Iterator} to the final position of the element values to be searched for. The range used + * is [first2, last2). + * + * @return An {@link Iterator} to the first element in [first1, last1) that is part of + * [first2, last2). If no matches are found, the function returns last1. + */ + function find_first_of, Iterator2 extends Iterator>(first1: Iterator1, last1: Iterator1, first2: Iterator2, last2: Iterator2): Iterator1; + /** + * Find element from set in range. + * + * Returns an iterator to the first element in the range [first1, last1) that matches any of the + * elements in [first2, last2). If no such element is found, the function returns last1. + * + * The elements in [first1, last1) are sequentially compared to each of the values in + * [first2, last2) using pred, until a pair matches. + * + * @param first1 An {@link Iterator} to the initial position of the first sequence. + * @param last1 An {@link Iterator} to the final position in a sequence. The range used is + * [first1, last1), including the element pointed by first1, but not the element + * pointed by last1. + * @param first2 An {@link Iterator} to the initial position of the element values to be searched for. + * @param last2 An {@link Iterator} to the final position of the element values to be searched for. The range used + * is [first2, last2). + * @param pred Binary function that accepts two elements as arguments (one of each of the two sequences, in the + * same order), and returns a value convertible to bool. The value returned indicates + * whether the elements are considered to match in the context of this function. + * + * @return An {@link Iterator} to the first element in [first1, last1) that is part of + * [first2, last2). If no matches are found, the function returns last1. + */ + function find_first_of, Iterator2 extends Iterator>(first1: Iterator1, last1: Iterator1, first2: Iterator2, last2: Iterator2, pred: (x: T, y: T) => boolean): Iterator1; + /** + * Find equal adjacent elements in range. + * + * Searches the range [first, last) for the first occurrence of two consecutive elements that match, + * and returns an {@link Iterator} to the first of these two elements, or last if no such pair is found. + * + * Two elements match if they compare equal using {@link equal_to}. + * + * @param first An {@link Iterator} to the initial position in a sequence. + * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), + * which contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + * + * @return An {@link Iterator} to the first element of the first pair of matching consecutive elements in the range + * [first, last). If no such pair is found, the function returns last. + */ + function adjacent_find>(first: InputIterator, last: InputIterator): InputIterator; + /** + * Find equal adjacent elements in range. + * + * Searches the range [first, last) for the first occurrence of two consecutive elements that match, + * and returns an {@link Iterator} to the first of these two elements, or last if no such pair is found. + * + * Two elements match if they compare equal using pred. + * + * @param first An {@link Iterator} to the initial position in a sequence. + * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), + * which contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + * @param pred Unary function that accepts an element in the range as argument and returns a value convertible to + * bool. The value returned indicates whether the element is considered a match in the + * context of this function. The function shall not modify its argument. + * + * @return An {@link Iterator} to the first element of the first pair of matching consecutive elements in the range + * [first, last). If no such pair is found, the function returns last. + */ + function adjacent_find>(first: InputIterator, last: InputIterator, pred: (x: T, y: T) => boolean): InputIterator; + /** + * Search range for subsequence. + * + * Searches the range [first1, last1) for the first occurrence of the sequence defined by + * [first2, last2), and returns an iterator to its first element, or last1 if no occurrences are + * found. + * + * The elements in both ranges are compared sequentially using {@link equal_to}: A subsequence of + * [first1, last1) is considered a match only when this is true for all the elements of + * [first2, last2). + * + * This function returns the first of such occurrences. For an algorithm that returns the last instead, see + * {@link find_end}. + * + * @param first1 {@link Iterator Forward iterator} to the initial position of the searched sequence. + * @param last1 {@link Iterator Forward iterator} to the final position of the searched sequence. The range used is + * [first1, last1), which contains all the elements between first1 and last1, + * including the element pointed by first1 but not the element pointed by last1. + * @param first2 {@link Iterator Forward iterator} to the initial position of the sequence to be searched for. + * @param last2 {@link Iterator Forward iterator} to the final position of the sequence to be searched for. The range + * used is [first2, last2). + * + * @return An iterator to the first element of the first occurrence of [first2, last2) in first1 + * and last1. If the sequence is not found, the function returns last1. Otherwise + * [first2, last2) is an empty range, the function returns first1. + */ + function search, ForwardIterator2 extends Iterator>(first1: ForwardIterator1, last1: ForwardIterator1, first2: ForwardIterator2, last2: ForwardIterator2): ForwardIterator1; + /** + * Search range for subsequence. + * + * Searches the range [first1, last1) for the first occurrence of the sequence defined by + * [first2, last2), and returns an iterator to its first element, or last1 if no occurrences are + * found. + * + * The elements in both ranges are compared sequentially using pred: A subsequence of + * [first1, last1) is considered a match only when this is true for all the elements of + * [first2, last2). + * + * This function returns the first of such occurrences. For an algorithm that returns the last instead, see + * {@link find_end}. + * + * @param first1 {@link Iterator Forward iterator} to the initial position of the searched sequence. + * @param last1 {@link Iterator Forward iterator} to the final position of the searched sequence. The range used is + * [first1, last1), which contains all the elements between first1 and last1, + * including the element pointed by first1 but not the element pointed by last1. + * @param first2 {@link Iterator Forward iterator} to the initial position of the sequence to be searched for. + * @param last2 {@link Iterator Forward iterator} to the final position of the sequence to be searched for. The range + * used is [first2, last2). + * @param pred Binary function that accepts two elements as arguments (one of each of the two sequences, in the same + * order), and returns a value convertible to bool. The returned value indicates whether the elements are + * considered to match in the context of this function. The function shall not modify any of its + * arguments. + * + * @return An iterator to the first element of the first occurrence of [first2, last2) in + * [first1, last1). If the sequence is not found, the function returns last1. Otherwise + * [first2, last2) is an empty range, the function returns first1. + */ + function search, ForwardIterator2 extends Iterator>(first1: ForwardIterator1, last1: ForwardIterator1, first2: ForwardIterator2, last2: ForwardIterator2, pred: (x: T, y: T) => boolean): ForwardIterator1; + /** + * Search range for elements. + * + * Searches the range [first, last) for a sequence of count elements, each comparing equal to + * val. + * + * The function returns an iterator to the first of such elements, or last if no such sequence is found. + * + * @param first {@link Iterator Forward iterator} to the initial position of the searched sequence. + * @param last {@link Iterator Forward iterator} to the final position of the searched sequence. The range used is + * [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * @param count Minimum number of successive elements to match. + * @param val Individual value to be compared, or to be used as argument for {@link equal_to}. + * + * @return An iterator to the first element of the sequence. If no such sequence is found, the function returns + * last. + */ + function search_n>(first: ForwardIterator, last: ForwardIterator, count: number, val: T): ForwardIterator; + /** + * Search range for elements. + * + * Searches the range [first, last) for a sequence of count elements, each comparing equal to + * val. + * + * The function returns an iterator to the first of such elements, or last if no such sequence is found. + * + * + * @param first {@link Iterator Forward iterator} to the initial position of the searched sequence. + * @param last {@link Iterator Forward iterator} to the final position of the searched sequence. The range used is + * [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * @param count Minimum number of successive elements to match. + * @param val Individual value to be compared, or to be used as argument for pred. + * @param pred Binary function that accepts two arguments (one element from the sequence as first, and val as + * second), and returns a value convertible to bool. The value returned indicates whether the + * element is considered a match in the context of this function. The function shall not modify any of its + * arguments. + * + * @return An {@link Iterator} to the first element of the sequence. If no such sequence is found, the function + * returns last. + */ + function search_n>(first: ForwardIterator, last: ForwardIterator, count: number, val: T, pred: (x: T, y: T) => boolean): ForwardIterator; + /** + * Return first position where two ranges differ. + * + * Compares the elements in the range [first1, last1) with those in the range beginning at + * first2, and returns the first element of both sequences that does not match. + * + * The function returns a {@link Pair} of {@link iterators Iterator} to the first element in each range that + * does not match. + * + * @param first1 An {@link Iterator} to the initial position of the first sequence. + * @param last1 An {@link Iterator} to the final position in a sequence. The range used is + * [first1, last1), including the element pointed by first1, but not the element + * pointed by last1. + * @param first2 An {@link Iterator} to the initial position of the second sequence. The comparison includes up to + * as many elements of this sequence as those in the range [first1, last1). + * + * @return A {@link Pair}, where its members {@link Pair.first first} and {@link Pair.second second} point to the + * first element in both sequences that did not compare equal to each other. If the elements compared in + * both sequences have all matched, the function returns a {@link Pair} with {@link Pair.first first} set + * to last1 and {@link Pair.second second} set to the element in that same relative position in the + * second sequence. If none matched, it returns {@link make_pair}(first1, first2). + */ + function mismatch, Iterator2 extends Iterator>(first1: Iterator1, last1: Iterator1, first2: Iterator2): Pair; + /** + * Return first position where two ranges differ. + * + * Compares the elements in the range [first1, last1) with those in the range beginning at + * first2, and returns the first element of both sequences that does not match. + * + * The function returns a {@link Pair} of {@link iterators Iterator} to the first element in each range that + * does not match. + * + * @param first1 An {@link Iterator} to the initial position of the first sequence. + * @param last1 An {@link Iterator} to the final position in a sequence. The range used is + * [first1, last1), including the element pointed by first1, but not the element + * pointed by last1. + * @param first2 An {@link Iterator} to the initial position of the second sequence. The comparison includes up to + * as many elements of this sequence as those in the range [first1, last1). + * @param pred Binary function that accepts two elements as argument (one of each of the two sequences, in the same + * order), and returns a value convertible to bool. The value returned indicates whether + * the elements are considered to match in the context of this function. + * + * @return A {@link Pair}, where its members {@link Pair.first first} and {@link Pair.second second} point to the + * first element in both sequences that did not compare equal to each other. If the elements compared in + * both sequences have all matched, the function returns a {@link Pair} with {@link Pair.first first} set + * to last1 and {@link Pair.second second} set to the element in that same relative position in the + * second sequence. If none matched, it returns {@link make_pair}(first1, first2). + */ + function mismatch, Iterator2 extends Iterator>(first1: Iterator1, last1: Iterator1, first2: Iterator2, compare: (x: T, y: T) => boolean): Pair; + /** + * Count appearances of value in range. + * + * Returns the number of elements in the range [first, last) that compare equal to val. + * + * The function uses {@link equal_to} to compare the individual elements to val. + * + * @param first An {@link Iterator} to the initial position in a sequence. + * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), + * which contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + * @param val Value to match. + * + * @return The number of elements in the range [first, last) that compare equal to val. + */ + function count>(first: InputIterator, last: InputIterator, val: T): number; + /** + * Return number of elements in range satisfying condition. + * + * Returns the number of elements in the range [first, last) for which pred is true. + * + * @param first An {@link Iterator} to the initial position in a sequence. + * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), + * which contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + * @param pred Unary function that accepts an element in the range as argument, and returns a value convertible + * to bool. The value returned indicates whether the element is counted by this function. + * The function shall not modify its argument. This can either be a function pointer or a function + * object. + */ + function count_if>(first: InputIterator, last: InputIterator, pred: (val: T) => boolean): number; +} +declare namespace std { + /** + * Copy range of elements. + * + * Copies the elements in the range [first, last) into the range beginning at result. + * + * The function returns an iterator to the end of the destination range (which points to the element following the + * last element copied). + * + * The ranges shall not overlap in such a way that result points to an element in the range + * [first, last). For such cases, see {@link copy_backward}. + * + * @param first {@link Iterator Input iterator} to the initial position in a sequence to be copied. + * @param last {@link Iterator Input iterator} to the initial position in a sequence to be copied. The range used is + * [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * @param result {@link Iterator Output iterator} to the initial position in the destination sequence. This shall not + * point to any element in the range [first, last). + * + * @return An iterator to the end of the destination range where elements have been copied. + */ + function copy, OutputIterator extends base.ILinearIterator>(first: InputIterator, last: InputIterator, result: OutputIterator): OutputIterator; + /** + * Copy elements. + * + * Copies the first n elements from the range beginning at first into the range beginning at + * result. + * + * The function returns an iterator to the end of the destination range (which points to one past the last element + * copied). + * + * If n is negative, the function does nothing. + * + * If the ranges overlap, some of the elements in the range pointed by result may have undefined but valid values. + * + * @param first {@link Iterator Input iterator} to the initial position in a sequence of at least n elements to + * be copied. InputIterator shall point to a type assignable to the elements pointed by + * OutputIterator. + * @param n Number of elements to copy. If this value is negative, the function does nothing. + * @param result {@link Iterator Output iterator} to the initial position in the destination sequence of at least + * n elements. This shall not point to any element in the range [first, last]. + * + * @return An iterator to the end of the destination range where elements have been copied. + */ + function copy_n, OutputIterator extends base.ILinearIterator>(first: InputIterator, n: number, result: OutputIterator): OutputIterator; + /** + * Copy certain elements of range. + * + * Copies the elements in the range [first, last) for which pred returns true to the + * range beginning at result. + * + * @param first {@link Iterator Input iterator} to the initial position in a sequence to be copied. + * @param last {@link Iterator Input iterator} to the initial position in a sequence to be copied. The range used is + * [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * @param result {@link Iterator Output iterator} to the initial position in the destination sequence. This shall not + * point to any element in the range [first, last). + * @param pred Unary function that accepts an element in the range as argument, and returns a value convertible to + * bool. The value returned indicates whether the element is to be copied (if + * true, it is copied). The function shall not modify any of its arguments. + * + * @return An iterator to the end of the destination range where elements have been copied. + */ + function copy_if, OutputIterator extends base.ILinearIterator>(first: InputIterator, last: InputIterator, result: OutputIterator, pred: (x: T) => boolean): OutputIterator; + /** + * Copy range of elements backward. + * + * Copies the elements in the range [first, last) starting from the end into the range terminating + * at result. + * + * The function returns an iterator to the first element in the destination range. + * + * The resulting range has the elements in the exact same order as [first, last). To reverse their + * order, see {@link reverse_copy}. + * + * The function begins by copying *(last-1) into *(result-1), and then follows backward + * by the elements preceding these, until first is reached (and including it). + * + * The ranges shall not overlap in such a way that result (which is the past-the-end element in the + * destination range) points to an element in the range (first,last]. For such cases, see {@link copy}. + * + * @param first {@link Iterator Bidirectional iterator} to the initial position in a sequence to be copied. + * @param last {@link Iterator Bidirectional iterator} to the initial position in a sequence to be copied. The range + * used is [first, last), which contains all the elements between first and + * last, including the element pointed by first but not the element pointed by last. + * @param result {@link Iterator Bidirectional iterator} to the initial position in the destination sequence. This + * shall not point to any element in the range [first, last). + * + * @return An iterator to the first element of the destination sequence where elements have been copied. + */ + function copy_backward, BidirectionalIterator2 extends base.ILinearIterator>(first: BidirectionalIterator1, last: BidirectionalIterator1, result: BidirectionalIterator2): BidirectionalIterator2; + /** + * Fill range with value. + * + * Assigns val to all the elements in the range [first, last). + * + * @param first {@link Iterator Forward iterator} to the initial position in a sequence of elements that support being + * assigned a value of type T. + * @param last {@link Iterator Forward iterator} to the final position in a sequence of elements that support being + * assigned a value of type T.. The range filled is [first, last), which contains + * all the elements between first and last, including the element pointed by first + * but not the element pointed by last. + * @param val Value to assign to the elements in the filled range. + */ + function fill>(first: ForwardIterator, last: ForwardIterator, val: T): void; + /** + * Fill sequence with value. + * + * Assigns val to the first n elements of the sequence pointed by first. + * + * @param first {@link Iterator Output iterator} to the initial position in a sequence of elements that support being + * assigned a value of type T. + * @param n Number of elements to fill. If negative, the function does nothing. + * @param val Value to be used to fill the range. + * + * @return An iterator pointing to the element that follows the last element filled. + */ + function fill_n>(first: OutputIterator, n: number, val: T): OutputIterator; + /** + * Transform range. + * + * Applies op to each of the elements in the range [first, last) and stores the value returned + * by each operation in the range that begins at result. + * + * @param first {@link Iterator Input iterator} to the initial position in a sequence to be transformed. + * @param last {@link Iterator Input iterator} to the initial position in a sequence to be transformed. The range + * used is [first, last), which contains all the elements between first and + * last, including the element pointed by first but not the element pointed by last. + * @param result {@link Iterator Output} iterator to the initial position of the range where the operation results are + * stored. The range includes as many elements as [first, last). + * @param op Unary function that accepts one element of the type pointed to by InputIterator as argument, and + * returns some result value convertible to the type pointed to by OutputIterator. + * + * @return An iterator pointing to the element that follows the last element written in the result sequence. + */ + function transform, OutputIterator extends base.ILinearIterator>(first: InputIterator, last: InputIterator, result: OutputIterator, op: (val: T) => T): OutputIterator; + /** + * Transform range. + * + * Calls binary_op using each of the elements in the range [first1, last1) as first argument, + * and the respective argument in the range that begins at first2 as second argument. The value returned by + * each call is stored in the range that begins at result. + * + * @param first1 {@link Iterator Input iterator} to the initial position of the first sequence. + * @param last1 {@link Iterator Input iterator} to the final position of the first sequence. The range used is + * [first1, last1), including the element pointed by first1, but not the element + * pointed by last1. + * @param first2 {@link Iterator Input iterator} to the initial position of the second range. The range includes as + * many elements as [first1, last1). + * @param result {@link Iterator Output} iterator to the initial position of the range where the operation results are + * stored. The range includes as many elements as [first1, last1). + * @param binary_op Binary function that accepts two elements as argument (one of each of the two sequences), and + * returns some result value convertible to the type pointed to by OutputIterator. + * + * @return An iterator pointing to the element that follows the last element written in the result sequence. + */ + function transform, InputIterator2 extends Iterator, OutputIterator extends base.ILinearIterator>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, result: OutputIterator, binary_op: (x: T, y: T) => T): OutputIterator; + /** + * Generate values for range with function. + * + * Assigns the value returned by successive calls to gen to the elements in the range [first, last). + * + * @param first {@link Iterator Forward iterator} to the initial position in a sequence. + * @param last {@link Iterator Forward iterator} to the final position in a sequence. The range affected is + * [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * @param gen Generator function that is called with no arguments and returns some value of a type convertible to + * those pointed by the iterators. + */ + function generate>(first: ForwardIterator, last: ForwardIterator, gen: () => T): void; + /** + * Generate values for sequence with function. + * + * Assigns the value returned by successive calls to gen to the first n elements of the sequence + * pointed by first. + * + * @param first {@link Iterator Output iterator} to the initial position in a sequence of at least n elements + * that support being assigned a value of the type returned by gen. + * @param n Number of values to generate. If negative, the function does nothing. + * @param gen Generator function that is called with no arguments and returns some value of a type convertible to + * those pointed by the iterators. + * + * @return An iterator pointing to the element that follows the last element whose value has been generated. + */ + function generate_n>(first: ForwardIterator, n: number, gen: () => T): ForwardIterator; + /** + * Remove consecutive duplicates in range. + * + * Removes all but the first element from every consecutive group of equivalent elements in the range + * [first, last). + * + * The function cannot alter the properties of the object containing the range of elements (i.e., it cannot + * alter the size of an array or a container): The removal is done by replacing the duplicate elements by the next + * element that is not a duplicate, and signaling the new size of the shortened range by returning an iterator to + * the element that should be considered its new past-the-last element. + * + * The relative order of the elements not removed is preserved, while the elements between the returned + * iterator and last are left in a valid but unspecified state. + * + * @param first An {@link Iterator} to the initial position in a sequence. + * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), + * which contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + * + * @return An iterator to the element that follows the last element not removed. The range between first and + * this iterator includes all the elements in the sequence that were not considered duplicates. + */ + function unique>(first: InputIterator, last: InputIterator): InputIterator; + /** + * Remove consecutive duplicates in range. + * + * Removes all but the first element from every consecutive group of equivalent elements in the range + * [first, last). + * + * The function cannot alter the properties of the object containing the range of elements (i.e., it cannot + * alter the size of an array or a container): The removal is done by replacing the duplicate elements by the next + * element that is not a duplicate, and signaling the new size of the shortened range by returning an iterator to + * the element that should be considered its new past-the-last element. + * + * The relative order of the elements not removed is preserved, while the elements between the returned + * iterator and last are left in a valid but unspecified state. + * + * @param first An {@link Iterator} to the initial position in a sequence. + * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), + * which contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + * @param pred Binary function that accepts two elements in the range as argument, and returns a value convertible + * to bool. The value returned indicates whether both arguments are considered equivalent + * (if true, they are equivalent and one of them is removed). The function shall not modify + * any of its arguments. + * + * @return An iterator to the element that follows the last element not removed. The range between first and + * this iterator includes all the elements in the sequence that were not considered duplicates. + */ + function unique>(first: InputIterator, last: InputIterator, pred: (left: t, right: t) => boolean): InputIterator; + /** + * Copy range removing duplicates. + * + * Copies the elements in the range [first, last) to the range beginning at result, except + * consecutive duplicates (elements that compare equal to the element preceding). + * + * Only the first element from every consecutive group of equivalent elements in the range + * [first, last) is copied. + * + * The comparison between elements is performed by applying {@lnk equal_to}. + * + * @param first {@link Iterator Forward iterator} to the initial position in a sequence. + * @param last {@link Iterator Forward iterator} to the final position in a sequence. The range used is + * [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * @param result Output iterator to the initial position of the range where the resulting range of values is stored. + * The pointed type shall support being assigned the value of an element in the range + * [first, last). + * + * @return An iterator pointing to the end of the copied range, which contains no consecutive duplicates. + */ + function unique_copy, OutputIterator extends base.ILinearIterator>(first: InputIterator, last: InputIterator, result: OutputIterator): OutputIterator; + /** + * Copy range removing duplicates. + * + * Copies the elements in the range [first, last) to the range beginning at result, except + * consecutive duplicates (elements that compare equal to the element preceding). + * + * Only the first element from every consecutive group of equivalent elements in the range + * [first, last) is copied. + * + * The comparison between elements is performed by applying pred. + * + * @param first {@link Iterator Forward iterator} to the initial position in a sequence. + * @param last {@link Iterator Forward iterator} to the final position in a sequence. The range used is + * [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * @param result Output iterator to the initial position of the range where the resulting range of values is stored. + * The pointed type shall support being assigned the value of an element in the range + * [first, last). + * @param pred Binary function that accepts two elements in the range as argument, and returns a value convertible to + * bool. The value returned indicates whether both arguments are considered equivalent (if + * true, they are equivalent and one of them is removed). The function shall not modify any + * of its arguments. + * + * @return An iterator pointing to the end of the copied range, which contains no consecutive duplicates. + */ + function unique_copy, OutputIterator extends base.ILinearIterator>(first: InputIterator, last: InputIterator, result: OutputIterator, pred: (x: T, y: T) => boolean): OutputIterator; + /** + * Remove value from range. + * + * Transforms the range [first, last) into a range with all the elements that compare equal to + * val removed, and returns an iterator to the new last of that range. + * + * The function cannot alter the properties of the object containing the range of elements (i.e., it cannot alter + * the size of an array or a container): The removal is done by replacing the elements that compare equal to + * val by the next element that does not, and signaling the new size of the shortened range by returning an + * iterator to the element that should be considered its new past-the-last element. + * + * The relative order of the elements not removed is preserved, while the elements between the returned iterator + * and last are left in a valid but unspecified state. + * + * @param first An {@link Iterator} to the initial position in a sequence. + * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), + * which contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + * @param val Value to be removed. + */ + function remove>(first: InputIterator, last: InputIterator, val: T): InputIterator; + /** + * Remove elements from range. + * + * Transforms the range [first, last) into a range with all the elements for which pred returns + * true removed, and returns an iterator to the new last of that range. + * + * The function cannot alter the properties of the object containing the range of elements (i.e., it cannot + * alter the size of an array or a container): The removal is done by replacing the elements for which pred returns + * true by the next element for which it does not, and signaling the new size of the shortened range + * by returning an iterator to the element that should be considered its new past-the-last element. + * + * The relative order of the elements not removed is preserved, while the elements between the returned + * iterator and last are left in a valid but unspecified state. + * + * @param first An {@link Iterator} to the initial position in a sequence. + * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), + * which contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + * @param pred Unary function that accepts an element in the range as argument, and returns a value convertible to + * bool. The value returned indicates whether the element is to be removed (if + * true, it is removed). The function shall not modify its argument. + */ + function remove_if>(first: InputIterator, last: InputIterator, pred: (left: T) => boolean): InputIterator; + /** + * Copy range removing value. + * + * Copies the elements in the range [first, last) to the range beginning at result, except + * those elements that compare equal to val. + * + * The resulting range is shorter than [first, last) by as many elements as matches in the sequence, + * which are "removed". + * + * The function uses {@link equal_to} to compare the individual elements to val. + * + * @param first {@link Iterator InputIterator} to the initial position in a sequence. + * @param last {@link Iterator InputIterator} to the final position in a sequence. The range used is + * [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting sequence is + * stored. The pointed type shall support being assigned the value of an element in the range + * [first, last). + * @param val Value to be removed. + * + * @return An iterator pointing to the end of the copied range, which includes all the elements in + * [first, last) except those that compare equal to val. + */ + function remove_copy, OutputIterator extends base.ILinearIterator>(first: InputIterator, last: InputIterator, result: OutputIterator, val: T): OutputIterator; + /** + * Copy range removing values. + * + * Copies the elements in the range [first, last) to the range beginning at result, except + * those elements for which pred returns true. + * + * The resulting range is shorter than [first, last) by as many elements as matches, which are + * "removed". + * + * @param first {@link Iterator InputIterator} to the initial position in a sequence. + * @param last {@link Iterator InputIterator} to the final position in a sequence. The range used is + * [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting sequence is + * stored. The pointed type shall support being assigned the value of an element in the range + * [first, last). + * @param pred Unary function that accepts an element in the range as argument, and returns a value convertible to + * bool. The value returned indicates whether the element is to be removed from the copy (if + * true, it is not copied). The function shall not modify its argument. + * + * @return An iterator pointing to the end of the copied range, which includes all the elements in + * [first, last) except those for which pred returns true. + */ + function remove_copy_if, OutputIterator extends base.ILinearIterator>(first: InputIterator, last: InputIterator, result: OutputIterator, pred: (val: T) => boolean): OutputIterator; + /** + * Replace value in range. + * + * Assigns new_val to all the elements in the range [first, last) that compare equal to + * old_val. + * + * The function uses {@link equal_to} to compare the individual elements to old_val. + * + * @param first An {@link Iterator} to the initial position in a sequence. + * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), + * which contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + * @param old_val Value to be replaced. + * @param new_val Replacement value. + */ + function replace>(first: InputIterator, last: InputIterator, old_val: T, new_val: T): void; + /** + * Replace value in range. + * + * Assigns new_val to all the elements in the range [first, last) for which pred returns + * true. + * + * @param first An {@link Iterator} to the initial position in a sequence. + * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), + * which contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + * @param pred Unary function that accepts an element in the range as argument, and returns a value convertible to + * bool. The value returned indicates whether the element is to be replaced (if + * true, it is replaced). The function shall not modify its argument. + * @param new_val Value to assign to replaced elements. + */ + function replace_if>(first: InputIterator, last: InputIterator, pred: (val: T) => boolean, new_val: T): void; + /** + * Copy range replacing value. + * + * Copies the elements in the range [first, last) to the range beginning at result, replacing + * the appearances of old_value by new_value. + * + * The function uses {@link equal_to} to compare the individual elements to old_value. + * + * The ranges shall not overlap in such a way that result points to an element in the range + * [first, last). + * + * @param first {@link Iterator InputIterator} to the initial position in a sequence. + * @param last {@link Iterator InputIterator} to the final position in a sequence. The range used is + * [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting sequence is + * stored. The pointed type shall support being assigned the value of an element in the range + * [first, last). + * @param old_val Value to be replaced. + * @param new_val Replacement value. + * + * @return An iterator pointing to the element that follows the last element written in the result sequence. + */ + function replace_copy, OutputIterator extends base.ILinearIterator>(first: InputIterator, last: InputIterator, result: OutputIterator, old_val: T, new_val: T): OutputIterator; + /** + * Copy range replacing value. + * + * Copies the elements in the range [first, last) to the range beginning at result, replacing + * those for which pred returns true by new_value. + * + * @param first {@link Iterator InputIterator} to the initial position in a sequence. + * @param last {@link Iterator InputIterator} to the final position in a sequence. The range used is + * [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting sequence is + * stored. The pointed type shall support being assigned the value of an element in the range + * [first, last). + * @param pred Unary function that accepts an element in the range as argument, and returns a value convertible to + * bool. The value returned indicates whether the element is to be removed from the copy (if + * true, it is not copied). The function shall not modify its argument. + * @param new_val Value to assign to replaced values. + * + * @return An iterator pointing to the element that follows the last element written in the result sequence. + */ + function replace_copy_if, OutputIterator extends base.ILinearIterator>(first: InputIterator, last: InputIterator, result: OutputIterator, pred: (val: T) => boolean, new_val: T): OutputIterator; + /** + * Exchange values of objects pointed to by two iterators. + * + * Swaps the elements pointed to by x and y. + * + * The function calls {@link Iterator.swap} to exchange the elements. + * + * @param x {@link Iterator Forward iterator} to the objects to swap. + * @param y {@link Iterator Forward iterator} to the objects to swap. + */ + function iter_swap(x: Iterator, y: Iterator): void; + /** + * Exchange values of two ranges. + * + * Exchanges the values of each of the elements in the range [first1, last1) with those of their + * respective elements in the range beginning at first2. + * + * The function calls {@link Iterator.swap} to exchange the elements. + * + * @param first1 {@link Iterator Forward iterator} to the initial position of the first sequence. + * @param last1 {@link Iterator Forward iterator} to the final position of the first sequence. The range used is + * [first1, last1), including the element pointed by first1, but not the element + * pointed by last1. + * @param first2 {@link Iterator Forward iterator} to the initial position of the second range. The range includes as + * many elements as [first1, last1). The two ranges shall not overlap. + * + * @return An iterator to the last element swapped in the second sequence. + */ + function swap_ranges, ForwardIterator2 extends Iterator>(first1: ForwardIterator1, last1: ForwardIterator1, first2: ForwardIterator2): ForwardIterator2; + /** + * Reverse range. + * + * Reverses the order of the elements in the range [first, last). + * + * The function calls {@link iter_swap} to swap the elements to their new locations. + * + * @param first An {@link Iterator} to the initial position in a sequence. + * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), + * which contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + */ + function reverse>(first: InputIterator, last: InputIterator): void; + /** + * Copy range reversed. + * + * Copies the elements in the range [first, last) to the range beginning at result, but in + * reverse order. + * + * @param first {@link Iterator Bidirectional iterator} to the initial position in a sequence to be copied. + * @param last {@link Iterator Bidirectional iterator} to the initial position in a sequence to be copied. The range + * used is [first, last), which contains all the elements between first and + * last, including the element pointed by first but not the element pointed by last. + * @param result {@link Iterator Output iterator} to the initial position of the range where the reserved range is + * stored. The pointed type shall support being assigned the value of an element in the range + * [first, last). + * + * @return An output iterator pointing to the end of the copied range, which contains the same elements in reverse + * order. + */ + function reverse_copy, OutputIterator extends base.ILinearIterator>(first: BidirectionalIterator, last: BidirectionalIterator, result: OutputIterator): OutputIterator; + /** + * Rotate left the elements in range. + * + * Rotates the order of the elements in the range [first, last), in such a way that the element + * pointed by middle becomes the new first element. + * + * @param first An {@link Iterator} to the initial position in a sequence. + * @param middle An {@link Iterator} pointing to the element within the range [first, last) that is + * moved to the first position in the range. + * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), + * which contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + * + * @return An iterator pointing to the element that now contains the value previously pointed by first. + */ + function rotate>(first: InputIterator, middle: InputIterator, last: InputIterator): InputIterator; + /** + * Copy range rotated left. + * + * Copies the elements in the range [first, last) to the range beginning at result, but + * rotating the order of the elements in such a way that the element pointed by middle becomes the first + * element in the resulting range. + * + * @param first {@link Iterator Forward iterator} to the initial position of the range to be copy-rotated. + * @param middle Forward iterator pointing to the element within the range [first, last) that is copied as the first element in the resulting range. + * @param last {@link Iterator Forward iterator} to the final positions of the range to be copy-rotated. The range + * used is [first, last), which contains all the elements between first and + * last, including the element pointed by first but not the element pointed by last. + * Notice that in this function, these are not consecutive parameters, but the first and third ones. + * @param result {@link Iterator Output iterator} to the initial position of the range where the reserved range is + * stored. The pointed type shall support being assigned the value of an element in the range + * [first, last). + * + * @return An output iterator pointing to the end of the copied range. + */ + function rotate_copy, OutputIterator extends base.ILinearIterator>(first: ForwardIterator, middle: ForwardIterator, last: ForwardIterator, result: OutputIterator): OutputIterator; + /** + * Randomly rearrange elements in range. + * + * Rearranges the elements in the range [first, last) randomly. + * + * The function swaps the value of each element with that of some other randomly picked element. When provided, + * the function gen determines which element is picked in every case. Otherwise, the function uses some unspecified + * source of randomness. + * + * To specify a uniform random generator, see {@link shuffle}. + * + * @param first An {@link Iterator} to the initial position in a sequence. + * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), + * which contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + */ + function random_shuffle>(first: RandomAccessIterator, last: RandomAccessIterator): void; + /** + * Randomly rearrange elements in range using generator. + * + * Rearranges the elements in the range [first, last) randomly, using g as uniform random + * number generator. + * + * The function swaps the value of each element with that of some other randomly picked element. The function + * determines the element picked by calling g(). + * + * To shuffle the elements of the range without such a generator, see {@link random_shuffle} instead. + * + *
Note
+ * Using random generator engine is not implemented yet. + * + * @param first An {@link Iterator} to the initial position in a sequence. + * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), + * which contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + */ + function shuffle>(first: RandomAccessIterator, last: RandomAccessIterator): void; +} +declare namespace std { + /** + * Sort elements in range. + * + * Sorts the elements in the range [first, last) into ascending order. The elements are compared + * using {@link less}. + * + * @param first {@link IArrayIterator Random-access iterator} to the initial position of the sequence to be sorted. + * @param last {@link IArrayIterator Random-access iterator} to the final position of the sequence to be sorted. + * The range used is [first, last), which contains all the elements between first + * and last, including the element pointed by first but not the element pointed by + * last. {@link IArrayIterator RandomAccessIterator} shall point to a type for which + * {@link Iterator.swap swap} is properly defined. + */ + function sort>(first: RandomAccessIterator, last: RandomAccessIterator): void; + /** + * Sort elements in range. + * + * Sorts the elements in the range [first, last) into specific order. The elements are compared + * using compare. + * + * @param first {@link IArrayIterator Random-access iterator} to the initial position of the sequence to be sorted. + * @param last {@link IArrayIterator Random-access iterator} to the final position of the sequence to be sorted. + * The range used is [first, last), which contains all the elements between first + * and last, including the element pointed by first but not the element pointed by + * last. {@link IArrayIterator RandomAccessIterator} shall point to a type for which + * {@link Iterator.swap swap} is properly defined. + * @param compare Binary function that accepts two elements in the range as arguments, and returns a value + * convertible to boolean. The value returned indicates whether the element passed as first + * argument is considered to go before the second in the specific strict weak ordering it defines. The + * function shall not modify any of its arguments. This can either be a function pointer or a function + * object. + */ + function sort>(first: RandomAccessIterator, last: RandomAccessIterator, compare: (left: T, right: T) => boolean): void; + /** + * Partially sort elements in range. + * + * Rearranges the elements in the range [first, last), in such a way that the elements before + * middle are the smallest elements in the entire range and are sorted in ascending order, while the remaining + * elements are left without any specific order. + * + * The elements are compared using {@link less}. + * + * @param last {@link IArrayIterator Random-access iterator} to the first position of the sequence to be sorted. + * @param middle {@link IArrayIterator Random-access iterator} pointing to the element within the range [first, last) that is used as the upper boundary of the elements that are fully sorted. + * @param last {@link IArrayIterator Random-access iterator} to the final position of the sequence to be sorted. + * The range used is [first, last), which contains all the elements between first + * and last, including the element pointed by first but not the element pointed by + * last. + */ + function partial_sort>(first: RandomAccessIterator, middle: RandomAccessIterator, last: RandomAccessIterator): void; + /** + * Partially sort elements in range. + * + * Rearranges the elements in the range [first, last), in such a way that the elements before + * middle are the smallest elements in the entire range and are sorted in ascending order, while the remaining + * elements are left without any specific order. + * + * The elements are compared using comp. + * + * @param last {@link IArrayIterator Random-access iterator} to the first position of the sequence to be sorted. + * @param middle {@link IArrayIterator Random-access iterator} pointing to the element within the range [first, last) that is used as the upper boundary of the elements that are fully sorted. + * @param last {@link IArrayIterator Random-access iterator} to the final position of the sequence to be sorted. + * The range used is [first, last), which contains all the elements between first + * and last, including the element pointed by first but not the element pointed by + * last. + * @param compare Binary function that accepts two elements in the range as arguments, and returns a value + * convertible to boolean. The value returned indicates whether the element passed as + * first argument is considered to go before the second in the specific strict weak ordering it + * defines. The function shall not modify any of its arguments. + */ + function partial_sort>(first: RandomAccessIterator, middle: RandomAccessIterator, last: RandomAccessIterator, compare: (x: T, y: T) => boolean): void; + /** + * Copy and partially sort range. + * + * Copies the smallest elements in the range [first, last) to + * [result_first, result_last), sorting the elements copied. The number of elements copied is the same + * as the {@link distance} between result_first and result_last (unless this is more than the amount of + * elements in [first, last)). + * + * The range [first, last) is not modified. + * + * The elements are compared using {@link less}. + * + * @param first {@link Iterator Input iterator} to the initial position of the sequence to copy from. + * @param last {@link Iterator Input iterator} to the final position of the sequence to copy from. The range used is + * [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * InputIterator shall point to a type assignable to the elements pointed by + * RandomAccessIterator. + * @param result_first {@link Iterator Random-access iterator} to the initial position of the destination sequence. + * @param result_last {@link Iterator Random-access iterator} to the final position of the destination sequence. + * The range used is [result_first, result_last). + * @param compare Binary function that accepts two elements in the result range as arguments, and returns a value + * convertible to bool. The value returned indicates whether the element passed as first + * argument is considered to go before the second in the specific strict weak ordering it + * defines. The function shall not modify any of its arguments. + * + * @return An iterator pointing to the element that follows the last element written in the result sequence. + */ + function partial_sort_copy, RandomAccessIterator extends Iterator>(first: InputIterator, last: InputIterator, result_first: RandomAccessIterator, result_last: RandomAccessIterator): RandomAccessIterator; + /** + * Copy and partially sort range. + * + * Copies the smallest (or largest) elements in the range [first, last) to + * [result_first, result_last), sorting the elements copied. The number of elements copied is the same + * as the {@link distance} between result_first and result_last (unless this is more than the amount of + * elements in [first, last)). + * + * The range [first, last) is not modified. + * + * The elements are compared using compare. + * + * @param first {@link Iterator Input iterator} to the initial position of the sequence to copy from. + * @param last {@link Iterator Input iterator} to the final position of the sequence to copy from. The range used is + * [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * InputIterator shall point to a type assignable to the elements pointed by + * RandomAccessIterator. + * @param result_first {@link Iterator Random-access iterator} to the initial position of the destination sequence. + * @param result_last {@link Iterator Random-access iterator} to the final position of the destination sequence. + * The range used is [result_first, result_last). + * @param compare Binary function that accepts two elements in the result range as arguments, and returns a value + * convertible to bool. The value returned indicates whether the element passed as first + * argument is considered to go before the second in the specific strict weak ordering it + * defines. The function shall not modify any of its arguments. + * + * @return An iterator pointing to the element that follows the last element written in the result sequence. + */ + function partial_sort_copy, RandomAccessIterator extends Iterator>(first: InputIterator, last: InputIterator, result_first: RandomAccessIterator, result_last: RandomAccessIterator, compare: (x: T, y: T) => boolean): RandomAccessIterator; + /** + * Check whether range is sorted. + * + * Returns true if the range [first, last) is sorted into ascending order. + * + * The elements are compared using {@link less}. + * + * @param first {@link Iterator Forward iterator} to the initial position of the sequence. + * @param last {@link Iterator Forward iterator} to the final position of the sequence. The range checked is + * [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * + * @return true if the range [first, last) is sorted into ascending order, + * false otherwise. If the range [first, last) contains less than two elements, + * the function always returns true. + */ + function is_sorted>(first: ForwardIterator, last: ForwardIterator): boolean; + /** + * Check whether range is sorted. + * + * Returns true if the range [first, last) is sorted into ascending order. + * + * The elements are compared using compare. + * + * @param first {@link Iterator Forward iterator} to the initial position of the sequence. + * @param last {@link Iterator Forward iterator} to the final position of the sequence. The range checked is + * [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * @param compare Binary function that accepts two elements in the range as arguments, and returns a value convertible + * to bool. The value returned indicates whether the element passed as first argument is + * considered to go before the second in the specific strict weak ordering it defines. The function + * shall not modify any of its arguments. + * + * @return true if the range [first, last) is sorted into ascending order, + * false otherwise. If the range [first, last) contains less than two elements, + * the function always returns true. + */ + function is_sorted>(first: ForwardIterator, last: ForwardIterator, compare: (x: T, y: T) => boolean): boolean; + /** + * Find first unsorted element in range. + * + * Returns an iterator to the first element in the range [first, last) which does not follow an + * ascending order. + * + * The range between first and the iterator returned {@link is_sorted is sorted}. + * + * If the entire range is sorted, the function returns last. + * + * The elements are compared using {@link equal_to}. + * + * @param first {@link Iterator Forward iterator} to the initial position of the sequence. + * @param last {@link Iterator Forward iterator} to the final position of the sequence. The range checked is + * [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * @param compare Binary function that accepts two elements in the range as arguments, and returns a value convertible + * to bool. The value returned indicates whether the element passed as first argument is + * considered to go before the second in the specific strict weak ordering it defines. The function + * shall not modify any of its arguments. + * + * @return An iterator to the first element in the range which does not follow an ascending order, or last if + * all elements are sorted or if the range contains less than two elements. + */ + function is_sorted_until>(first: ForwardIterator, last: ForwardIterator): ForwardIterator; + /** + * Find first unsorted element in range. + * + * Returns an iterator to the first element in the range [first, last) which does not follow an + * ascending order. + * + * The range between first and the iterator returned {@link is_sorted is sorted}. + * + * If the entire range is sorted, the function returns last. + * + * The elements are compared using compare. + * + * @param first {@link Iterator Forward iterator} to the initial position of the sequence. + * @param last {@link Iterator Forward iterator} to the final position of the sequence. The range checked is + * [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * @param compare Binary function that accepts two elements in the range as arguments, and returns a value convertible + * to bool. The value returned indicates whether the element passed as first argument is + * considered to go before the second in the specific strict weak ordering it defines. The function + * shall not modify any of its arguments. + * + * @return An iterator to the first element in the range which does not follow an ascending order, or last if + * all elements are sorted or if the range contains less than two elements. + */ + function is_sorted_until>(first: ForwardIterator, last: ForwardIterator, compare: (x: T, y: T) => boolean): ForwardIterator; +} +declare namespace std { + /** + * Make heap from range. + * + * Rearranges the elements in the range [first, last) in such a way that they form a heap. + * + * A heap is a way to organize the elements of a range that allows for fast retrieval of the element with the + * highest value at any moment (with {@link pop_heap}), even repeatedly, while allowing for fast insertion of new + * elements (with {@link push_heap}). + * + * The element with the highest value is always pointed by first. The order of the other elements depends on the + * particular implementation, but it is consistent throughout all heap-related functions of this header. + * + * The elements are compared using {@link less}: The element with the highest value is an element for which this + * would return false when compared to every other element in the range. + * + * The standard container adaptor {@link PriorityQueue} calls {@link make_heap}, {@link push_heap} and + * {@link pop_heap} automatically to maintain heap properties for a container. + * + * @param first {@link IArrayIterator Random-access iterator} to the initial position of the sequence to be + * transformed into a heap. + * @param last {@link IArrayIterator Random-access iterator} to the final position of the sequence to be transformed + * into a heap. The range used is [first, last), which contains all the elements between + * first and last, including the element pointed by first but not the element pointed + * by last. {@link IArrayIterator RandomAccessIterator} shall point to a type for which + * {@link Iterator.swap swap} is properly defined. + */ + function make_heap>(first: RandomAccessIterator, last: RandomAccessIterator): void; + /** + * Make heap from range. + * + * Rearranges the elements in the range [first, last) in such a way that they form a heap. + * + * A heap is a way to organize the elements of a range that allows for fast retrieval of the element with the + * highest value at any moment (with {@link pop_heap}), even repeatedly, while allowing for fast insertion of new + * elements (with {@link push_heap}). + * + * The element with the highest value is always pointed by first. The order of the other elements depends on the + * particular implementation, but it is consistent throughout all heap-related functions of this header. + * + * The elements are compared using compare: The element with the highest value is an element for which this + * would return false when compared to every other element in the range. + * + * The standard container adaptor {@link PriorityQueue} calls {@link make_heap}, {@link push_heap} and + * {@link pop_heap} automatically to maintain heap properties for a container. + * + * @param first {@link IArrayIterator Random-access iterator} to the initial position of the sequence to be + * transformed into a heap. + * @param last {@link IArrayIterator Random-access iterator} to the final position of the sequence to be transformed + * into a heap. The range used is [first, last), which contains all the elements between + * first and last, including the element pointed by first but not the element pointed + * by last. {@link IArrayIterator RandomAccessIterator} shall point to a type for which + * {@link Iterator.swap swap} is properly defined. + * @param compare Binary function that accepts two elements in the range as arguments, and returns a value + * convertible to boolean. The value returned indicates whether the element passed as + * first argument is considered to go before the second in the specific strict weak ordering it defines. + * The function shall not modify any of its arguments. This can either be a function pointer or a + * function object. + */ + function make_heap>(first: RandomAccessIterator, last: RandomAccessIterator, compare: (x: T, y: T) => boolean): void; + /** + * Push element into heap range. + * + * Given a heap in the range [first, last - 1), this function extends the range considered a heap to + * [first, last) by placing the value in (last - 1) into its corresponding location within it. + * + * + * A range can be organized into a heap by calling {@link make_heap}. After that, its heap properties are + * preserved if elements are added and removed from it using {@link push_heap} and {@link pop_heap}, respectively. + * + * + * @param first {@link IArrayIterator Random-access iterator} to the initial position of the new heap range, including + * the pushed element. + * @param last {@link IArrayIterator Random-access iterator} to the final position of the new heap range, including + * the pushed element. The range used is [first, last), which contains all the elements + * between first and last, including the element pointed by first but not the element + * pointed by last. {@link IArrayIterator RandomAccessIterator} shall point to a type for which + * {@link Iterator.swap swap} is properly defined. + */ + function push_heap>(first: RandomAccessIterator, last: RandomAccessIterator): void; + /** + * Push element into heap range. + * + * Given a heap in the range [first, last - 1), this function extends the range considered a heap to + * [first, last) by placing the value in (last - 1) into its corresponding location within it. + * + * A range can be organized into a heap by calling {@link make_heap}. After that, its heap properties are + * preserved if elements are added and removed from it using {@link push_heap} and {@link pop_heap}, respectively. + * + * + * @param first {@link IArrayIterator Random-access iterator} to the initial position of the new heap range, including + * the pushed element. + * @param last {@link IArrayIterator Random-access iterator} to the final position of the new heap range, including + * the pushed element. The range used is [first, last), which contains all the elements + * between first and last, including the element pointed by first but not the element + * pointed by last. {@link IArrayIterator RandomAccessIterator} shall point to a type for which + * {@link Iterator.swap swap} is properly defined. + * @param compare Binary function that accepts two elements in the range as arguments, and returns a value + * convertible to boolean. The value returned indicates whether the element passed as + * first argument is considered to go before the second in the specific strict weak ordering it defines. + * The function shall not modify any of its arguments. This can either be a function pointer or a + * function object. + */ + function push_heap>(first: RandomAccessIterator, last: RandomAccessIterator, compare: (x: T, y: T) => boolean): void; + /** + * Pop element from heap range. + * + * Rearranges the elements in the heap range [first, last) in such a way that the part considered a + * heap is shortened by one: The element with the highest value is moved to (last - 1). + * + * While the element with the highest value is moved from first to (last - 1) (which now is out of the + * heap), the other elements are reorganized in such a way that the range [first, last - 1) preserves + * the properties of a heap. + * + * A range can be organized into a heap by calling {@link make_heap}. After that, its heap properties are + * preserved if elements are added and removed from it using {@link push_heap} and {@link pop_heap}, respectively. + * + * @param first {@link IArrayIterator Random-access iterator} to the initial position of the heap to be shrank by one. + * @param last {@link IArrayIterator Random-access iterator} to the final position of the heap to be shrank by one. + * The range used is [first, last), which contains all the elements between first and + * last, including the element pointed by first but not the element pointed by last. + * {@link IArrayIterator RandomAccessIterator} shall point to a type for which {@link Iterator.swap swap} + * is properly defined. + */ + function pop_heap>(first: RandomAccessIterator, last: RandomAccessIterator): void; + /** + * Pop element from heap range. + * + * Rearranges the elements in the heap range [first, last) in such a way that the part considered a + * heap is shortened by one: The element with the highest value is moved to (last - 1). + * + * While the element with the highest value is moved from first to (last - 1) (which now is out of the + * heap), the other elements are reorganized in such a way that the range [first, last - 1) preserves + * the properties of a heap. + * + * A range can be organized into a heap by calling {@link make_heap}. After that, its heap properties are + * preserved if elements are added and removed from it using {@link push_heap} and {@link pop_heap}, respectively. + * + * @param first {@link IArrayIterator Random-access iterator} to the initial position of the heap to be shrank by one. + * @param last {@link IArrayIterator Random-access iterator} to the final position of the heap to be shrank by one. + * The range used is [first, last), which contains all the elements between first and + * last, including the element pointed by first but not the element pointed by last. + * {@link IArrayIterator RandomAccessIterator} shall point to a type for which {@link Iterator.swap swap} + * is properly defined. + * @param compare Binary function that accepts two elements in the range as arguments, and returns a value + * convertible to boolean. The value returned indicates whether the element passed as + * first argument is considered to go before the second in the specific strict weak ordering it defines. + * The function shall not modify any of its arguments. This can either be a function pointer or a + * function object. + */ + function pop_heap>(first: RandomAccessIterator, last: RandomAccessIterator, compare: (x: T, y: T) => boolean): void; + /** + * Test if range is heap. + * + * Returns true if the range [first, last) forms a heap, as if constructed with {@link make_heap}. + * + * The elements are compared using {@link less}. + * + * @param first {@link IArrayIterator Random-access iterator} to the initial position of the sequence. + * @param last {@link IArrayIterator Random-access iterator} to the final position of the sequence. The range used is + * [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * {@link IArrayIterator RandomAccessIterator} shall point to a type for which {@link Iterator.swap swap} + * is properly defined. + * + * @return true if the range [first, last) is a heap (as if constructed with + * {@link make_heap}), false otherwise. If the range [first, last) contains less + * than two elements, the function always returns true. + */ + function is_heap>(first: RandomAccessIterator, last: RandomAccessIterator): boolean; + /** + * Test if range is heap. + * + * Returns true if the range [first, last) forms a heap, as if constructed with {@link make_heap}. + * + * The elements are compared using compare. + * + * @param first {@link IArrayIterator Random-access iterator} to the initial position of the sequence. + * @param last {@link IArrayIterator Random-access iterator} to the final position of the sequence. The range used is + * [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * {@link IArrayIterator RandomAccessIterator} shall point to a type for which {@link Iterator.swap swap} + * is properly defined. + * @param compare Binary function that accepts two elements in the range as arguments, and returns a value + * convertible to boolean. The value returned indicates whether the element passed as + * first argument is considered to go before the second in the specific strict weak ordering it defines. + * The function shall not modify any of its arguments. This can either be a function pointer or a + * function object. + * + * @return true if the range [first, last) is a heap (as if constructed with + * {@link make_heap}), false otherwise. If the range [first, last) contains less + * than two elements, the function always returns true. + */ + function is_heap>(first: RandomAccessIterator, last: RandomAccessIterator, compare: (x: T, y: T) => boolean): boolean; + /** + * Find first element not in heap order. + * + * Returns an iterator to the first element in the range [first, last) which is not in a valid + * position if the range is considered a heap (as if constructed with {@link make_heap}). + * + * The range between first and the iterator returned is a heap. + * + * If the entire range is a valid heap, the function returns last. + * + * The elements are compared using {@link less}. + * + * @param first {@link IArrayIterator Random-access iterator} to the initial position of the sequence. + * @param last {@link IArrayIterator Random-access iterator} to the final position of the sequence. The range used is + * [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * {@link IArrayIterator RandomAccessIterator} shall point to a type for which {@link Iterator.swap swap} + * is properly defined. + */ + function is_heap_until>(first: RandomAccessIterator, last: RandomAccessIterator): RandomAccessIterator; + /** + * Find first element not in heap order. + * + * Returns an iterator to the first element in the range [first, last) which is not in a valid + * position if the range is considered a heap (as if constructed with {@link make_heap}). + * + * The range between first and the iterator returned is a heap. + * + * If the entire range is a valid heap, the function returns last. + * + * The elements are compared using {@link less}. + * + * @param first {@link IArrayIterator Random-access iterator} to the initial position of the sequence. + * @param last {@link IArrayIterator Random-access iterator} to the final position of the sequence. The range used is + * [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * {@link IArrayIterator RandomAccessIterator} shall point to a type for which {@link Iterator.swap swap} + * is properly defined. + * @param compare Binary function that accepts two elements in the range as arguments, and returns a value + * convertible to boolean. The value returned indicates whether the element passed as + * first argument is considered to go before the second in the specific strict weak ordering it defines. + * The function shall not modify any of its arguments. This can either be a function pointer or a + * function object. + */ + function is_heap_until>(first: RandomAccessIterator, last: RandomAccessIterator, compare: (x: T, y: T) => boolean): RandomAccessIterator; + /** + * Sort elements of heap. + * + * Sorts the elements in the heap range [first, last) into ascending order. + * + * The elements are compared using {@link less}, which shall be the same as used to construct the heap. + * + * The range loses its properties as a heap. + * + * @param first {@link IArrayIterator Random-access iterator} to the initial position of the sequence to be sorted. + * @param last {@link IArrayIterator Random-access iterator} to the final position of the sequence to be sorted. + * The range used is [first, last), which contains all the elements between first and + * last, including the element pointed by first but not the element pointed by last. + * {@link IArrayIterator RandomAccessIterator} shall point to a type for which {@link Iterator.swap swap} + * is properly defined. + */ + function sort_heap>(first: RandomAccessIterator, last: RandomAccessIterator): void; + /** + * Sort elements of heap. + * + * Sorts the elements in the heap range [first, last) into ascending order. + * + * The elements are compared using compare, which shall be the same as used to construct the heap. + * + * The range loses its properties as a heap. + * + * @param first {@link IArrayIterator Random-access iterator} to the initial position of the sequence to be sorted. + * @param last {@link IArrayIterator Random-access iterator} to the final position of the sequence to be sorted. + * The range used is [first, last), which contains all the elements between first and + * last, including the element pointed by first but not the element pointed by last. + * {@link IArrayIterator RandomAccessIterator} shall point to a type for which {@link Iterator.swap swap} + * is properly defined. + * @param compare Binary function that accepts two elements in the range as arguments, and returns a value + * convertible to boolean. The value returned indicates whether the element passed as + * first argument is considered to go before the second in the specific strict weak ordering it defines. + * The function shall not modify any of its arguments. This can either be a function pointer or a + * function object. + */ + function sort_heap>(first: RandomAccessIterator, last: RandomAccessIterator, compare: (x: T, y: T) => boolean): void; +} +declare namespace std { + /** + * Return iterator to lower bound. + * + * Returns an iterator pointing to the first element in the range [first, last) which does not + * compare less than val. + * + * The elements are compared using {@link less}. The elements in the range shall already be {@link is_sorted sorted} + * according to this same criterion ({@link less}), or at least {@link is_partitioned partitioned} with respect to + * val. + * + * The function optimizes the number of comparisons performed by comparing non-consecutive elements of the sorted + * range, which is specially efficient for {@link IArrayIterator random-access iterators}. + * + * Unlike {@link upper_bound}, the value pointed by the iterator returned by this function may also be equivalent + * to val, and not only greater. + * + * @param first {@link Iterator Forward iterator} to the initial position of a {@link is_sorted sorted} (or properly + * {@link is_partitioned partitioned}) sequence. + * @param last {@link Iterator Forward iterator} to the final position of a {@link is_sorted sorted} (or properly + * {@link is_partitioned partitioned}) sequence. The range used is [first, last), which + * contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + * @param val Value of the lower bound to search for in the range. T shall be a type supporting being compared + * with elements of the range [first, last) as the left-hand side operand of {@link less}. + * + * @return An iterator to the lower bound of val in the range. If all the element in the range compare less than + * val, the function returns last. + */ + function lower_bound>(first: ForwardIterator, last: ForwardIterator, val: T): ForwardIterator; + /** + * Return iterator to lower bound. + * + * Returns an iterator pointing to the first element in the range [first, last) which does not + * compare less than val. + * + * The elements are compared using compare. The elements in the range shall already be + * {@link is_sorted sorted} according to this same criterion (compare), or at least + * {@link is_partitioned partitioned} with respect to val. + * + * The function optimizes the number of comparisons performed by comparing non-consecutive elements of the sorted + * range, which is specially efficient for {@link IArrayIterator random-access iterators}. + * + * Unlike {@link upper_bound}, the value pointed by the iterator returned by this function may also be equivalent + * to val, and not only greater. + * + * @param first {@link Iterator Forward iterator} to the initial position of a {@link is_sorted sorted} (or properly + * {@link is_partitioned partitioned}) sequence. + * @param last {@link Iterator Forward iterator} to the final position of a {@link is_sorted sorted} (or properly + * {@link is_partitioned partitioned}) sequence. The range used is [first, last), which + * contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + * @param val Value of the lower bound to search for in the range. + * @param compare Binary function that accepts two arguments (the first of the type pointed by ForwardIterator, + * and the second, always val), and returns a value convertible to bool. The value + * returned indicates whether the first argument is considered to go before the second. The function + * shall not modify any of its arguments. + * + * @return An iterator to the lower bound of val in the range. If all the element in the range compare less than + * val, the function returns last. + */ + function lower_bound>(first: ForwardIterator, last: ForwardIterator, val: T, compare: (x: T, y: T) => boolean): ForwardIterator; + /** + * Return iterator to upper bound. + * + * Returns an iterator pointing to the first element in the range [first, last) which compares + * greater than val. + * + * The elements are compared using {@link less}. The elements in the range shall already be {@link is_sorted sorted} + * according to this same criterion ({@link less}), or at least {@link is_partitioned partitioned} with respect to + * val. + * + * The function optimizes the number of comparisons performed by comparing non-consecutive elements of the sorted + * range, which is specially efficient for {@link IArrayIterator random-access iterators}. + * + * Unlike {@link lower_bound}, the value pointed by the iterator returned by this function cannot be equivalent to + * val, only greater. + * + * @param first {@link Iterator Forward iterator} to the initial position of a {@link is_sorted sorted} (or properly + * {@link is_partitioned partitioned}) sequence. + * @param last {@link Iterator Forward iterator} to the final position of a {@link is_sorted sorted} (or properly + * {@link is_partitioned partitioned}) sequence. The range used is [first, last), which + * contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + * @param val Value of the lower bound to search for in the range. T shall be a type supporting being compared + * with elements of the range [first, last) as the left-hand side operand of {@link less}. + * + * @return An iterator to the upper bound of val in the range. If no element in the range comparse greater than + * val, the function returns last. + */ + function upper_bound>(first: ForwardIterator, last: ForwardIterator, val: T): ForwardIterator; + /** + * Return iterator to upper bound. + * + * Returns an iterator pointing to the first element in the range [first, last) which compares + * greater than val. + * + * The elements are compared using compare. The elements in the range shall already be + * {@link is_sorted sorted} according to this same criterion (compare), or at least + * {@link is_partitioned partitioned} with respect to val. + * + * The function optimizes the number of comparisons performed by comparing non-consecutive elements of the sorted + * range, which is specially efficient for {@link IArrayIterator random-access iterators}. + * + * Unlike {@link lower_bound}, the value pointed by the iterator returned by this function cannot be equivalent to + * val, only greater. + * + * @param first {@link Iterator Forward iterator} to the initial position of a {@link is_sorted sorted} (or properly + * {@link is_partitioned partitioned}) sequence. + * @param last {@link Iterator Forward iterator} to the final position of a {@link is_sorted sorted} (or properly + * {@link is_partitioned partitioned}) sequence. The range used is [first, last), which + * contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + * @param val Value of the lower bound to search for in the range. + * @param compare Binary function that accepts two arguments (the first of the type pointed by ForwardIterator, + * and the second, always val), and returns a value convertible to bool. The value + * returned indicates whether the first argument is considered to go before the second. The function + * shall not modify any of its arguments. + * + * @return An iterator to the upper bound of val in the range. If no element in the range comparse greater than + * val, the function returns last. + */ + function upper_bound>(first: ForwardIterator, last: ForwardIterator, val: T, compare: (x: T, y: T) => boolean): ForwardIterator; + /** + * Get subrange of equal elements. + * + * Returns the bounds of the subrange that includes all the elements of the range [first, last) with + * values equivalent to val. + * + * The elements are compared using {@link less}. Two elements, ax/i> and y are considered equivalent + * if (!less(x, y) && !less(y, x)). + * + * The elements in the range shall already be {@link is_sorted sorted} according to this same criterion + * ({@link less}), or at least {@link is_partitioned partitioned} with respect to val. + * + * If val is not equivalent to any value in the range, the subrange returned has a length of zero, with both + * iterators pointing to the nearest value greater than val, if any, or to last, if val compares + * greater than all the elements in the range. + * + * @param first {@link Iterator Forward iterator} to the initial position of a {@link is_sorted sorted} (or properly + * {@link is_partitioned partitioned}) sequence. + * @param last {@link Iterator Forward iterator} to the final position of a {@link is_sorted sorted} (or properly + * {@link is_partitioned partitioned}) sequence. The range used is [first, last), which + * contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + * @param val Value of the lower bound to search for in the range. T shall be a type supporting being compared + * with elements of the range [first, last) as the left-hand side operand of {@link less}. + * + * @return A {@link Pair} object, whose member {@link Pair.first} is an iterator to the lower bound of the subrange of + * equivalent values, and {@link Pair.second} its upper bound. The values are the same as those that would be + * returned by functions {@link lower_bound} and {@link upper_bound} respectively. + */ + function equal_range>(first: ForwardIterator, last: ForwardIterator, val: T): Pair; + /** + * Get subrange of equal elements. + * + * Returns the bounds of the subrange that includes all the elements of the range [first, last) with + * values equivalent to val. + * + * The elements are compared using compare. Two elements, ax/i> and y are considered equivalent + * if (!compare(x, y) && !compare(y, x)). + * + * The elements in the range shall already be {@link is_sorted sorted} according to this same criterion + * (compare), or at least {@link is_partitioned partitioned} with respect to val. + * + * If val is not equivalent to any value in the range, the subrange returned has a length of zero, with both + * iterators pointing to the nearest value greater than val, if any, or to last, if val compares + * greater than all the elements in the range. + * + * @param first {@link Iterator Forward iterator} to the initial position of a {@link is_sorted sorted} (or properly + * {@link is_partitioned partitioned}) sequence. + * @param last {@link Iterator Forward iterator} to the final position of a {@link is_sorted sorted} (or properly + * {@link is_partitioned partitioned}) sequence. The range used is [first, last), which + * contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + * @param val Value of the lower bound to search for in the range. + * @param compare Binary function that accepts two arguments of the type pointed by ForwardIterator (and of type + * T), and returns a value convertible to bool. The value returned indicates whether + * the first argument is considered to go before the second. The function shall not modify any of its + * arguments. + * + * @return A {@link Pair} object, whose member {@link Pair.first} is an iterator to the lower bound of the subrange of + * equivalent values, and {@link Pair.second} its upper bound. The values are the same as those that would be + * returned by functions {@link lower_bound} and {@link upper_bound} respectively. + */ + function equal_range>(first: ForwardIterator, last: ForwardIterator, val: T, compare: (x: T, y: T) => boolean): Pair; + /** + * Get subrange of equal elements. + * + * Returns the bounds of the subrange that includes all the elements of the range [first, last) with + * values equivalent to val. + * + * The elements are compared using {@link less}. Two elements, x and y are considered equivalent + * if (!less(x, y) && !less(y, x)). + * + * The elements in the range shall already be {@link is_sorted sorted} according to this same criterion + * ({@link less}), or at least {@link is_partitioned partitioned} with respect to val. + * + * If val is not equivalent to any value in the range, the subrange returned has a length of zero, with both + * iterators pointing to the nearest value greater than val, if any, or to last, if val compares + * greater than all the elements in the range. + * + * @param first {@link Iterator Forward iterator} to the initial position of a {@link is_sorted sorted} (or properly + * {@link is_partitioned partitioned}) sequence. + * @param last {@link Iterator Forward iterator} to the final position of a {@link is_sorted sorted} (or properly + * {@link is_partitioned partitioned}) sequence. The range used is [first, last), which + * contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + * @param val Value of the lower bound to search for in the range. T shall be a type supporting being compared + * with elements of the range [first, last) as the left-hand side operand of {@link less}. + * + * @return true if an element equivalent to val is found, and false otherwise. + */ + function binary_search>(first: ForwardIterator, last: ForwardIterator, val: T): boolean; + /** + * Get subrange of equal elements. + * + * Returns the bounds of the subrange that includes all the elements of the range [first, last) with + * values equivalent to val. + * + * The elements are compared using {compare}. Two elements, x and y are considered equivalent + * if (!compare(x, y) && !compare(y, x)). + * + * The elements in the range shall already be {@link is_sorted sorted} according to this same criterion + * (compare), or at least {@link is_partitioned partitioned} with respect to val. + * + * If val is not equivalent to any value in the range, the subrange returned has a length of zero, with both + * iterators pointing to the nearest value greater than val, if any, or to last, if val compares + * greater than all the elements in the range. + * + * @param first {@link Iterator Forward iterator} to the initial position of a {@link is_sorted sorted} (or properly + * {@link is_partitioned partitioned}) sequence. + * @param last {@link Iterator Forward iterator} to the final position of a {@link is_sorted sorted} (or properly + * {@link is_partitioned partitioned}) sequence. The range used is [first, last), which + * contains all the elements between first and last, including the element pointed by + * first but not the element pointed by last. + * @param val Value of the lower bound to search for in the range. + * @param compare Binary function that accepts two arguments of the type pointed by ForwardIterator (and of type + * T), and returns a value convertible to bool. The value returned indicates whether + * the first argument is considered to go before the second. The function shall not modify any of its + * arguments. + * + * @return true if an element equivalent to val is found, and false otherwise. + */ + function binary_search>(first: ForwardIterator, last: ForwardIterator, val: T, compare: (x: T, y: T) => boolean): boolean; +} +declare namespace std { + /** + * Test whether range is partitioned. + * + * Returns true if all the elements in the range [first, last) for which pred + * returns true precede those for which it returns false. + * + * If the range is {@link Container.empty empty}, the function returns true. + * + * @param first {@link Iterator Input iterator} to the initial position of the sequence. + * @param last {@link Iterator Input iterator} to the final position of the sequence. The range used is + * [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * @param pred Unary function that accepts an element in the range as argument, and returns a value convertible to + * bool. The value returned indicates whether the element belongs to the first group (if + * true, the element is expected before all the elements for which it returns + * false). The function shall not modify its argument. + * + * @return true if all the elements in the range [first, last) for which pred returns + * true precede those for which it returns false. Otherwise it returns + * false. If the range is {@link Container.empty empty}, the function returns true. + */ + function is_partitioned>(first: InputIterator, last: InputIterator, pred: (x: T) => boolean): boolean; + /** + * Partition range in two. + * + * Rearranges the elements from the range [first, last), in such a way that all the elements for + * which pred returns true precede all those for which it returns false. The iterator + * returned points to the first element of the second group. + * + * The relative ordering within each group is not necessarily the same as before the call. See + * {@link stable_partition} for a function with a similar behavior but with stable ordering within each group. + * + * @param first {@link Iterator Forward iterator} to the initial position of the sequence to partition. + * @param last {@link Iterator Forward iterator} to the final position of the sequence to partition. The range used is + * [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * @param pred Unary function that accepts an element in the range as argument, and returns a value convertible to + * bool. The value returned indicates whether the element belongs to the first group (if + * true, the element is expected before all the elements for which it returns + * false). The function shall not modify its argument. + * + * @return An iterator that points to the first element of the second group of elements (those for which pred + * returns false), or last if this group is {@link Container.empty empty}. + */ + function partition>(first: BidirectionalIterator, last: BidirectionalIterator, pred: (x: T) => boolean): BidirectionalIterator; + /** + * Partition range in two - stable ordering. + * + * Rearranges the elements in the range [first, last), in such a way that all the elements for which + * pred returns true precede all those for which it returns false, and, unlike + * function {@link partition}, the relative order of elements within each group is preserved. + * + * This is generally implemented using an internal temporary buffer. + * + * @param first {@link Iterator Bidirectional iterator} to the initial position of the sequence to partition. + * @param last {@link Iterator Bidirectional iterator} to the final position of the sequence to partition. The range + * used is [first, last), which contains all the elements between first and + * last, including the element pointed by first but not the element pointed by last. + * @param pred Unary function that accepts an element in the range as argument, and returns a value convertible to + * bool. The value returned indicates whether the element belongs to the first group (if + * true, the element is expected before all the elements for which it returns + * false). The function shall not modify its argument. + * + * @return An iterator that points to the first element of the second group of elements (those for which pred + * returns false), or last if this group is {@link Container.empty empty}. + */ + function stable_partition>(first: BidirectionalIterator, last: BidirectionalIterator, pred: (x: T) => boolean): BidirectionalIterator; + /** + * Partition range into two. + * + * Copies the elements in the range [first, last) for which pred returns true + * into the range pointed by result_true, and those for which it does not into the range pointed by + * result_false. + * + * @param first {@link Iterator Input iterator} to the initial position of the range to be copy-partitioned. + * @param last {@link Iterator Input iterator} to the final position of the range to be copy-partitioned. The range + * used is [first, last), which contains all the elements between first and + * last, including the element pointed by first but not the element pointed by last. + * @param result_true {@link Iterator Output iterator} to the initial position of the range where the elements for + * which pred returns true are stored. + * @param result_false {@link Iterator Output iterator} to the initial position of the range where the elements for + * which pred returns false are stored. + * @param pred Unary function that accepts an element pointed by InputIterator as argument, and returns a value + * convertible to bool. The value returned indicates on which result range the element is + * copied. The function shall not modify its argument. + * + * @return A {@link Pair} of iterators with the end of the generated sequences pointed by result_true and + * result_false, respectivelly. Its member {@link Pair.first first} points to the element that follows + * the last element copied to the sequence of elements for which pred returned true. Its + * member {@link Pair.second second} points to the element that follows the last element copied to the sequence + * of elements for which pred returned false. + */ + function partition_copy, OutputIterator1 extends base.ILinearIterator, OutputIterator2 extends base.ILinearIterator>(first: InputIterator, last: InputIterator, result_true: OutputIterator1, result_false: OutputIterator2, pred: (val: T) => T): Pair; + /** + * Get partition point. + * + * Returns an iterator to the first element in the partitioned range [first, last) for which + * pred is not true, indicating its partition point. + * + * The elements in the range shall already {@link is_partitioned be partitioned}, as if {@link partition} had been + * called with the same arguments. + * + * The function optimizes the number of comparisons performed by comparing non-consecutive elements of the sorted + * range, which is specially efficient for {@link Iteartor random-access iterators}. + * + * @param first {@link Iterator Forward iterator} to the initial position of the partitioned sequence. + * @param last {@link Iterator Forward iterator} to the final position of the partitioned sequence. The range checked + * is [first, last), which contains all the elements between first an last, + * including the element pointed by first but not the element pointed by last. + * @param pred Unary function that accepts an element in the range as argument, and returns a value convertible to + * bool. The value returned indicates whether the element goes before the partition point (if + * true, it goes before; if false goes at or after it). The function shall not + * modify its argument. + * + * @return An iterator to the first element in the partitioned range [first, last) for which pred + * is not true, or last if it is not true for any element. + */ + function partition_point>(first: ForwardIterator, last: ForwardIterator, pred: (x: T) => boolean): ForwardIterator; +} +declare namespace std { + /** + * Merge sorted ranges. + * + * Combines the elements in the sorted ranges [first1, last1) and [first2, last2), into + * a new range beginning at result with all its elements sorted. + * + * The elements are compared using {@link less}. The elements in both ranges shall already be ordered according to + * this same criterion ({@link less}). The resulting range is also sorted according to this. + * + * @param first1 {@link Iterator Input iterator} to the initial position of the first sorted sequence. + * @param last1 {@link Iterator Input iterator} to the final position of the first sorted sequence. The range used is + * [first1, last1), which contains all the elements between first1 and last1, + * including the element pointed by first1 but not the element pointed by last1. + * @param first2 {@link Iterator Input iterator} to the initial position of the second sorted sequence. + * @param last2 {@link Iterator Input iterator} to the final position of the second sorted sequence. The range used is + * [first2, last2). + * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting combined + * range is stored. Its size is equal to the sum of both ranges above. + * + * @return An iterator pointing to the past-the-end element in the resulting sequence. + */ + function merge, InputIterator2 extends Iterator, OutputIterator extends base.ILinearIterator>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, result: OutputIterator): OutputIterator; + /** + * Merge sorted ranges. + * + * Combines the elements in the sorted ranges [first1, last1) and [first2, last2), into + * a new range beginning at result with all its elements sorted. + * + * The elements are compared using {@link less}. The elements in both ranges shall already be ordered according to + * this same criterion (compare). The resulting range is also sorted according to this. + * + * @param first1 {@link Iterator Input iterator} to the initial position of the first sorted sequence. + * @param last1 {@link Iterator Input iterator} to the final position of the first sorted sequence. The range used is + * [first1, last1), which contains all the elements between first1 and last1, + * including the element pointed by first1 but not the element pointed by last1. + * @param first2 {@link Iterator Input iterator} to the initial position of the second sorted sequence. + * @param last2 {@link Iterator Input iterator} to the final position of the second sorted sequence. The range used is + * [first2, last2). + * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting combined + * range is stored. Its size is equal to the sum of both ranges above. + * @param compare Binary function that accepts two arguments of the types pointed by the iterators, and returns a value + * convertible to bool. The value returned indicates whether the first argument is + * considered to go before the second in the specific strict weak ordering it defines. The + * function shall not modify any of its arguments. + * + * @return An iterator pointing to the past-the-end element in the resulting sequence. + */ + function merge, InputIterator2 extends Iterator, OutputIterator extends base.ILinearIterator>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, result: OutputIterator, compare: (x: T, y: T) => boolean): OutputIterator; + /** + * Merge consecutive sorted ranges. + * + * Merges two consecutive sorted ranges: [first, middle) and [middle, last), putting + * the result into the combined sorted range [first, last). + * + * The elements are compared using {@link less}. The elements in both ranges shall already be ordered according to + * this same criterion ({@link less}). The resulting range is also sorted according to this. + * + * The function preserves the relative order of elements with equivalent values, with the elements in the first + * range preceding those equivalent in the second. + * + * @param first {@link Iterator Bidirectional iterator} to the initial position in the first sorted sequence to merge. + * This is also the initial position where the resulting merged range is stored. + * @param middle {@link Iterator Bidirectional iterator} to the initial position of the second sorted sequence, which + * because both sequences must be consecutive, matches the past-the-end position of the first + * sequence. + * @param last {@link Iterator Bidirectional iterator} to the past-the-end position of the second sorted + * sequence. This is also the past-the-end position of the range where the resulting merged range is + * stored. + */ + function inplace_merge>(first: BidirectionalIterator, middle: BidirectionalIterator, last: BidirectionalIterator): void; + /** + * Merge consecutive sorted ranges. + * + * Merges two consecutive sorted ranges: [first, middle) and [middle, last), putting + * the result into the combined sorted range [first, last). + * + * The elements are compared using compare. The elements in both ranges shall already be ordered according + * to this same criterion (compare). The resulting range is also sorted according to this. + * + * The function preserves the relative order of elements with equivalent values, with the elements in the first + * range preceding those equivalent in the second. + * + * @param first {@link Iterator Bidirectional iterator} to the initial position in the first sorted sequence to merge. + * This is also the initial position where the resulting merged range is stored. + * @param middle {@link Iterator Bidirectional iterator} to the initial position of the second sorted sequence, which + * because both sequences must be consecutive, matches the past-the-end position of the first + * sequence. + * @param last {@link Iterator Bidirectional iterator} to the past-the-end position of the second sorted + * sequence. This is also the past-the-end position of the range where the resulting merged range is + * stored. + * @param compare Binary function that accepts two arguments of the types pointed by the iterators, and returns a value + * convertible to bool. The value returned indicates whether the first argument is + * considered to go before the second in the specific strict weak ordering it defines. The + * function shall not modify any of its arguments. + */ + function inplace_merge>(first: BidirectionalIterator, middle: BidirectionalIterator, last: BidirectionalIterator, compare: (x: T, y: T) => boolean): void; + /** + * Test whether sorted range includes another sorted range. + * + * Returns true if the sorted range [first1, last1) contains all the elements in the + * sorted range [first2, last2). + * + * The elements are compared using {@link less}. Two elements, x and y are considered equivalent + * if (!less(x, y) && !less(y, x)). + * + * The elements in the range shall already be ordered according to this same criterion ({@link less}). + * + * @param first1 {@link Iterator Input iterator} to the initial position of the first sorted sequence. + * @param last1 {@link Iterator Input iterator} to the final position of the first sorted sequence (which is tested on + * whether it contains the second sequence). The range used is [first1, last1), which + * contains all the elements between first1 and last1, including the element pointed by + * first1 but not the element pointed by last1. + * @param first2 {@link Iterator Input iterator} to the initial position of the second sorted sequence. + * @param last2 {@link Iterator Input iterator} to the final position of the second sorted sequence. (which is tested + * on whether it is contained in the first sequence). The range used is [first2, last2). + * + * @return true if every element in the range [first2, last2) is contained in the range + * [first1, last1), false otherwise. If [first2, last2) is an empty + * range, the function returns true. + */ + function includes, InputIterator2 extends Iterator>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2): boolean; + /** + * Test whether sorted range includes another sorted range. + * + * Returns true if the sorted range [first1, last1) contains all the elements in the + * sorted range [first2, last2). + * + * The elements are compared using compare. Two elements, x and y are considered equivalent + * if (!compare(x, y) && !compare(y, x)). + * + * The elements in the range shall already be ordered according to this same criterion (compare). + * + * @param first1 {@link Iterator Input iterator} to the initial position of the first sorted sequence. + * @param last1 {@link Iterator Input iterator} to the final position of the first sorted sequence (which is tested on + * whether it contains the second sequence). The range used is [first1, last1), which + * contains all the elements between first1 and last1, including the element pointed by + * first1 but not the element pointed by last1. + * @param first2 {@link Iterator Input iterator} to the initial position of the second sorted sequence. + * @param last2 {@link Iterator Input iterator} to the final position of the second sorted sequence. (which is tested + * on whether it is contained in the first sequence). The range used is [first2, last2). + * @param compare Binary function that accepts two elements as arguments (one from each of the two sequences, in the + * same order), and returns a value convertible to bool. The value returned indicates + * whether the element passed as first argument is considered to go before the second in the specific + * strict weak ordering it defines. The function shall not modify any of its arguments. + * + * @return true if every element in the range [first2, last2) is contained in the range + * [first1, last1), false otherwise. If [first2, last2) is an empty + * range, the function returns true. + */ + function includes, InputIterator2 extends Iterator>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, compare: (x: T, y: T) => boolean): boolean; + /** + * Union of two sorted ranges. + * + * Constructs a sorted range beginning in the location pointed by result with the set union of the + * two sorted ranges [first1, last1) and [first2, last2). + * + * The union of two sets is formed by the elements that are present in either one of the sets, or in both. + * Elements from the second range that have an equivalent element in the first range are not copied to the resulting + * range. + * + * The elements are compared using {@link less}. Two elements, x and y are considered equivalent + * if (!less(x, y) && !less(y, x)). + * + * The elements in the ranges shall already be ordered according to this same criterion ({@link less}). The + * resulting range is also sorted according to this. + * + * @param first1 {@link Iterator Input iterator} to the initial position of the first sorted sequence. + * @param last1 {@link Iterator Input iterator} to the final position of the first sorted sequence. The range used is + * [first1, last1), which contains all the elements between first1 and last1, + * including the element pointed by first1 but not the element pointed by last1. + * @param first2 {@link Iterator Input iterator} to the initial position of the second sorted sequence. + * @param last2 {@link Iterator Input iterator} to the final position of the second sorted sequence. The range used is + * [first2, last2). + * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting sequence is + * stored. The pointed type shall support being assigned the value of an element from the other ranges. + * + * @return An iterator to the end of the constructed range. + */ + function set_union, InputIterator2 extends Iterator, OutputIterator extends base.ILinearIterator>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, result: OutputIterator): OutputIterator; + /** + * Union of two sorted ranges. + * + * Constructs a sorted range beginning in the location pointed by result with the set union of the + * two sorted ranges [first1, last1) and [first2, last2). + * + * The union of two sets is formed by the elements that are present in either one of the sets, or in both. + * Elements from the second range that have an equivalent element in the first range are not copied to the resulting + * range. + * + * The elements are compared using compare. Two elements, x and y are considered equivalent + * if (!compare(x, y) && !compare(y, x)). + * + * The elements in the ranges shall already be ordered according to this same criterion (compare). The + * resulting range is also sorted according to this. + * + * @param first1 {@link Iterator Input iterator} to the initial position of the first sorted sequence. + * @param last1 {@link Iterator Input iterator} to the final position of the first sorted sequence. The range used is + * [first1, last1), which contains all the elements between first1 and last1, + * including the element pointed by first1 but not the element pointed by last1. + * @param first2 {@link Iterator Input iterator} to the initial position of the second sorted sequence. + * @param last2 {@link Iterator Input iterator} to the final position of the second sorted sequence. The range used is + * [first2, last2). + * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting sequence is + * stored. The pointed type shall support being assigned the value of an element from the other ranges. + * @param compare Binary function that accepts two arguments of the types pointed by the input iterators, and returns a + * value convertible to bool. The value returned indicates whether the first argument is + * considered to go before the second in the specific strict weak ordering it defines. The + * function shall not modify any of its arguments. + * + * @return An iterator to the end of the constructed range. + */ + function set_union, InputIterator2 extends Iterator, OutputIterator extends base.ILinearIterator>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, result: OutputIterator, compare: (x: T, y: T) => boolean): OutputIterator; + /** + * Intersection of two sorted ranges. + * + * Constructs a sorted range beginning in the location pointed by result with the set intersection of + * the two sorted ranges [first1, last1) and [first2, last2). + * + * The intersection of two sets is formed only by the elements that are present in both sets. The elements + * copied by the function come always from the first range, in the same order. + * + * The elements are compared using {@link less}. Two elements, x and y are considered equivalent + * if (!less(x, y) && !less(y, x)). + * + * The elements in the ranges shall already be ordered according to this same criterion ({@link less}). The + * resulting range is also sorted according to this. + * + * @param first1 {@link Iterator Input iterator} to the initial position of the first sorted sequence. + * @param last1 {@link Iterator Input iterator} to the final position of the first sorted sequence. The range used is + * [first1, last1), which contains all the elements between first1 and last1, + * including the element pointed by first1 but not the element pointed by last1. + * @param first2 {@link Iterator Input iterator} to the initial position of the second sorted sequence. + * @param last2 {@link Iterator Input iterator} to the final position of the second sorted sequence. The range used is + * [first2, last2). + * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting sequence is + * stored. The pointed type shall support being assigned the value of an element from the first range. + * + * @return An iterator to the end of the constructed range. + */ + function set_intersection, InputIterator2 extends Iterator, OutputIterator extends base.ILinearIterator>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, result: OutputIterator): OutputIterator; + /** + * Intersection of two sorted ranges. + * + * Constructs a sorted range beginning in the location pointed by result with the set intersection of + * the two sorted ranges [first1, last1) and [first2, last2). + * + * The intersection of two sets is formed only by the elements that are present in both sets. The elements + * copied by the function come always from the first range, in the same order. + * + * The elements are compared using compare. Two elements, x and y are considered equivalent + * if (!compare(x, y) && !compare(y, x)). + * + * The elements in the ranges shall already be ordered according to this same criterion (compare). The + * resulting range is also sorted according to this. + * + * @param first1 {@link Iterator Input iterator} to the initial position of the first sorted sequence. + * @param last1 {@link Iterator Input iterator} to the final position of the first sorted sequence. The range used is + * [first1, last1), which contains all the elements between first1 and last1, + * including the element pointed by first1 but not the element pointed by last1. + * @param first2 {@link Iterator Input iterator} to the initial position of the second sorted sequence. + * @param last2 {@link Iterator Input iterator} to the final position of the second sorted sequence. The range used is + * [first2, last2). + * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting sequence is + * stored. The pointed type shall support being assigned the value of an element from the first range. + * @param compare Binary function that accepts two arguments of the types pointed by the input iterators, and returns a + * value convertible to bool. The value returned indicates whether the first argument is + * considered to go before the second in the specific strict weak ordering it defines. The + * function shall not modify any of its arguments. + * + * @return An iterator to the end of the constructed range. + */ + function set_intersection, InputIterator2 extends Iterator, OutputIterator extends base.ILinearIterator>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, result: OutputIterator, compare: (x: T, y: T) => boolean): OutputIterator; + /** + * Difference of two sorted ranges. + * + * Constructs a sorted range beginning in the location pointed by result with the set difference of + * the sorted range [first1, last1) with respect to the sorted range [first2, last2). + * + * The difference of two sets is formed by the elements that are present in the first set, but not in the + * second one. The elements copied by the function come always from the first range, in the same order. + * + * For containers supporting multiple occurrences of a value, the difference includes as many occurrences of + * a given value as in the first range, minus the amount of matching elements in the second, preserving order. + * + * Notice that this is a directional operation - for a symmetrical equivalent, see {@link set_symmetric_difference}. + * + * The elements are compared using {@link less}. Two elements, x and y are considered equivalent + * if (!less(x, y) && !less(y, x)). + * + * The elements in the ranges shall already be ordered according to this same criterion ({@link less}). The + * resulting range is also sorted according to this. + * + * @param first1 {@link Iterator Input iterator} to the initial position of the first sorted sequence. + * @param last1 {@link Iterator Input iterator} to the final position of the first sorted sequence. The range used is + * [first1, last1), which contains all the elements between first1 and last1, + * including the element pointed by first1 but not the element pointed by last1. + * @param first2 {@link Iterator Input iterator} to the initial position of the second sorted sequence. + * @param last2 {@link Iterator Input iterator} to the final position of the second sorted sequence. The range used is + * [first2, last2). + * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting sequence is + * stored. The pointed type shall support being assigned the value of an element from the first range. + * + * @return An iterator to the end of the constructed range. + */ + function set_difference, InputIterator2 extends Iterator, OutputIterator extends base.ILinearIterator>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, result: OutputIterator): OutputIterator; + /** + * Difference of two sorted ranges. + * + * Constructs a sorted range beginning in the location pointed by result with the set difference of + * the sorted range [first1, last1) with respect to the sorted range [first2, last2). + * + * The difference of two sets is formed by the elements that are present in the first set, but not in the + * second one. The elements copied by the function come always from the first range, in the same order. + * + * For containers supporting multiple occurrences of a value, the difference includes as many occurrences of + * a given value as in the first range, minus the amount of matching elements in the second, preserving order. + * + * Notice that this is a directional operation - for a symmetrical equivalent, see {@link set_symmetric_difference}. + * + * The elements are compared using compare. Two elements, x and y are considered equivalent + * if (!compare(x, y) && !compare(y, x)). + * + * The elements in the ranges shall already be ordered according to this same criterion (compare). The + * resulting range is also sorted according to this. + * + * @param first1 {@link Iterator Input iterator} to the initial position of the first sorted sequence. + * @param last1 {@link Iterator Input iterator} to the final position of the first sorted sequence. The range used is + * [first1, last1), which contains all the elements between first1 and last1, + * including the element pointed by first1 but not the element pointed by last1. + * @param first2 {@link Iterator Input iterator} to the initial position of the second sorted sequence. + * @param last2 {@link Iterator Input iterator} to the final position of the second sorted sequence. The range used is + * [first2, last2). + * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting sequence is + * stored. The pointed type shall support being assigned the value of an element from the first range. + * @param compare Binary function that accepts two arguments of the types pointed by the input iterators, and returns a + * value convertible to bool. The value returned indicates whether the first argument is + * considered to go before the second in the specific strict weak ordering it defines. The + * function shall not modify any of its arguments. + * + * @return An iterator to the end of the constructed range. + */ + function set_difference, InputIterator2 extends Iterator, OutputIterator extends base.ILinearIterator>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, result: OutputIterator, compare: (x: T, y: T) => boolean): OutputIterator; + /** + * Symmetric difference of two sorted ranges. + * + * Constructs a sorted range beginning in the location pointed by0 result with the set + * symmetric difference of the two sorted ranges [first1, last1) and [first2, last2). + * + * The symmetric difference of two sets is formed by the elements that are present in one of the sets, but + * not in the other. Among the equivalent elements in each range, those discarded are those that appear before in the + * existent order before the call. The existing order is also preserved for the copied elements. + * + * The elements are compared using {@link less}. Two elements, x and y are considered equivalent + * if (!less(x, y) && !less(y, x)). + * + * The elements in the ranges shall already be ordered according to this same criterion ({@link less}). The + * resulting range is also sorted according to this. + * + * @param first1 {@link Iterator Input iterator} to the initial position of the first sorted sequence. + * @param last1 {@link Iterator Input iterator} to the final position of the first sorted sequence. The range used is + * [first1, last1), which contains all the elements between first1 and last1, + * including the element pointed by first1 but not the element pointed by last1. + * @param first2 {@link Iterator Input iterator} to the initial position of the second sorted sequence. + * @param last2 {@link Iterator Input iterator} to the final position of the second sorted sequence. The range used is + * [first2, last2). + * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting sequence is + * stored. The pointed type shall support being assigned the value of an element from the other ranges. + * @param compare Binary function that accepts two arguments of the types pointed by the input iterators, and returns a + * value convertible to bool. The value returned indicates whether the first argument is + * considered to go before the second in the specific strict weak ordering it defines. The + * function shall not modify any of its arguments. + * + * @return An iterator to the end of the constructed range. + */ + function set_symmetric_difference, InputIterator2 extends Iterator, OutputIterator extends base.ILinearIterator>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, result: OutputIterator): OutputIterator; + /** + * Symmetric difference of two sorted ranges. + * + * Constructs a sorted range beginning in the location pointed by0 result with the set + * symmetric difference of the two sorted ranges [first1, last1) and [first2, last2). + * + * The symmetric difference of two sets is formed by the elements that are present in one of the sets, but + * not in the other. Among the equivalent elements in each range, those discarded are those that appear before in the + * existent order before the call. The existing order is also preserved for the copied elements. + * + * The elements are compared using compare. Two elements, x and y are considered equivalent + * if (!compare(x, y) && !compare(y, x)). + * + * The elements in the ranges shall already be ordered according to this same criterion (compare). The + * resulting range is also sorted according to this. + * + * @param first1 {@link Iterator Input iterator} to the initial position of the first sorted sequence. + * @param last1 {@link Iterator Input iterator} to the final position of the first sorted sequence. The range used is + * [first1, last1), which contains all the elements between first1 and last1, + * including the element pointed by first1 but not the element pointed by last1. + * @param first2 {@link Iterator Input iterator} to the initial position of the second sorted sequence. + * @param last2 {@link Iterator Input iterator} to the final position of the second sorted sequence. The range used is + * [first2, last2). + * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting sequence is + * stored. The pointed type shall support being assigned the value of an element from the other ranges. + * @param compare Binary function that accepts two arguments of the types pointed by the input iterators, and returns a + * value convertible to bool. The value returned indicates whether the first argument is + * considered to go before the second in the specific strict weak ordering it defines. The + * function shall not modify any of its arguments. + * + * @return An iterator to the end of the constructed range. + */ + function set_symmetric_difference, InputIterator2 extends Iterator, OutputIterator extends base.ILinearIterator>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, result: OutputIterator, compare: (x: T, y: T) => boolean): OutputIterator; +} +declare namespace std { + /** + * Return the smallest. + * + * Returns the smallest of all the elements in the args. + * + * @param args Values to compare. + * + * @return The lesser of the values passed as arguments. + */ + function min(...args: T[]): T; + /** + * Return the largest. + * + * Returns the largest of all the elements in the args. + * + * @param args Values to compare. + * + * @return The largest of the values passed as arguments. + */ + function max(...args: T[]): T; + /** + * Return smallest and largest elements. + * + * Returns a {@link Pair} with the smallest of all the elements in the args as first element (the first of + * them, if there are more than one), and the largest as second (the last of them, if there are more than one). + * + * @param args Values to compare. + * + * @return The lesser and greatest of the values passed as arguments. + */ + function minmax(...args: T[]): Pair; + /** + * Return smallest element in range. + * + * Returns an iterator pointing to the element with the smallest value in the range [first, last). + * + * The comparisons are performed using either {@link less}; An element is the smallest if no other element + * compares less than it. If more than one element fulfills this condition, the iterator returned points to the first + * of such elements. + * + * @param first {@link Iteartor Input iterator} to the initial final position of the sequence to compare. + * @param last {@link Iteartor Input iterator} to the final final position of the sequence to compare. The range used + * is [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * + * @return An iterator to smallest value in the range, or last if the range is empty. + */ + function min_element>(first: ForwardIterator, last: ForwardIterator): ForwardIterator; + /** + * Return smallest element in range. + * + * Returns an iterator pointing to the element with the smallest value in the range [first, last). + * + * The comparisons are performed using either compare; An element is the smallest if no other element + * compares less than it. If more than one element fulfills this condition, the iterator returned points to the first + * of such elements. + * + * @param first {@link Iteartor Input iterator} to the initial final position of the sequence to compare. + * @param last {@link Iteartor Input iterator} to the final final position of the sequence to compare. The range used + * is [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * @param compare Binary function that accepts two elements in the range as arguments, and returns a value convertible + * to bool. The value returned indicates whether the element passed as first argument is + * considered less than the second. The function shall not modify any of its arguments. + * + * @return An iterator to smallest value in the range, or last if the range is empty. + */ + function min_element>(first: ForwardIterator, last: ForwardIterator, compare: (x: T, y: T) => boolean): ForwardIterator; + /** + * Return largest element in range. + * + * Returns an iterator pointing to the element with the largest value in the range [first, last). + * + * The comparisons are performed using either {@link greater}; An element is the largest if no other element + * compares less than it. If more than one element fulfills this condition, the iterator returned points to the first + * of such elements. + * + * @param first {@link Iteartor Input iterator} to the initial final position of the sequence to compare. + * @param last {@link Iteartor Input iterator} to the final final position of the sequence to compare. The range used + * is [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * + * @return An iterator to largest value in the range, or last if the range is empty. + */ + function max_element>(first: ForwardIterator, last: ForwardIterator): ForwardIterator; + /** + * Return largest element in range. + * + * Returns an iterator pointing to the element with the largest value in the range [first, last). + * + * The comparisons are performed using either compare; An element is the largest if no other element + * compares less than it. If more than one element fulfills this condition, the iterator returned points to the first + * of such elements. + * + * @param first {@link Iteartor Input iterator} to the initial final position of the sequence to compare. + * @param last {@link Iteartor Input iterator} to the final final position of the sequence to compare. The range used + * is [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * @param compare Binary function that accepts two elements in the range as arguments, and returns a value convertible + * to bool. The value returned indicates whether the element passed as first argument is + * considered less than the second. The function shall not modify any of its arguments. + * + * @return An iterator to largest value in the range, or last if the range is empty. + */ + function max_element>(first: ForwardIterator, last: ForwardIterator, compare: (x: T, y: T) => boolean): ForwardIterator; + /** + * Return smallest and largest elements in range. + * + * Returns a {@link Pair} with an iterator pointing to the element with the smallest value in the range + * [first, last) as first element, and the largest as second. + * + * The comparisons are performed using either {@link less} and {@link greater}. + * + * If more than one equivalent element has the smallest value, the first iterator points to the first of such + * elements. + * + * If more than one equivalent element has the largest value, the second iterator points to the last of such + * elements. + * + * @param first {@link Iteartor Input iterator} to the initial final position of the sequence to compare. + * @param last {@link Iteartor Input iterator} to the final final position of the sequence to compare. The range used + * is [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * @param compare Binary function that accepts two elements in the range as arguments, and returns a value convertible + * to bool. The value returned indicates whether the element passed as first argument is + * considered less than the second. The function shall not modify any of its arguments. + * + * @return A {@link Pair} with an iterator pointing to the element with the smallest value in the range + * [first, last) as first element, and the largest as second. + */ + function minmax_element>(first: ForwardIterator, last: ForwardIterator): Pair; + /** + * Return smallest and largest elements in range. + * + * Returns a {@link Pair} with an iterator pointing to the element with the smallest value in the range + * [first, last) as first element, and the largest as second. + * + * The comparisons are performed using either compare. + * + * If more than one equivalent element has the smallest value, the first iterator points to the first of such + * elements. + * + * If more than one equivalent element has the largest value, the second iterator points to the last of such + * elements. + * + * @param first {@link Iteartor Input iterator} to the initial final position of the sequence to compare. + * @param last {@link Iteartor Input iterator} to the final final position of the sequence to compare. The range used + * is [first, last), which contains all the elements between first and last, + * including the element pointed by first but not the element pointed by last. + * @param compare Binary function that accepts two elements in the range as arguments, and returns a value convertible + * to bool. The value returned indicates whether the element passed as first argument is + * considered less than the second. The function shall not modify any of its arguments. + * + * @return A {@link Pair} with an iterator pointing to the element with the smallest value in the range + * [first, last) as first element, and the largest as second. + */ + function minmax_element>(first: ForwardIterator, last: ForwardIterator, compare: (x: T, y: T) => boolean): Pair; + /** + * Clamp a value between a pair of boundary. + * + * @param v The value to clamp. + * @param lo Start of the boundaries to clamp *v* to. + * @param hi Terminal of the boundaries to clamp *v* to. + * + * @return *lo* if *v* is less than *lo*, *hi* if *hi* is less than *v*, otherwise *v*. + */ + function clamp(v: T, lo: T, hi: T): T; + /** + * Clamp a value between a pair of boundary. + * + * @param v The value to clamp. + * @param lo Start of the boundaries to clamp *v* to. + * @param hi Terminal of the boundaries to clamp *v* to. + * @param comp Binary function that accepts two elements as arguments (one of each of the two sequences, in the + * same order), and returns a value convertible to bool. The value returned indicates + * whether the elements are considered to match in the context of this function. + * + * @return *lo* if *v* is less than *lo*, *hi* if *hi* is less than *v*, otherwise *v*. + */ + function clamp(v: T, lo: T, hi: T, comp: (x: T, y: T) => boolean): T; + /** + * Test whether range is permutation of another. + * + * Compares the elements in the range [first1, last1) with those in the range beginning at + * first2, and returns true if all of the elements in both ranges match, even in a different + * order. + * + * @param first1 An {@link Iterator} to the initial position of the first sequence. + * @param last1 An {@link Iterator} to the final position in a sequence. The range used is + * [first1, last1), including the element pointed by first1, but not the element + * pointed by last1. + * @param first2 An {@link Iterator} to the initial position of the second sequence. The comparison includes up to + * as many elements of this sequence as those in the range [first1, last1). + * + * @return true if all the elements in the range [first1, last1) compare equal to those + * of the range starting at first2 in any order, and false otherwise. + */ + function is_permutation, Iterator2 extends Iterator>(first1: Iterator1, last1: Iterator1, first2: Iterator2): boolean; + /** + * Test whether range is permutation of another. + * + * Compares the elements in the range [first1, last1) with those in the range beginning at + * first2, and returns true if all of the elements in both ranges match, even in a different + * order. + * + * @param first1 An {@link Iterator} to the initial position of the first sequence. + * @param last1 An {@link Iterator} to the final position in a sequence. The range used is + * [first1, last1), including the element pointed by first1, but not the element + * pointed by last1. + * @param first2 An {@link Iterator} to the initial position of the second sequence. The comparison includes up to + * as many elements of this sequence as those in the range [first1, last1). + * @param pred Binary function that accepts two elements as argument (one of each of the two sequences, in the same + * order), and returns a value convertible to bool. The value returned indicates whether + * the elements are considered to match in the context of this function. + * + * @return true if all the elements in the range [first1, last1) compare equal to those + * of the range starting at first2 in any order, and false otherwise. + */ + function is_permutation, Iterator2 extends Iterator>(first1: Iterator1, last1: Iterator1, first2: Iterator2, pred: (x: T, y: T) => boolean): boolean; + /** + * Transform range to previous permutation. + * + * Rearranges the elements in the range [*first*, *last*) into the previous *lexicographically-ordered* permutation. + * + * A *permutation* is each one of the N! possible arrangements the elements can take (where *N* is the number of + * elements in the range). Different permutations can be ordered according to how they compare + * {@link lexicographicaly lexicographical_compare} to each other; The first such-sorted possible permutation (the one + * that would compare *lexicographically smaller* to all other permutations) is the one which has all its elements + * sorted in ascending order, and the largest has all its elements sorted in descending order. + * + * The comparisons of individual elements are performed using the {@link less less()} function. + * + * If the function can determine the previous permutation, it rearranges the elements as such and returns true. If + * that was not possible (because it is already at the lowest possible permutation), it rearranges the elements + * according to the last permutation (sorted in descending order) and returns false. + * + * @param first Bidirectional iterators to the initial positions of the sequence + * @param last Bidirectional iterators to the final positions of the sequence. The range used is [*first*, *last*), + * which contains all the elements between *first* and *last*, including the element pointed by *first* + * but not the element pointed by *last*. + * + * @return true if the function could rearrange the object as a lexicographicaly smaller permutation. Otherwise, the + * function returns false to indicate that the arrangement is not less than the previous, but the largest + * possible (sorted in descending order). + */ + function prev_permutation>(first: BidirectionalIterator, last: BidirectionalIterator): boolean; + /** + * Transform range to previous permutation. + * + * Rearranges the elements in the range [*first*, *last*) into the previous *lexicographically-ordered* permutation. + * + * A *permutation* is each one of the N! possible arrangements the elements can take (where *N* is the number of + * elements in the range). Different permutations can be ordered according to how they compare + * {@link lexicographicaly lexicographical_compare} to each other; The first such-sorted possible permutation (the one + * that would compare *lexicographically smaller* to all other permutations) is the one which has all its elements + * sorted in ascending order, and the largest has all its elements sorted in descending order. + * + * The comparisons of individual elements are performed using the *compare*. + * + * If the function can determine the previous permutation, it rearranges the elements as such and returns true. If + * that was not possible (because it is already at the lowest possible permutation), it rearranges the elements + * according to the last permutation (sorted in descending order) and returns false. + * + * @param first Bidirectional iterators to the initial positions of the sequence + * @param last Bidirectional iterators to the final positions of the sequence. The range used is [*first*, *last*), + * which contains all the elements between *first* and *last*, including the element pointed by *first* + * but not the element pointed by *last*. + * @param compare Binary function that accepts two arguments of the type pointed by BidirectionalIterator, and returns + * a value convertible to bool. The value returned indicates whether the first argument is considered + * to go before the second in the specific strict weak ordering it defines. + * + * @return true if the function could rearrange the object as a lexicographicaly smaller permutation. Otherwise, the + * function returns false to indicate that the arrangement is not less than the previous, but the largest + * possible (sorted in descending order). + */ + function prev_permutation>(first: BidirectionalIterator, last: BidirectionalIterator, compare: (x: T, y: T) => boolean): boolean; + /** + * Transform range to next permutation. + * + * Rearranges the elements in the range [*first*, *last*) into the next *lexicographically greater* permutation. + * + * A permutation is each one of the *N!* possible arrangements the elements can take (where *N* is the number of + * elements in the range). Different permutations can be ordered according to how they compare + * {@link lexicographicaly lexicographical_compare} to each other; The first such-sorted possible permutation (the one + * that would compare *lexicographically smaller* to all other permutations) is the one which has all its elements + * sorted in ascending order, and the largest has all its elements sorted in descending order. + * + * The comparisons of individual elements are performed using the {@link less} function. + * + * If the function can determine the next higher permutation, it rearranges the elements as such and returns true. If + * that was not possible (because it is already at the largest possible permutation), it rearranges the elements + * according to the first permutation (sorted in ascending order) and returns false. + * + * @param first Bidirectional iterators to the initial positions of the sequence + * @param last Bidirectional iterators to the final positions of the sequence. The range used is [*first*, *last*), + * which contains all the elements between *first* and *last*, including the element pointed by *first* + * but not the element pointed by *last*. + * + * @return true if the function could rearrange the object as a lexicographicaly greater permutation. Otherwise, the + * function returns false to indicate that the arrangement is not greater than the previous, but the lowest + * possible (sorted in ascending order). + */ + function next_permutation>(first: BidirectionalIterator, last: BidirectionalIterator): boolean; + /** + * Transform range to next permutation. + * + * Rearranges the elements in the range [*first*, *last*) into the next *lexicographically greater* permutation. + * + * A permutation is each one of the *N!* possible arrangements the elements can take (where *N* is the number of + * elements in the range). Different permutations can be ordered according to how they compare + * {@link lexicographicaly lexicographical_compare} to each other; The first such-sorted possible permutation (the one + * that would compare *lexicographically smaller* to all other permutations) is the one which has all its elements + * sorted in ascending order, and the largest has all its elements sorted in descending order. + * + * The comparisons of individual elements are performed using the *compare*. + * + * If the function can determine the next higher permutation, it rearranges the elements as such and returns true. If + * that was not possible (because it is already at the largest possible permutation), it rearranges the elements + * according to the first permutation (sorted in ascending order) and returns false. + * + * @param first Bidirectional iterators to the initial positions of the sequence + * @param last Bidirectional iterators to the final positions of the sequence. The range used is [*first*, *last*), + * which contains all the elements between *first* and *last*, including the element pointed by *first* + * but not the element pointed by *last*. + * @param compare Binary function that accepts two arguments of the type pointed by BidirectionalIterator, and returns + * a value convertible to bool. The value returned indicates whether the first argument is considered + * to go before the second in the specific strict weak ordering it defines. + * + * @return true if the function could rearrange the object as a lexicographicaly greater permutation. Otherwise, the + * function returns false to indicate that the arrangement is not greater than the previous, but the lowest + * possible (sorted in ascending order). + */ + function next_permutation>(first: BidirectionalIterator, last: BidirectionalIterator, compare: (x: T, y: T) => boolean): boolean; +} +declare namespace std.base { + /** + * An abstract container. + * + * + * + * + * + * ### Container properties + *
+ *
Sequence
+ *
Elements in sequence containers are ordered in a strict linear sequence. Individual elements are + * accessed by their position in this sequence.
+ * + *
Doubly-linked list
+ *
Each element keeps information on how to locate the next and the previous elements, allowing + * constant time insert and erase operations before or after a specific element (even of entire ranges), + * but no direct random access.
+ *
+ * + * @param Type of elements. + * + * @author Jeongho Nam + */ + abstract class Container { + /** + * Default Constructor. + */ + protected constructor(); + /** + * Assign new content to content. + * + * Assigns new contents to the container, replacing its current contents, and modifying its + * {@link size} accordingly. + * + * @param begin Input interator of the initial position in a sequence. + * @param end Input interator of the final position in a sequence. + */ + abstract assign>(begin: InputIterator, end: InputIterator): void; + /** + * Clear content. + * + * Removes all elements from the Container, leaving the container with a size of 0. + */ + clear(): void; + /** + * Return iterator to beginning. + * + * Returns an iterator referring the first element in the + * + * #### Note + * If the container is {@link empty}, the returned iterator is same with {@link end end()}. + * + * @return An iterator to the first element in the The iterator containes the first element's value. + */ + abstract begin(): Iterator; + /** + * Return iterator to end. + * Returns an iterator referring to the past-the-end element in the + * + * The past-the-end element is the theoretical element that would follow the last element in the + * It does not point to any element, and thus shall not be dereferenced. + * + * Because the ranges used by functions of the Container do not include the element reference by their + * closing iterator, this function is often used in combination with {@link Container}.{@link begin} to + * specify a range including all the elements in the container. + * + * #### Note + * Returned iterator from {@link Container}.{@link end} does not refer any element. Trying to accessing + * element by the iterator will cause throwing exception ({@link OutOfRange}). + * + * If the container is {@link empty}, this function returns the same as {@link Container}.{@link begin}. + * + * + * @return An iterator to the end element in the + */ + abstract end(): Iterator; + /** + * Return {@link ReverseIterator reverse iterator} to reverse beginning. + * + * Returns a {@link ReverseIterator reverse iterator} pointing to the last element in the container (i.e., + * its reverse beginning). + * + * {@link ReverseIterator reverse iterators} iterate backwards: increasing them moves them towards the + * beginning of the + * + * {@link rbegin} points to the element right before the one that would be pointed to by member {@link end}. + * + * + * @return A {@link ReverseIterator reverse iterator} to the reverse beginning of the sequence + */ + abstract rbegin(): IReverseIterator; + /** + * Return {@link ReverseIterator reverse iterator} to reverse end. + * + * Returns a {@link ReverseIterator reverse iterator} pointing to the theoretical element preceding the + * first element in the container (which is considered its reverse end). + * + * The range between {@link Container}.{@link rbegin} and {@link Container}.{@link rend} contains all + * the elements of the container (in reverse order). + * + * @return A {@link ReverseIterator reverse iterator} to the reverse end of the sequence + */ + abstract rend(): IReverseIterator; + /** + * Return the number of elements in the {@link Container}. + * + * @return The number of elements in the container. + */ + abstract size(): number; + /** + * Test whether the container is empty. + * Returns whether the container is empty (i.e. whether its size is 0). + * + * This function does not modify the container in any way. To clear the content of the container, + * see {@link clear clear()}. + * + * @return true if the container size is 0, false otherwise. + */ + empty(): boolean; + /** + * Insert elements. + * + * Appends new elements to the container, and returns the new size of the + * + * @param items New elements to insert. + * + * @return New size of the Container. + */ + abstract push(...items: T[]): number; + /** + * Insert an element. + * + * The container is extended by inserting a new element before the element at the specified + * position. This effectively increases the {@link Container.size container size} by the amount of + * elements inserted. + * + * @param position Position in the {@link Container} where the new element is inserted. + * {@link iterator} is a member type, defined as a {@link Iterator random access iterator} + * type that points to elements. + * @param val Value to be copied to the inserted element. + * + * @re + public abstract insert(position: Iterator, val: T): Iterator; + + /* --------------------------------------------------------- + ERASE + --------------------------------------------------------- */ + /** + * Erase an element. + * + * Removes from the container a single element. + * + * This effectively reduces the container size by the number of element removed. + * + * @param position Iterator pointing to a single element to be removed from the Container. + * + * @return An iterator pointing to the element that followed the last element erased by the function + * call. This is the {@link end Container.end} if the operation erased the last element in the + * sequence. + */ + abstract erase(position: Iterator): Iterator; + /** + * Erase elements. + * + * Removes from the container a range of elements. + * + * This effectively reduces the container size by the number of elements removed. + * + * @param begin An iterator specifying a range of beginning to erase. + * @param end An iterator specifying a range of end to erase. + * + * @return An iterator pointing to the element that followed the last element erased by the function + * call. This is the {@link end Container.end} if the operation erased the last element in + * the sequence. + */ + abstract erase(begin: Iterator, end: Iterator): Iterator; + /** + * Swap content. + * + * Exchanges the content of the container by the content of obj, which is another + * {@link Container container} object with same type of elements. Sizes and container type may differ. + * + * After the call to this member function, the elements in this container are those which were in obj + * before the call, and the elements of obj are those which were in this. All iterators, references and + * pointers remain valid for the swapped objects. + * + * Notice that a non-member function exists with the same name, {@link swap swap}, overloading that + * algorithm with an optimization that behaves like this member function. + * + * @param obj Another {@link Container container} of the same type of elements (i.e., instantiated + * with the same template parameter, T) whose content is swapped with that of this + * {@link Container container}. + */ + swap(obj: Container): void; + } + interface IReverseIterator extends ReverseIterator, Iterator, IReverseIterator> { + } +} +declare namespace std { + /** + * Bi-directional iterator. + * + * {@link Iterator Bidirectional iterators} are iterators that can be used to access the sequence of elements + * in a range in both directions (towards the end and towards the beginning). + * + * All {@link IArrayIterator random-access iterators} are also valid {@link Iterrator bidirectional iterators}. + * + * There is not a single type of {@link Iterator bidirectional iterator}: {@link Container Each container} + * may define its own specific iterator type able to iterate through it and access its elements. + * + * + * + * + * @reference http://www.cplusplus.com/reference/iterator/BidirectionalIterator + * @author Jeongho Nam + */ + abstract class Iterator { + /** + * @hidden + */ + protected source_: base.Container; + /** + * Construct from the source {@link Container container}. + * + * @param source The source container. + */ + protected constructor(source: base.Container); + /** + * Get iterator to previous element. + * + * If current iterator is the first item(equal with {@link Container.begin Container.begin()}), + * returns {@link Container.end Container.end()}. + * + * @return An iterator of the previous item. + */ + abstract prev(): Iterator; + /** + * Get iterator to next element. + * + * If current iterator is the last item, returns {@link Container.end Container.end()}. + * + * @return An iterator of the next item. + */ + abstract next(): Iterator; + /** + * Advances the {@link Iterator} by n element positions. + * + * @param n Number of element positions to advance. + * @return An advanced iterator. + */ + abstract advance(n: number): Iterator; + /** + * Get source container. + * + * Get source container of this iterator is directing for. + */ + abstract source(): base.Container; + /** + * Whether an iterator is equal with the iterator. + * + * Compare two iterators and returns whether they are equal or not. + * + * #### Note + * Iterator's {@link equals equals()} only compare souce container and index number. + * + * Although elements in a pair, key and value are {@link equal_to equal_to}, if the source map or + * index number is different, then the {@link equals equals()} will return false. If you want to + * compare the elements of a pair, compare them directly by yourself. + * + * @param obj An iterator to compare + * @return Indicates whether equal or not. + */ + equals(obj: Iterator): boolean; + /** + * Get value of the iterator is pointing. + * + * @return A value of the iterator. + */ + readonly abstract value: T; + abstract swap(obj: Iterator): void; + } +} +declare namespace std { + /** + * This class reverses the direction in which a bidirectional or random-access iterator iterates through a range. + * + * A copy of the original iterator (the {@link Iterator base iterator}) is kept internally and used to reflect + * the operations performed on the {@link ReverseIterator}: whenever the {@link ReverseIterator} is incremented, its + * {@link Iterator base iterator} is decreased, and vice versa. A copy of the {@link Iterator base iterator} with the + * current state can be obtained at any time by calling member {@link base}. + * + * Notice however that when an iterator is reversed, the reversed version does not point to the same element in + * the range, but to the one preceding it. This is so, in order to arrange for the past-the-end element of a + * range: An iterator pointing to a past-the-end element in a range, when reversed, is pointing to the last element + * (not past it) of the range (this would be the first element of the reversed range). And if an iterator to the + * first element in a range is reversed, the reversed iterator points to the element before the first element (this + * would be the past-the-end element of the reversed range). + * + * + * + * + * @reference http://www.cplusplus.com/reference/iterator/reverse_iterator + * @author Jeongho Nam + */ + abstract class ReverseIterator, Base extends Iterator, This extends ReverseIterator> extends Iterator { + /** + * @hidden + */ + protected base_: Base; + /** + * Construct from base iterator. + * + * @param base A reference of the base iterator, which iterates in the opposite direction. + */ + protected constructor(base: Base); + /** + * @hidden + */ + protected abstract _Create_neighbor(base: Base): This; + source(): Source; + /** + * Return base iterator. + * + * Return a reference of the base iteraotr. + * + * The base iterator is an iterator of the same type as the one used to construct the {@link ReverseIterator}, + * but pointing to the element next to the one the {@link ReverseIterator} is currently pointing to + * (a {@link ReverseIterator} has always an offset of -1 with respect to its base iterator). + * + * @return A reference of the base iterator, which iterates in the opposite direction. + */ + base(): Base; + /** + * Get value of the iterator is pointing. + * + * @return A value of the reverse iterator. + */ + readonly value: T; + /** + * @inheritdoc + */ + prev(): This; + /** + * @inheritdoc + */ + next(): This; + /** + * @inheritdoc + */ + advance(n: number): This; + /** + * @inheritdoc + */ + equals(obj: This): boolean; + /** + * @inheritdoc + */ + swap(obj: This): void; + } + /** + * Return the number of elements in the {@link Container}. + * + * @param container A container with a size method. + * @return The number of elements in the container. + */ + function size(container: base.Container): number; + /** + * Test whether the container is empty. + * + * Returns whether the {@link Container} is empty (i.e. whether its {@link size} is 0). + * + * @param container A container with a empty method. + * @return true if the container size is 0, false otherwise. + */ + function empty(container: base.Container): boolean; + /** + * Return distance between {@link Iterator iterators}. + * + * Calculates the number of elements between first and last. + * + * If it is a {@link IArrayIterator random-access iterator}, the function uses operator- to calculate this. + * Otherwise, the function uses the increase operator {@link Iterator.next next()} repeatedly. + * + * @param first Iterator pointing to the initial element. + * @param last Iterator pointing to the final element. This must be reachable from first. + * + * @return The number of elements between first and last. + */ + function distance>(first: InputIterator, last: InputIterator): number; + /** + * Advance iterator. + * + * Advances the iterator it by n elements positions. + * + * @param it Iterator to be advanced. + * @param n Number of element positions to advance. + * + * @return An iterator to the element n positions before it. + */ + function advance>(it: InputIterator, n: number): InputIterator; + /** + * Get iterator to previous element. + * + * Returns an iterator pointing to the element that it would be pointing to if advanced -n positions. + * + * @param it Iterator to base position. + * @param n Number of element positions offset (1 by default). + * + * @return An iterator to the element n positions before it. + */ + function prev>(it: BidirectionalIterator, n?: number): BidirectionalIterator; + /** + * Get iterator to next element. + * + * Returns an iterator pointing to the element that it would be pointing to if advanced n positions. + * + * @param it Iterator to base position. + * @param n Number of element positions offset (1 by default). + * + * @return An iterator to the element n positions away from it. + */ + function next>(it: ForwardIterator, n?: number): ForwardIterator; + /** + * Iterator to beginning. + * + * Returns an iterator pointing to the first element in the sequence. + * + * If the sequence is {@link empty}, the returned value shall not be dereferenced. + * + * @param container A container object of a class type for which member {@link begin} is defined. + * @return The same as returned by {@link begin begin()}. + */ + function begin(container: base.Container): Iterator; + function begin(container: Vector): VectorIterator; + function begin(container: List): ListIterator; + function begin(container: Deque): DequeIterator; + function begin(container: base.SetContainer): SetIterator; + function begin(container: base.MapContainer): MapIterator; + /** + * Iterator to reverse-beginning. + * + * Returns a reverse iterator pointing to the last element in the sequence. + * + * If the sequence is {@link empty}, the returned value shall not be dereferenced. + * + * @param container A container object of a class type for which member {@link rbegin} is defined. + * @return The same as returned by {@link rbegin()}. + */ + function rbegin(container: base.Container): base.IReverseIterator; + function rbegin(container: Vector): VectorReverseIterator; + function rbegin(container: List): ListReverseIterator; + function rbegin(container: Deque): DequeReverseIterator; + function rbegin(container: base.SetContainer): SetReverseIterator; + function rbegin(container: base.MapContainer): MapReverseIterator; + /** + * Iterator to end. + * + * Returns an iterator pointing to the past-the-end element in the sequence. + * + * If the sequence is {@link empty}, the returned value compares equal to the one returned by {@link begin} with the same argument. + * + * @param container A container of a class type for which member {@link end} is defined. + * @return The same as returned by {@link end end()}. + */ + function end(container: base.Container): Iterator; + function end(container: Vector): VectorIterator; + function end(container: List): ListIterator; + function end(container: Deque): DequeIterator; + function end(container: base.SetContainer): SetIterator; + function end(container: base.MapContainer): MapIterator; + /** + * Iterator to end. + * + * Returns an iterator pointing to the past-the-end element in the sequence. + * + * If the sequence is {@link empty}, the returned value compares equal to the one returned by {@link begin} with the same argument. + * + * @param container A container of a class type for which member {@link end} is defined. + * @return The same as returned by {@link end end()}. + */ + function rend(container: base.Container): base.IReverseIterator; + function rend(container: Vector): VectorReverseIterator; + function rend(container: List): ListReverseIterator; + function rend(container: Deque): DequeReverseIterator; + function rend(container: base.SetContainer): SetReverseIterator; + function rend(container: base.MapContainer): MapReverseIterator; + /** + * Make reverse iterator. + * + * @param it A reference of the base iterator, which iterates in the opposite direction. + * @return A {@link ReverseIterator reverse iterator} based on *it*. + */ + function make_reverse_iterator(it: VectorIterator): VectorReverseIterator; + function make_reverse_iterator(it: DequeIterator): DequeReverseIterator; + function make_reverse_iterator(it: ListIterator): ListReverseIterator; + function make_reverse_iterator(it: SetIterator): SetReverseIterator; + function make_reverse_iterator(it: MapIterator): MapReverseIterator; +} +declare namespace std.base { + /** + * @hidden + */ + abstract class _ListContainer> extends Container implements IDequeContainer { + /** + * @hidden + */ + private begin_; + /** + * @hidden + */ + private end_; + /** + * @hidden + */ + private size_; + /** + * Default Constructor. + */ + protected constructor(); + /** + * @hidden + */ + protected abstract _Create_iterator(prev: BidirectionalIterator, next: BidirectionalIterator, val: T): BidirectionalIterator; + /** + * @hidden + */ + protected _Set_begin(it: BidirectionalIterator): void; + /** + * @inheritdoc + */ + assign>(first: InputIterator, last: InputIterator): void; + /** + * @inheritdoc + */ + clear(): void; + /** + * @inheritdoc + */ + begin(): BidirectionalIterator; + /** + * @inheritdoc + */ + end(): BidirectionalIterator; + /** + * @inheritdoc + */ + size(): number; + /** + * @inheritdoc + */ + front(): T; + /** + * @inheritdoc + */ + back(): T; + /** + * @inheritdoc + */ + push_front(val: T): void; + /** + * @inheritdoc + */ + push_back(val: T): void; + /** + * @inheritdoc + */ + pop_front(): void; + /** + * @inheritdoc + */ + pop_back(): void; + /** + * @inheritdoc + */ + push(...items: T[]): number; + /** + * Insert an element. + * + * The container is extended by inserting a new element before the element at the specified + * position. This effectively increases the {@link List.size List size} by the amount of elements + * inserted. + * + * Unlike other standard sequence containers, {@link List} is specifically designed to be efficient + * inserting and removing elements in any position, even in the middle of the sequence. + * + * @param position Position in the container where the new element is inserted. + * {@link iterator}> is a member type, defined as a + * {@link ListIterator bidirectional iterator} type that points to elements. + * @param val Value to be inserted as an element. + * + * @return An iterator that points to the newly inserted element; val. + */ + insert(position: BidirectionalIterator, val: T): BidirectionalIterator; + /** + * Insert elements by repeated filling. + * + * The container is extended by inserting a new element before the element at the specified + * position. This effectively increases the {@link List.size List size} by the amount of elements + * inserted. + * + * Unlike other standard sequence containers, {@link List} is specifically designed to be efficient + * inserting and removing elements in any position, even in the middle of the sequence. + * + * @param position Position in the container where the new elements are inserted. The {@link iterator} is a + * member type, defined as a {@link ListIterator bidirectional iterator} type that points to + * elements. + * @param size Number of elements to insert. + * @param val Value to be inserted as an element. + * + * @return An iterator that points to the first of the newly inserted elements. + */ + insert(position: BidirectionalIterator, size: number, val: T): BidirectionalIterator; + /** + * Insert elements by range iterators. + * + * The container is extended by inserting a new element before the element at the specified + * position. This effectively increases the {@link List.size List size} by the amount of elements + * inserted. + * + * Unlike other standard sequence containers, {@link List} is specifically designed to be efficient + * inserting and removing elements in any position, even in the middle of the sequence. + * + * @param position Position in the container where the new elements are inserted. The {@link iterator} is a + * member type, defined as a {@link ListIterator bidirectional iterator} type that points to + * elements. + * @param begin An iterator specifying range of the begining element. + * @param end An iterator specifying range of the ending element. + * + * @return An iterator that points to the first of the newly inserted elements. + */ + insert>(position: BidirectionalIterator, begin: InputIterator, end: InputIterator): BidirectionalIterator; + /** + * @hidden + */ + private _Insert_by_repeating_val(position, n, val); + /** + * @hidden + */ + protected _Insert_by_range>(position: BidirectionalIterator, begin: InputIterator, end: InputIterator): BidirectionalIterator; + /** + * Erase an element. + * + * Removes from the {@link List} either a single element; position. + * + * This effectively reduces the container size by the number of element removed. + * + * Unlike other standard sequence containers, {@link List} objects are specifically designed to be + * efficient inserting and removing elements in any position, even in the middle of the sequence. + * + * @param position Iterator pointing to a single element to be removed from the {@link List}. + * + * @return An iterator pointing to the element that followed the last element erased by the function call. + * This is the {@link end end()} if the operation erased the last element in the sequence. + */ + erase(position: BidirectionalIterator): BidirectionalIterator; + /** + * Erase elements. + * + * Removes from the {@link List} container a range of elements. + * + * This effectively reduces the container {@link size} by the number of elements removed. + * + * Unlike other standard sequence containers, {@link List} objects are specifically designed to be + * efficient inserting and removing elements in any position, even in the middle of the sequence. + * + * @param begin An iterator specifying a range of beginning to erase. + * @param end An iterator specifying a range of end to erase. + * + * @return An iterator pointing to the element that followed the last element erased by the function call. + * This is the {@link end end()} if the operation erased the last element in the sequence. + */ + erase(begin: BidirectionalIterator, end: BidirectionalIterator): BidirectionalIterator; + /** + * @hidden + */ + protected _Erase_by_range(first: BidirectionalIterator, last: BidirectionalIterator): BidirectionalIterator; + /** + * Swap content. + * + * Exchanges the content of the container by the content of obj, which is another + * {@link List container} object with same type of elements. Sizes and container type may differ. + * + * After the call to this member function, the elements in this container are those which were in obj + * before the call, and the elements of obj are those which were in this. All iterators, references and + * pointers remain valid for the swapped objects. + * + * Notice that a non-member function exists with the same name, {@link swap swap}, overloading that + * algorithm with an optimization that behaves like this member function. + * + * @param obj Another {@link List container} of the same type of elements (i.e., instantiated + * with the same template parameter, T) whose content is swapped with that of this + * {@link List container}. + */ + swap(obj: _ListContainer): void; + /** + * @inheritdoc + */ + swap(obj: Container): void; + } +} +declare namespace std.base { + /** + * @hidden + */ + abstract class _ListIteratorBase extends Iterator { + /** + * @hidden + */ + protected prev_: _ListIteratorBase; + /** + * @hidden + */ + protected next_: _ListIteratorBase; + /** + * @hidden + */ + protected value_: T; + /** + * Initializer Constructor. + * + * @param source The source {@link Container} to reference. + * @param prev A refenrece of previous node ({@link ListIterator iterator}). + * @param next A refenrece of next node ({@link ListIterator iterator}). + * @param value Value to be stored in the node (iterator). + */ + protected constructor(source: Container, prev: _ListIteratorBase, next: _ListIteratorBase, value: T); + /** + * @inheritdoc + */ + prev(): _ListIteratorBase; + /** + * @inheritdoc + */ + next(): _ListIteratorBase; + /** + * @inheritdoc + */ + advance(step: number): _ListIteratorBase; + /** + * @inheritdoc + */ + readonly value: T; + /** + * @inheritdoc + */ + equals(obj: _ListIteratorBase): boolean; + /** + * @inheritdoc + */ + swap(obj: _ListIteratorBase): void; + } +} +declare namespace std.base { + /** + * An abstract error instance. + * + * {@link ErrorInstance} is an abstract class of {@link ErrorCode} and {@link ErrorCondition} + * holding an error instance's identifier {@link value}, associated with a {@link category}. + * + * The operating system and other low-level applications and libraries generate numerical error codes to + * represent possible results. These numerical values may carry essential information for a specific platform, + * but be non-portable from one platform to another. + * + * Objects of this class associate such numerical codes to {@link ErrorCategory error categories}, + * so that they can be interpreted when needed as more abstract (and portable) + * {@link ErrorCondition error conditions}. + * + * + * + * + * @author Jeongho Nam + */ + abstract class ErrorInstance { + /** + * @hidden + */ + protected category_: ErrorCategory; + /** + * @hidden + */ + protected value_: number; + /** + * Default Constructor. + */ + constructor(); + /** + * Construct from a numeric value and error category. + * + * @param val A numerical value identifying an error instance. + * @param category A reference to an {@link ErrorCategory} object. + */ + constructor(val: number, category: ErrorCategory); + /** + * Assign error instance. + * + * Assigns the {@link ErrorCode} object a value of val associated with the {@link ErrorCategory}. + * + * @param val A numerical value identifying an error instance. + * @param category A reference to an {@link ErrorCategory} object. + */ + assign(val: number, category: ErrorCategory): void; + /** + * Clear error instance. + * + * Clears the value in the {@link ErrorCode} object so that it is set to a value of 0 of the + * {@link ErrorCategory.systemCategory ErrorCategory.systemCategory()} (indicating no error). + */ + clear(): void; + /** + * Get category. + * + * Returns a reference to the {@link ErrorCategory} associated with the {@link ErrorCode} object. + * + * @return A reference to a non-copyable object of a type derived from {@link ErrorCategory}. + */ + category(): ErrorCategory; + /** + * Error value. + * + * Returns the error value associated with the {@link ErrorCode} object. + * + * @return The error value. + */ + value(): number; + /** + * Get message. + * + * Returns the message associated with the error instance. + * + * Error messages are defined by the {@link category} the error instance belongs to. + * + * This function returns the same as if the following member was called: + * + * category().message(value()) + * + * @return A string object with the message associated with the {@link ErrorCode}. + */ + message(): string; + /** + * Default error condition. + * + * Returns the default {@link ErrorCondition}object associated with the {@link ErrorCode} object. + * + * This function returns the same as if the following member was called: + * + * category().default_error_condition(value()) + * + * {@link ErrorCategory.default_error_condition ErrorCategory.default_error_condition()} + * is a virtual member function, that can operate differently for each category. + * + * @return An {@link ErrorCondition}object that corresponds to the {@link ErrorCode} object. + */ + default_error_condition(): ErrorCondition; + /** + * Convert to bool. + * + * Returns whether the error instance has a numerical {@link value} other than 0. + * + * If it is zero (which is generally used to represent no error), the function returns false, otherwise it returns true. + * + * @return true if the error's numerical value is not zero. + * false otherwise. + */ + to_bool(): boolean; + } +} +declare namespace std.base { + /** + * @hidden + */ + enum _Hash { + MIN_SIZE = 10, + RATIO = 1, + MAX_RATIO = 2, + } + /** + * @hidden + */ + abstract class _HashBuckets { + private buckets_; + private item_size_; + protected constructor(); + rehash(size: number): void; + clear(): void; + size(): number; + item_size(): number; + capacity(): number; + at(index: number): Vector; + hash_index(val: T): number; + insert(val: T): void; + erase(val: T): void; + } +} +declare namespace std.base { + /** + * @hidden + */ + class _MapHashBuckets extends _HashBuckets> { + private map_; + constructor(map: IHashMap); + find(key: K): MapIterator; + } +} +declare namespace std.base { + /** + * @hidden + */ + class _SetHashBuckets extends _HashBuckets> { + private set_; + constructor(set: IHashSet); + find(val: T): SetIterator; + } +} +declare namespace std.base { + /** + * Array Container. + * + * {@link IArrayContainer} is an interface for sequence containers representing arrays that can change in + * {@link size}. However, compared to arrays, {@link IArrayContainer} objectss consume more memory in exchange for + * the ability to manage storage and grow dynamically in an efficient way. + * + * Both {@link Vector Vectors} and {@link Deque Deques} who implemented {@link IArrayContainer} provide a very + * similar interface and can be used for similar purposes, but internally both work in quite different ways: + * While {@link Vector Vectors} use a single array that needs to be occasionally reallocated for growth, the + * elements of a {@link Deque} can be scattered in different chunks of storage, with the container keeping the + * necessary information internally to provide direct access to any of its elements in constant time and with a + * uniform sequential interface (through iterators). Therefore, {@link Deque Deques} are a little more complex + * internally than {@link Vector Vectors}, but this allows them to grow more efficiently under certain + * circumstances, especially with very long sequences, where reallocations become more expensive. + * + * Both {@link Vector Vectors} and {@link Deque Deques} provide a very similar interface and can be used for + * similar purposes, but internally both work in quite different ways: While {@link Vector Vectors} use a single + * array that needs to be occasionally reallocated for growth, the elements of a {@link Deque} can be scattered + * in different chunks of storage, with the container keeping the necessary information internally to provide + * direct access to any of its elements in constant time and with a uniform sequential interface (through + * iterators). Therefore, {@link Deque Deques} are a little more complex internally than {@link Vector Vectors}, + * but this allows them to grow more efficiently under certain circumstances, especially with very long + * sequences, where reallocations become more expensive. + * + * For operations that involve frequent insertion or removals of elements at positions other than the + * beginning or the end, {@link IArrayContainer} objects perform worse and have less consistent iterators and references + * than {@link List Lists}. + * + * + * + * + * + * ### Container properties + *
+ *
Sequence
+ *
+ * Elements in sequence containers are ordered in a strict linear sequence. Individual elements are + * accessed by their position in this sequence. + *
+ * + *
Dynamic array
+ *
+ * Allows direct access to any element in the sequence, even through pointer arithmetics, and provides + * relatively fast addition/removal of elements at the end of the sequence. + *
+ *
+ * + * @param Type of the elements. + * + * @author Jeongho Nam + */ + interface IArrayContainer extends ILinearContainer { + /** + * Access element. + * Returns a value to the element at position index in the {@link IArrayContainer container}.

+ * + * The function automatically checks whether index is within the bounds of valid elements + * in the {@link IArrayContainer container}, throwing an {@link OutOfRange} exception if it is not (i.e., + * if index is greater or equal than its {@link size}). + * + * @param index Position of an element in the + * If this is greater than or equal to the {@link IArrayContainer container} {@link size}, an + * exception of type {@link OutOfRange} is thrown. Notice that the first + * element has a position of 0 (not 1). + * + * @return The element at the specified position in the + */ + at(index: number): T; + /** + * Modify element. + * Replaces an element at the specified position (index) in this {@link IArrayContainer container} + * with the specified element (val). + * + * The function automatically checks whether index is within the bounds of valid elements + * in the {@link IArrayContainer container}, throwing an {@link OutOfRange} exception if it is not (i.e., if + * index is greater or equal than its {@link size}). + * + * @.param index A specified position of the value to replace. + * @param val A value to be stored at the specified position. + * + * @return The previous element had stored at the specified position. + */ + set(index: number, val: T): void; + } + /** + * Random-access iterator. + * + * {@link IArrayIterator Random-access iterators} are iterators that can be used to access elements at an + * arbitrary offset position relative to the element they point to, offering the same functionality as pointers. + * + * {@link IArrayIterator Random-access iterators} are the most complete iterators in terms of functionality. + * All pointer types are also valid {@link IArrayIterator random-access iterators}. + * + * There is not a single type of {@link IArrayIterator random-access iterator}: Each container may define its + * own specific iterator type able to iterate through it and access its elements. + * + * + * + * + * + * @reference http://www.cplusplus.com/reference/iterator/RandomAccessIterator + * @author Jeongho Nam + */ + interface IArrayIterator extends ILinearIterator { + /** + * @inheritdoc + */ + source(): IArrayContainer; + /** + * Get index, sequence number of the iterator in the source {@link IArrayContainer array}. + * + * @return Sequence number of the iterator in the source {@link IArrayContainer array}. + */ + index(): number; + /** + * @inheritdoc + */ + prev(): IArrayIterator; + /** + * @inheritdoc + */ + next(): IArrayIterator; + } +} +declare namespace std.base { + /** + * An interface for deque + * + * + * + * + * + * @author Jeongho Nam + */ + interface IDequeContainer extends ILinearContainer { + /** + * Insert element at beginning. + * + * Inserts a new element at the beginning of the {@link IDeque container}, right before its + * current first element. This effectively increases the {@link IDeque container} {@link size} by + * one. + * + * @param val Value to be inserted as an element. + */ + push_front(val: T): void; + /** + * Delete first element. + * + * Removes the first element in the {@link IDeque container}, effectively reducing its + * {@link size} by one. + */ + pop_front(): void; + } +} +declare namespace std.base { + /** + * Common interface for hash map. + * + * {@link IHashMap}s are associative containers that store elements formed by the combination of + * a key value and a mapped value. + * + * In an {@link IHashMap}, the key value is generally used to uniquely identify the + * element, while the mapped value is an object with the content associated to this key. + * Types of key and mapped value may differ. + * + * Internally, the elements in the {@link IHashMap} are not sorted in any particular order with + * respect to either their key or mapped values, but organized into buckets depending on + * their hash values to allow for fast access to individual elements directly by their key values + * (with a constant average time complexity on average). + * + * Elements with equivalent keys are grouped together in the same bucket and in such a way that + * an iterator can iterate through all of them. Iterators in the container are doubly linked iterators. + * + * + * + * + * + * ### Container properties + *
+ *
Associative
+ *
Elements in associative containers are referenced by their key and not by their absolute + * position in the container.
+ * + *
Hashed
+ *
Hashed containers organize their elements using hash tables that allow for fast access to elements + * by their key.
+ * + *
Map
+ *
Each element associates a key to a mapped value: + * Keys are meant to identify the elements whose main content is the mapped value.
+ *
+ * + * @param Type of the key values. + * Each element in an {@link IHashMap} is identified by a key value. + * @param Type of the mapped value. + * Each element in an {@link IHashMap} is used to store some data as its mapped value. + * + * @reference http://www.cplusplus.com/reference/unordered_map + * @author Jeongho Nam + */ + interface IHashMap extends MapContainer { + /** + * Return number of buckets. + * + * Returns the number of buckets in the {@link IHashMap} container. + * + * A bucket is a slot in the container's internal hash table to which elements are assigned based on the + * hash value of their key. + * + * The number of buckets influences directly the {@link load_factor load factor} of the container's hash + * table (and thus the probability of collision). The container automatically increases the number of buckets to + * keep the load factor below a specific threshold (its {@link max_load_factor}), causing a {@link rehash} each + * time the number of buckets needs to be increased. + * + * @return The current amount of buckets. + */ + bucket_count(): number; + /** + * Return bucket size. + * + * Returns the number of elements in bucket n. + * + * A bucket is a slot in the container's internal hash table to which elements are assigned based on the hash + * value of their key. + * + * The number of elements in a bucket influences the time it takes to access a particular element in the + * bucket. The container automatically increases the number of buckets to keep the {@link load_cator load factor} + * (which is the average bucket size) below its {@link max_load_factor}. + * + * @param n Bucket number. This shall be lower than {@link bucket_count}. + * + * @return The number of elements in bucket n. + */ + bucket_size(n: number): number; + /** + * Get maximum load factor. + * + * Returns the current maximum load factor for the {@link HashMultiMap} container. + * + * The load factor is the ratio between the number of elements in the container (its {@link size}) and the + * number of buckets ({@link bucket_count}). + * + * By default, {@link HashMultiMap} containers have a {@link max_load_factor} of 1.0. + * + * The load factor influences the probability of collision in the hash table (i.e., the probability of two + * elements being located in the same bucket). The container uses the value of max_load_factor as the threshold + * that forces an increase in the number of buckets (and thus causing a {@link rehash}). + * + * Note though, that implementations may impose an upper limit on the number of buckets (see + * {@link max_bucket_count}), which may force the container to ignore the {@link max_load_factor}. + * + * @return The current load factor. + */ + max_load_factor(): number; + /** + * Set maximum load factor. + * + * Sets z as the cnew maximum load factor for the {@link HashMultiMap} container. + * + * The load factor is the ratio between the number of elements in the container (its {@link size}) and the + * number of buckets ({@link bucket_count}). + * + * By default, {@link HashMultiMap} containers have a {@link max_load_factor} of 1.0. + * + * The load factor influences the probability of collision in the hash table (i.e., the probability of two + * elements being located in the same bucket). The container uses the value of max_load_factor as the threshold + * that forces an increase in the number of buckets (and thus causing a {@link rehash}). + * + * Note though, that implementations may impose an upper limit on the number of buckets (see + * {@link max_bucket_count}), which may force the container to ignore the {@link max_load_factor}. + * + * @param z The new maximum load factor. + */ + max_load_factor(z: number): void; + /** + * Locate element's bucket. + * + * Returns the bucket number where the element with key is located. + * + * A bucket is a slot in the container's internal hash table to which elements are assigned based on the + * hash value of their key. Buckets are numbered from 0 to ({@link bucket_count} - 1). + * + * Individual elements in a bucket can be accessed by means of the range iterators returned by + * {@link begin} and {@link end}. + * + * @param key Key whose bucket is to be located. + */ + bucket(key: Key): number; + /** + * Request a capacity change. + * + * Sets the number of buckets in the container ({@link bucket_count}) to the most appropriate to contain at + * least n elements. + * + * If n is greater than the current {@link bucket_count} multiplied by the {@link max_load_factor}, + * the container's {@link bucket_count} is increased and a {@link rehash} is forced. + * + * If n is lower than that, the function may have no effect. + * + * @param n The number of elements requested as minimum capacity. + */ + reserve(n: number): void; + /** + * Set number of buckets. + * + * Sets the number of buckets in the container to n or more. + * + * If n is greater than the current number of buckets in the container ({@link bucket_count}), a + * {@link HashBuckets.rehash rehash} is forced. The new {@link bucket_count bucket count} can either be equal or + * greater than n. + * + * If n is lower than the current number of buckets in the container ({@link bucket_count}), the + * function may have no effect on the {@link bucket_count bucket count} and may not force a + * {@link HashBuckets.rehash rehash}. + * + * A {@link HashBuckets.rehash rehash} is the reconstruction of the hash table: All the elements in the + * container are rearranged according to their hash value into the new set of buckets. This may alter the order + * of iteration of elements within the container. + * + * {@link HashBuckets.rehash Rehashes} are automatically performed by the container whenever its + * {@link load_factor load factor} is going to surpass its {@link max_load_factor} in an operation. + * + * Notice that this function expects the number of buckets as argument. A similar function exists, + * {@link reserve}, that expects the number of elements in the container as argument. + * + * @param n The minimum number of buckets for the container hash table. + */ + rehash(n: number): void; + } +} +declare namespace std.base { + /** + * A common interface for hash set. + * + * {@link IHashSet}s are containers that store unique elements in no particular order, and which + * allow for fast retrieval of individual elements based on their value. + * + * In an {@link IHashSet}, the value of an element is at the same time its key, that + * identifies it uniquely. Keys are immutable, therefore, the elements in an {@link IHashSet} cannot be + * modified once in the container - they can be inserted and removed, though. + * + * Internally, the elements in the {@link IHashSet} are not sorted in any particular order, but + * organized into buckets depending on their hash values to allow for fast access to individual elements + * directly by their values (with a constant average time complexity on average). + * + * {@link IHashSet} containers are faster than {@link TreeSet} containers to access individual + * elements by their key, although they are generally less efficient for range iteration through a + * subset of their elements. + * + * + * + * + * + * ### Container properties + *
+ *
Associative
+ *
Elements in associative containers are referenced by their key and not by their absolute + * position in the container.
+ * + *
Hashed
+ *
Hashed containers organize their elements using hash tables that allow for fast access to elements + * by their key.
+ * + *
Set
+ *
The value of an element is also the key used to identify it.
+ *
+ * + * @param Type of the elements. + * Each element in an {@link IHashSet} is also uniquely identified by this value. + * + * @reference http://www.cplusplus.com/reference/unordered_set/unordered_set + * @author Jeongho Nam + */ + interface IHashSet extends SetContainer { + /** + * Return number of buckets. + * + * Returns the number of buckets in the {@link IHashSet} container. + * + * A bucket is a slot in the container's internal hash table to which elements are assigned based on the + * hash value of their key. + * + * The number of buckets influences directly the {@link load_factor load factor} of the container's hash + * table (and thus the probability of collision). The container automatically increases the number of buckets to + * keep the load factor below a specific threshold (its {@link max_load_factor}), causing a {@link rehash} each + * time the number of buckets needs to be increased. + * + * @return The current amount of buckets. + */ + bucket_count(): number; + /** + * Return bucket size. + * + * Returns the number of elements in bucket n. + * + * A bucket is a slot in the container's internal hash table to which elements are assigned based on the hash + * value of their key. + * + * The number of elements in a bucket influences the time it takes to access a particular element in the + * bucket. The container automatically increases the number of buckets to keep the {@link load_cator load factor} + * (which is the average bucket size) below its {@link max_load_factor}. + * + * @param n Bucket number. This shall be lower than {@link bucket_count}. + * + * @return The number of elements in bucket n. + */ + bucket_size(n: number): number; + /** + * Get maximum load factor. + * + * Returns the current maximum load factor for the {@link HashMultiMap} container. + * + * The load factor is the ratio between the number of elements in the container (its {@link size}) and the + * number of buckets ({@link bucket_count}). + * + * By default, {@link HashMultiMap} containers have a {@link max_load_factor} of 1.0. + * + * The load factor influences the probability of collision in the hash table (i.e., the probability of two + * elements being located in the same bucket). The container uses the value of max_load_factor as the threshold + * that forces an increase in the number of buckets (and thus causing a {@link rehash}). + * + * Note though, that implementations may impose an upper limit on the number of buckets (see + * {@link max_bucket_count}), which may force the container to ignore the {@link max_load_factor}. + * + * @return The current load factor. + */ + max_load_factor(): number; + /** + * Set maximum load factor. + * + * Sets z as the cnew maximum load factor for the {@link HashMultiMap} container. + * + * The load factor is the ratio between the number of elements in the container (its {@link size}) and the + * number of buckets ({@link bucket_count}). + * + * By default, {@link HashMultiMap} containers have a {@link max_load_factor} of 1.0. + * + * The load factor influences the probability of collision in the hash table (i.e., the probability of two + * elements being located in the same bucket). The container uses the value of max_load_factor as the threshold + * that forces an increase in the number of buckets (and thus causing a {@link rehash}). + * + * Note though, that implementations may impose an upper limit on the number of buckets (see + * {@link max_bucket_count}), which may force the container to ignore the {@link max_load_factor}. + * + * @param z The new maximum load factor. + */ + max_load_factor(z: number): void; + /** + * Locate element's bucket. + * + * Returns the bucket number where the element with key is located. + * + * A bucket is a slot in the container's internal hash table to which elements are assigned based on the + * hash value of their key. Buckets are numbered from 0 to ({@link bucket_count} - 1). + * + * Individual elements in a bucket can be accessed by means of the range iterators returned by + * {@link begin} and {@link end}. + * + * @param key Key whose bucket is to be located. + */ + bucket(key: T): number; + /** + * Request a capacity change. + * + * Sets the number of buckets in the container ({@link bucket_count}) to the most appropriate to contain at + * least n elements. + * + * If n is greater than the current {@link bucket_count} multiplied by the {@link max_load_factor}, + * the container's {@link bucket_count} is increased and a {@link rehash} is forced. + * + * If n is lower than that, the function may have no effect. + * + * @param n The number of elements requested as minimum capacity. + */ + reserve(n: number): void; + /** + * Set number of buckets. + * + * Sets the number of buckets in the container to n or more. + * + * If n is greater than the current number of buckets in the container ({@link bucket_count}), a + * {@link HashBuckets.rehash rehash} is forced. The new {@link bucket_count bucket count} can either be equal or + * greater than n. + * + * If n is lower than the current number of buckets in the container ({@link bucket_count}), the + * function may have no effect on the {@link bucket_count bucket count} and may not force a + * {@link HashBuckets.rehash rehash}. + * + * A {@link HashBuckets.rehash rehash} is the reconstruction of the hash table: All the elements in the + * container are rearranged according to their hash value into the new set of buckets. This may alter the order + * of iteration of elements within the container. + * + * {@link HashBuckets.rehash Rehashes} are automatically performed by the container whenever its + * {@link load_factor load factor} is going to surpass its {@link max_load_factor} in an operation. + * + * Notice that this function expects the number of buckets as argument. A similar function exists, + * {@link reserve}, that expects the number of elements in the container as argument. + * + * @param n The minimum number of buckets for the container hash table. + */ + rehash(n: number): void; + } +} +declare namespace std.base { + /** + * An interface for linear containers. + * + * + * + * + * + * @author Jeonngho Nam + */ + interface ILinearContainer extends Container { + /** + * @inheritdoc + */ + assign>(begin: InputIterator, end: InputIterator): void; + /** + * Assign container content. + * + * Assigns new contents to the {@link IList container}, replacing its current contents, + * and modifying its {@link size} accordingly. + * + * @param n New size for the + * @param val Value to fill the container with. Each of the n elements in the container will + * be initialized to a copy of this value. + */ + assign(n: number, val: T): void; + /** + * Access first element. + * Returns a value of the first element in the {@link IList container}. + * + * Unlike member {@link end end()}, which returns an iterator just past this element, + * this function returns a direct value. + * + * Calling this function on an {@link empty} {@link IList container} causes undefined behavior. + * + * @return A value of the first element of the {@link IList container}. + */ + front(): T; + /** + * Access last element. + * Returns a value of the last element in the {@link IList container}. + * + * Unlike member {@link end end()}, which returns an iterator just past this element, + * this function returns a direct value. + * + * Calling this function on an {@link empty} {@link IList container} causes undefined behavior. + * + * @return A value of the last element of the {@link IList container}. + */ + back(): T; + /** + * Add element at the end. + * + * Adds a new element at the end of the {@link IList container}, after its current last element. + * This effectively increases the {@link IList container} {@link size} by one. + * + * @param val Value to be copied to the new element. + */ + push_back(val: T): void; + /** + * Delete last element. + * + * Removes the last element in the {@link IList container}, effectively reducing the + * {@link IList container} {@link size} by one. + */ + pop_back(): void; + /** + * Insert an element. + * + * The {@link IList conatiner} is extended by inserting new element before the element at the + * specified position, effectively increasing the {@link IList container} {@link size} by + * one. + * + * @param position Position in the {@link IList container} where the new elements are inserted. + * {@link iterator} is a member type, defined as a {@link iterator random access iterator} + * type that points to elements. + * @param val Value to be copied to the inserted element. + * + * @return An iterator that points to the newly inserted element. + */ + insert(position: Iterator, val: T): Iterator; + /** + * Insert elements by range iterators. + * + * The {@link IList container} is extended by inserting new elements before the element at the + * specified position, effectively increasing the {@link IList container} {@link size} by + * the number of repeating elements
n
. + * + * @param position Position in the {@link IList container} where the new elements are inserted. + * {@link iterator} is a member type, defined as a {@link iterator random access iterator} + * type that points to elements. + * @param n Number of elements to insert. Each element is initialized to a copy of val. + * @param val Value to be copied (or moved) to the inserted elements. + * + * @return An iterator that points to the first of the newly inserted elements. + */ + insert(position: Iterator, n: number, val: T): Iterator; + /** + * Insert elements by range iterators. + * + * The {@link IList container} is extended by inserting new elements before the element at the + * specified position, effectively increasing the {@link IList container} {@link size} by + * the number of elements inserted by range iterators. + * + * @param position Position in the {@link IList container} where the new elements are inserted. + * {@link iterator} is a member type, defined as a {@link iterator random access iterator} + * type that points to elements. + * @param begin Input interator of the initial position in a sequence. + * @param end Input interator of the final position in a sequence. + * + * @return An iterator that points to the first of the newly inserted elements. + */ + insert>(position: Iterator, begin: InputIterator, end: InputIterator): Iterator; + } + /** + * An interface for iterators from linear containers. + * + * {@link ILieanerIterator} is an bi-directional iterator which is created from the related + * {@link ILinearContainer linear containers}. Not only accessing to {@link value} of the pointed element from + * this {@link ILieanerIterator}, but also modifying the {@link value} is possible. + * + * @author Jeongho Nam + */ + interface ILinearIterator extends Iterator { + /** + * @inheritdoc + */ + source(): ILinearContainer; + /** + * @inheritdoc + */ + value: T; + /** + * @inheritdoc + */ + prev(): ILinearIterator; + /** + * @inheritdoc + */ + next(): ILinearIterator; + } +} +declare namespace std.base { + /** + * Common interface for tree-structured map. + * + * {@link ITreeMap ITreeMaps} are associative containers that store elements formed by a combination of + * a key value and a mapped value, following a specific order. + * + * In a {@link ITreeMap}, the key values are generally used to sort and uniquely identify + * the elements, while the mapped values store the content associated to this key. The types of + * key and mapped value may differ, and are grouped together in member type + * value_type, which is a {@link Pair} type combining both: + * + * typedef Pair value_type; + * + * Internally, the elements in a {@link ITreeMap}are always sorted by its key following a + * strict weak ordering criterion indicated by its internal comparison method (of {@link less}). + * + * {@link ITreeMap}containers are generally slower than {@link IHashMap} containers + * to access individual elements by their key, but they allow the direct iteration on subsets based + * on their order. + * + * {@link ITreeMap TreeMultiMaps} are typically implemented as binary search trees. + * + * + * + * + * ### Container properties + *
+ *
Associative
+ *
Elements in associative containers are referenced by their key and not by their absolute + * position in the container.
+ * + *
Ordered
+ *
The elements in the container follow a strict order at all times. All inserted elements are + * given a position in this order.
+ * + *
Map
+ *
Each element associates a key to a mapped value: + * Keys are meant to identify the elements whose main content is the mapped value.
+ *
+ * + * @param Type of the keys. Each element in a map is uniquely identified by its key value. + * @param Type of the mapped value. Each element in a map stores some data as its mapped value. + * + * @reference http://www.cplusplus.com/reference/map + * @author Jeongho Nam + */ + interface ITreeMap extends MapContainer { + /** + * Return key comparison function. + * + * Returns a references of the comparison function used by the container to compare keys. + * + * The comparison object of a {@link ITreeMap tree-map object} is set on + * {@link TreeMap.constructor construction}. Its type (Key) is the last parameter of the + * {@link ITreeMap.constructor constructors}. By default, this is a {@link less} function, which returns the same + * as operator<. + * + * This function determines the order of the elements in the container: it is a function pointer that takes + * two arguments of the same type as the element keys, and returns true if the first argument + * is considered to go before the second in the strict weak ordering it defines, and false otherwise. + * + * + * Two keys are considered equivalent if {@link key_comp} returns false reflexively (i.e., no + * matter the order in which the keys are passed as arguments). + * + * @return The comparison function. + */ + key_comp(): (x: Key, y: Key) => boolean; + /** + * Return value comparison function. + * + * Returns a comparison function that can be used to compare two elements to get whether the key of the first + * one goes before the second. + * + * The arguments taken by this function object are of member type Pair (defined in + * {@link ITreeMap}), but the mapped type (T) part of the value is not taken into consideration in this + * comparison. + * + * This comparison class returns true if the {@link Pair.first key} of the first argument + * is considered to go before that of the second (according to the strict weak ordering specified by the + * container's comparison function, {@link key_comp}), and false otherwise. + * + * @return The comparison function for element values. + */ + value_comp(): (x: Pair, y: Pair) => boolean; + /** + * Return iterator to lower bound. + * + * Returns an iterator pointing to the first element in the container whose key is not considered to + * go before k (i.e., either it is equivalent or goes after). + * + * The function uses its internal comparison object (key_comp) to determine this, returning an + * iterator to the first element for which key_comp(k, element_key) would return false. + * + * If the {@link ITreeMap} class is instantiated with the default comparison type ({@link less}), + * the function returns an iterator to the first element whose key is not less than k. + * + * A similar member function, {@link upper_bound}, has the same behavior as {@link lower_bound}, except + * in the case that the {@link ITreeMap} contains an element with a key equivalent to k: In this + * case, {@link lower_bound} returns an iterator pointing to that element, whereas {@link upper_bound} + * returns an iterator pointing to the next element. + * + * @param k Key to search for. + * + * @return An iterator to the the first element in the container whose key is not considered to go before + * k, or {@link ITreeMap.end} if all keys are considered to go before k. + */ + lower_bound(key: Key): MapIterator; + /** + * Return iterator to upper bound. + * + * Returns an iterator pointing to the first element in the container whose key is considered to + * go after k. + * + * The function uses its internal comparison object (key_comp) to determine this, returning an + * iterator to the first element for which key_comp(k, element_key) would return true. + * + * If the {@link ITreeMap} class is instantiated with the default comparison type ({@link less}), + * the function returns an iterator to the first element whose key is greater than k. + * + * A similar member function, {@link lower_bound}, has the same behavior as {@link upper_bound}, except + * in the case that the map contains an element with a key equivalent to k: In this case + * {@link lower_bound} returns an iterator pointing to that element, whereas {@link upper_bound} returns an + * iterator pointing to the next element. + * + * @param k Key to search for. + * + * @return An iterator to the the first element in the container whose key is considered to go after + * k, or {@link TreeMap.end end} if no keys are considered to go after k. + */ + upper_bound(key: Key): MapIterator; + /** + * Get range of equal elements. + * + * Returns the bounds of a range that includes all the elements in the container which have a key + * equivalent to k. + * + * If no matches are found, the range returned has a length of zero, with both iterators pointing to + * the first element that has a key considered to go after k according to the container's internal + * comparison object (key_comp). + * + * Two keys are considered equivalent if the container's comparison object returns false reflexively + * (i.e., no matter the order in which the keys are passed as arguments). + * + * @param k Key to search for. + * + * @return The function returns a {@link Pair}, whose member {@link Pair.first} is the lower bound of + * the range (the same as {@link lower_bound}), and {@link Pair.second} is the upper bound + * (the same as {@link upper_bound}). + */ + equal_range(key: Key): Pair, MapIterator>; + } +} +declare namespace std.base { + /** + * A common interface for tree-structured set. + * + * {@link ITreeSet TreeMultiSets} are containers that store elements following a specific order. + * + * In a {@link ITreeSet}, the value of an element also identifies it (the value is itself + * the key, of type T). The value of the elements in a {@link ITreeSet} cannot + * be modified once in the container (the elements are always const), but they can be inserted or removed + * from the + * + * Internally, the elements in a {@link ITreeSet TreeMultiSets} are always sorted following a strict + * weak ordering criterion indicated by its internal comparison method (of {@link IComparable.less less}). + * + * {@link ITreeSet} containers are generally slower than {@link IHashSet} containers + * to access individual elements by their key, but they allow the direct iteration on subsets based on + * their order. + * + * {@link ITreeSet TreeMultiSets} are typically implemented as binary search trees. + * + * + * + * + * ### Container properties + *
+ *
Associative
+ *
+ * Elements in associative containers are referenced by their key and not by their absolute + * position in the container. + *
+ * + *
Ordered
+ *
+ * The elements in the container follow a strict order at all times. All inserted elements are + * given a position in this order. + *
+ * + *
Set
+ *
The value of an element is also the key used to identify it.
+ *
+ * + * @param Type of the elements. Each element in a {@link ITreeSet} container is also identified + * by this value (each value is itself also the element's key). + * + * @reference http://www.cplusplus.com/reference/set + * @author Jeongho Nam + */ + interface ITreeSet extends SetContainer { + /** + * Return comparison function. + * + * Returns a copy of the comparison function used by the container. + * + * By default, this is a {@link less} object, which returns the same as operator<. + * + * This object determines the order of the elements in the container: it is a function pointer or a function + * object that takes two arguments of the same type as the container elements, and returns true if + * the first argument is considered to go before the second in the strict weak ordering it + * defines, and false otherwise. + * + * Two elements of a {@link ITreeSet} are considered equivalent if {@link key_comp} returns false + * reflexively (i.e., no matter the order in which the elements are passed as arguments). + * + * In {@link ITreeSet} containers, the keys to sort the elements are the values (T) themselves, + * therefore {@link key_comp} and its sibling member function {@link value_comp} are equivalent. + * + * @return The comparison function. + */ + key_comp(): (x: T, y: T) => boolean; + /** + * Return comparison function. + * + * Returns a copy of the comparison function used by the container. + * + * By default, this is a {@link less} object, which returns the same as operator<. + * + * This object determines the order of the elements in the container: it is a function pointer or a function + * object that takes two arguments of the same type as the container elements, and returns true if + * the first argument is considered to go before the second in the strict weak ordering it + * defines, and false otherwise. + * + * Two elements of a {@link ITreeSet} are considered equivalent if {@link key_comp} returns false + * reflexively (i.e., no matter the order in which the elements are passed as arguments). + * + * In {@link ITreeSet} containers, the keys to sort the elements are the values (T) themselves, + * therefore {@link key_comp} and its sibling member function {@link value_comp} are equivalent. + * + * @return The comparison function. + */ + value_comp(): (x: T, y: T) => boolean; + /** + * Return iterator to lower bound. + * + * Returns an iterator pointing to the first element in the container which is not considered to + * go before val (i.e., either it is equivalent or goes after). + * + * The function uses its internal comparison object (key_comp) to determine this, returning an + * iterator to the first element for which key_comp(element,val) would return false. + * + * If the {@link ITreeSet} class is instantiated with the default comparison type ({@link less}), + * the function returns an iterator to the first element that is not less than val. + + * A similar member function, {@link upper_bound}, has the same behavior as {@link lower_bound}, except + * in the case that the {@link ITreeSet} contains elements equivalent to val: In this case + * {@link lower_bound} returns an iterator pointing to the first of such elements, whereas + * {@link upper_bound} returns an iterator pointing to the element following the last. + * + * @param val Value to compare. + * + * @return An iterator to the the first element in the container which is not considered to go before + * val, or {@link ITreeSet.end} if all elements are considered to go before val. + */ + lower_bound(val: T): SetIterator; + /** + * Return iterator to upper bound. + * + * Returns an iterator pointing to the first element in the container which is considered to go after + * val. + + * The function uses its internal comparison object (key_comp) to determine this, returning an + * iterator to the first element for which key_comp(val,element) would return true. + + * If the {@code ITreeSet} class is instantiated with the default comparison type (less), the + * function returns an iterator to the first element that is greater than val. + * + * A similar member function, {@link lower_bound}, has the same behavior as {@link upper_bound}, except + * in the case that the {@ITreeSet} contains elements equivalent to val: In this case + * {@link lower_bound} returns an iterator pointing to the first of such elements, whereas + * {@link upper_bound} returns an iterator pointing to the element following the last. + * + * @param val Value to compare. + * + * @return An iterator to the the first element in the container which is considered to go after + * val, or {@link TreeSet.end end} if no elements are considered to go after val. + */ + upper_bound(val: T): SetIterator; + /** + * Get range of equal elements. + * + * Returns the bounds of a range that includes all the elements in the container that are equivalent + * to val. + * + * If no matches are found, the range returned has a length of zero, with both iterators pointing to + * the first element that is considered to go after val according to the container's + * internal comparison object (key_comp). + * + * Two elements of a multiset are considered equivalent if the container's comparison object returns + * false reflexively (i.e., no matter the order in which the elements are passed as arguments). + * + * @param key Value to search for. + * + * @return The function returns a {@link Pair}, whose member {@link Pair.first} is the lower bound of + * the range (the same as {@link lower_bound}), and {@link Pair.second} is the upper bound + * (the same as {@link upper_bound}). + */ + equal_range(val: T): Pair, SetIterator>; + } +} +declare namespace std.base { + /** + * @hidden + */ + class _ArrayIterator extends Iterator { + private data_; + private index_; + constructor(data: Array, index: number); + source(): Container; + index(): number; + readonly value: T; + prev(): _ArrayIterator; + next(): _ArrayIterator; + advance(n: number): _ArrayIterator; + equals(obj: _ArrayIterator): boolean; + swap(obj: _ArrayIterator): void; + } +} +declare namespace std.base { + /** + * @hidden + */ + class _Repeater extends Iterator { + private index_; + private value_; + constructor(index: number, value?: T); + source(): base.Container; + index(): number; + readonly value: T; + prev(): _Repeater; + next(): _Repeater; + advance(n: number): _Repeater; + equals(obj: _Repeater): boolean; + swap(obj: _Repeater): void; + } +} +declare namespace std.base { + /** + * An abstract map. + * + * {@link MapContainer MapContainers} are associative containers that store elements formed by a combination + * of a key value (Key) and a mapped value (T), and which allows for fast retrieval + * of individual elements based on their keys. + * + * In a {@link MapContainer}, the key values are generally used to identify the elements, while the + * mapped values store the content associated to this key. The types of key and + * mapped value may differ, and are grouped together in member type value_type, which is a + * {@link Pair} type combining both: + * + * typedef pair value_type; + * + * {@link MapContainer} stores elements, keeps sequence and enables indexing by inserting elements into a + * {@link List} and registering {@link ListIterator iterators} of the {@link data_ list container} to an index + * table like {@link RBTree tree} or {@link HashBuckets hash-table}. + * + * + * + * + * ### Container properties + *
+ *
Associative
+ *
+ * Elements in associative containers are referenced by their key and not by their absolute position + * in the container. + *
+ * + *
Map
+ *
+ * Each element associates a key to a mapped value: + * Keys are meant to identify the elements whose main content is the mapped value. + *
+ *
+ * + * @param Type of the keys. Each element in a map is identified by its key value. + * @param Type of the mapped value. Each element in a map stores some data as its mapped value. + * + * @author Jeongho Nam + */ + abstract class MapContainer extends Container> { + /** + * @hidden + */ + private data_; + /** + * Default Constructor. + */ + protected constructor(); + /** + * @inheritdoc + */ + assign>>(first: InputIterator, last: InputIterator): void; + /** + * @inheritdoc + */ + clear(): void; + /** + * Get iterator to element. + * + * Searches the container for an element with a identifier equivalent to key and returns an + * iterator to it if found, otherwise it returns an iterator to {@link end end()}. + * + * Two keys are considered equivalent if the container's comparison object returns false reflexively + * (i.e., no matter the order in which the elements are passed as arguments). + * + * Another member functions, {@link has has()} and {@link count count()}, can be used to just check + * whether a particular key exists. + * + * @param key Key to be searched for + * @return An iterator to the element, if an element with specified key is found, or + * {@link end end()} otherwise. + */ + abstract find(key: Key): MapIterator; + /** + * Return iterator to beginning. + * + * Returns an iterator referring the first element in the + * + * #### Note + * If the container is {@link empty}, the returned iterator is same with {@link end end()}. + * + * @return An iterator to the first element in the The iterator containes the first element's value. + */ + begin(): MapIterator; + /** + * Return iterator to end. + * Returns an iterator referring to the past-the-end element in the + * + * The past-the-end element is the theoretical element that would follow the last element in the + * It does not point to any element, and thus shall not be dereferenced. + * + * Because the ranges used by functions of the container do not include the element reference by their + * closing iterator, this function is often used in combination with {@link MapContainer}.{@link begin} to + * specify a range including all the elements in the + * + * #### Note + * Returned iterator from {@link MapContainer}.{@link end} does not refer any element. Trying to accessing + * element by the iterator will cause throwing exception ({@link OutOfRange}). + * + * If the container is {@link empty}, this function returns the same as {@link begin}. + * + * @return An iterator to the end element in the + */ + end(): MapIterator; + /** + * Return {@link MapReverseIterator reverse iterator} to reverse beginning. + * + * Returns a {@link MapReverseIterator reverse iterator} pointing to the last element in the container + * (i.e., its reverse beginning). + * + * {@link MapReverseIterator Reverse iterators} iterate backwards: increasing them moves them towards the + * beginning of the container. + * + * {@link rbegin} points to the element preceding the one that would be pointed to by member {@link end}. + *7 + * + * @return A {@link MapReverseIterator reverse iterator} to the reverse beginning of the sequence + * + */ + rbegin(): MapReverseIterator; + /** + * Return {@link MapReverseIterator reverse iterator} to reverse end. + * + * Returns a {@link MapReverseIterator reverse iterator} pointing to the theoretical element right before + * the first element in the {@link MapContainer map container} (which is considered its reverse end). + * + * + * The range between {@link MapContainer}.{@link rbegin} and {@link MapContainer}.{@link rend} contains + * all the elements of the container (in reverse order). + * + * @return A {@link MapReverseIterator reverse iterator} to the reverse end of the sequence + */ + rend(): MapReverseIterator; + /** + * Whether have the item or not. + * + * Indicates whether a map has an item having the specified identifier. + * + * @param key Key value of the element whose mapped value is accessed. + * + * @return Whether the map has an item having the specified identifier. + */ + has(key: Key): boolean; + /** + * Count elements with a specific key. + * + * Searches the container for elements whose key is key and returns the number of elements found. + * + * @param key Key value to be searched for. + * + * @return The number of elements in the container with a key. + */ + abstract count(key: Key): number; + /** + * Return the number of elements in the map. + */ + size(): number; + /** + * @inheritdoc + */ + push(...args: Pair[]): number; + /** + * @inheritdoc + */ + push(...args: [Key, T][]): number; + /** + * Construct and insert element with hint + * + * Inserts a new element in the {@link MapContainer map container}. This new element is constructed in + * place using *args* as the arguments for the element's constructor. *hint* points to a location in the + * container suggested as a hint on where to start the search for its insertion point (the container may or + * may not use this suggestion to optimize the insertion operation). + * + * A similar member function exists, {@link insert}, which either copies or moves an existing object into + * the container, and may also take a position *hint*. + * + * @param hint Hint for the position where the element can be inserted. + * @param key The key used both to look up and to insert if not found. + * @param value Value, the item. + * + * @return An iterator pointing to either the newly inserted element or to the element that already had an + * equivalent key in the {@link MapContainer}. + */ + emplace_hint(hint: MapIterator, key: Key, val: T): MapIterator; + /** + * Construct and insert element with hint + * + * Inserts a new element in the {@link MapContainer map container}. This new element is constructed in + * place using *args* as the arguments for the element's constructor. *hint* points to a location in the + * container suggested as a hint on where to start the search for its insertion point (the container may or + * may not use this suggestion to optimize the insertion operation). + * + * A similar member function exists, {@link insert}, which either copies or moves an existing object into + * the container, and may also take a position *hint*. + * + * @param hint Hint for the position where the element can be inserted. + * @param key The key used both to look up and to insert if not found. + * @param value Value, the item. + * + * @return An {@link MapIterator iterator} pointing to either the newly inserted element or to the element + * that already had an equivalent key in the {@link MapContainer}. + */ + emplace_hint(hint: MapReverseIterator, key: Key, val: T): MapReverseIterator; + /** + * Construct and insert element with hint + * + * Inserts a new element in the {@link MapContainer map container}. This new element is constructed in + * place using *args* as the arguments for the element's constructor. *hint* points to a location in the + * container suggested as a hint on where to start the search for its insertion point (the container may or + * may not use this suggestion to optimize the insertion operation). + * + * A similar member function exists, {@link insert}, which either copies or moves an existing object into + * the container, and may also take a position *hint*. + * + * @param hint Hint for the position where the element can be inserted. + * @param pair A single argument of a {@link Pair} type with a value for the *key* as + * {@link Pair.first first} member, and a *value* for the mapped value as + * {@link Pair.second second}. + * + * @return An iterator pointing to either the newly inserted element or to the element that already had an + * equivalent key in the {@link MapContainer}. + */ + emplace_hint(hint: MapIterator, pair: Pair): MapIterator; + /** + * Construct and insert element with hint + * + * Inserts a new element in the {@link MapContainer map container}. This new element is constructed in + * place using *args* as the arguments for the element's constructor. *hint* points to a location in the + * container suggested as a hint on where to start the search for its insertion point (the container may or + * may not use this suggestion to optimize the insertion operation). + * + * A similar member function exists, {@link insert}, which either copies or moves an existing object into + * the container, and may also take a position *hint*. + * + * @param hint Hint for the position where the element can be inserted. + * @param pair A single argument of a {@link Pair} type with a value for the *key* as + * {@link Pair.first first} member, and a *value* for the mapped value as + * {@link Pair.second second}. + * + * @return An {@link MapIterator iterator} pointing to either the newly inserted element or to the element + * that already had an equivalent key in the {@link MapContainer}. + */ + emplace_hint(hint: MapReverseIterator, pair: Pair): MapReverseIterator; + /** + * Insert an element. + * + * Extends the container by inserting a new element, effectively increasing the container {@link size} + * by the number of element inserted (zero or one). + * + * @param hint Hint for the position where the element can be inserted. + * @param pair A single argument of a {@link Pair} type with a value for the *key* as + * {@link Pair.first first} member, and a *value* for the mapped value as + * {@link Pair.second second}. + * + * @return An iterator pointing to either the newly inserted element or to the element that already had an + * equivalent key in the {@link MapContainer}. + */ + insert(hint: MapIterator, pair: Pair): MapIterator; + /** + * Insert an element. + * + * Extends the container by inserting a new element, effectively increasing the container {@link size} + * by the number of element inserted (zero or one). + * + * @param hint Hint for the position where the element can be inserted. + * @param pair A single argument of a {@link Pair} type with a value for the *key* as + * {@link Pair.first first} member, and a *value* for the mapped value as + * {@link Pair.second second}. + * + * @return An iterator pointing to either the newly inserted element or to the element that already had an + * equivalent key in the {@link MapContainer}. + */ + insert(hint: MapReverseIterator, pair: Pair): MapReverseIterator; + /** + * Insert an element. + * + * Extends the container by inserting new elements, effectively increasing the container {@link size} + * by the number of elements inserted. + * + * @param hint Hint for the position where the element can be inserted. + * @param tuple Tuple represensts the {@link Pair} to be inserted as an element. + * + * @return An iterator pointing to either the newly inserted element or to the element that already had an + * equivalent key in the {@link MapContainer}. + */ + insert(hint: MapIterator, tuple: [L, U]): MapIterator; + /** + * Insert an element. + * + * Extends the container by inserting new elements, effectively increasing the container {@link size} + * by the number of elements inserted. + * + * @param hint Hint for the position where the element can be inserted. + * @param tuple Tuple represensts the {@link Pair} to be inserted as an element. + * + * @return An iterator pointing to either the newly inserted element or to the element that already had an + * equivalent key in the {@link MapContainer}. + */ + insert(hint: MapReverseIterator, tuple: [L, U]): MapReverseIterator; + /** + * Insert elements from range iterators. + * + * Extends the container by inserting new elements, effectively increasing the container {@link size} by + * the number of elements inserted. + * + * @param begin Input iterator specifying initial position of a range of elements. + * @param end Input iterator specifying final position of a range of elements. + * Notice that the range includes all the elements between begin and end, + * including the element pointed by begin but not the one pointed by end. + */ + insert>>(first: InputIterator, last: InputIterator): void; + /** + * @hidden + */ + protected abstract _Insert_by_pair(pair: Pair): any; + /** + * @hidden + */ + private _Insert_by_tuple(tuple); + /** + * @hidden + */ + protected abstract _Insert_by_hint(hint: MapIterator, pair: Pair): MapIterator; + /** + * @hidden + */ + private _Insert_by_hint_with_tuple(hint, tuple); + /** + * @hidden + */ + protected abstract _Insert_by_range>>(first: InputIterator, last: InputIterator): void; + /** + * Erase an elemet by key. + * + * Removes from the {@link MapContainer map container} a single element. + * + * This effectively reduces the container {@link size} by the number of element removed (zero or one), + * which are destroyed. + * + * @param key Key of the element to be removed from the {@link MapContainer}. + */ + erase(key: Key): number; + /** + * Erase an elemet by iterator. + * + * Removes from the {@link MapContainer map container} a single element. + * + * This effectively reduces the container {@link size} by the number of element removed (zero or one), + * which are destroyed. + * + * @param it Iterator specifying position winthin the {@link MapContainer map contaier} to be removed. + */ + erase(it: MapIterator): MapIterator; + /** + * Erase elements by range iterators. + * + * Removes from the {@link MapContainer map container} a range of elements. + * + * This effectively reduces the container {@link size} by the number of elements removed, which are + * destroyed. + * + * @param begin An iterator specifying initial position of a range within {@link MApContainer map container} + * to be removed. + * @param end An iterator specifying initial position of a range within {@link MApContainer map container} + * to be removed. + * Notice that the range includes all the elements between begin and end, + * including the element pointed by begin but not the one pointed by end. + */ + erase(begin: MapIterator, end: MapIterator): MapIterator; + /** + * Erase an elemet by iterator. + * + * Removes from the {@link MapContainer map container} a single element. + * + * This effectively reduces the container {@link size} by the number of element removed (zero or one), + * which are destroyed. + * + * @param it Iterator specifying position winthin the {@link MapContainer map contaier} to be removed. + */ + erase(it: MapReverseIterator): MapReverseIterator; + /** + * Erase elements by range iterators. + * + * Removes from the {@link MapContainer map container} a range of elements. + * + * This effectively reduces the container {@link size} by the number of elements removed, which are + * destroyed. + * + * @param begin An iterator specifying initial position of a range within {@link MApContainer map container} + * to be removed. + * @param end An iterator specifying initial position of a range within {@link MApContainer map container} + * to be removed. + * Notice that the range includes all the elements between begin and end, + * including the element pointed by begin but not the one pointed by end. + */ + erase(begin: MapReverseIterator, end: MapReverseIterator): MapReverseIterator; + /** + * @hidden + */ + private _Erase_by_key(key); + /** + * @hidden + */ + private _Erase_by_iterator(first, last?); + /** + * @hidden + */ + private _Erase_by_range(first, last); + /** + * @hidden + */ + protected _Swap(obj: MapContainer): void; + /** + * Merge two maps. + * + * Extracts and transfers elements from *source* to this container. + * + * @param source A {@link MapContainer map container} to transfer the elements from. + */ + abstract merge(source: MapContainer): void; + /** + * @hidden + */ + protected abstract _Handle_insert(first: MapIterator, last: MapIterator): void; + /** + * @hidden + */ + protected abstract _Handle_erase(first: MapIterator, last: MapIterator): void; + } + /** + * @hidden + */ + class _MapElementList extends _ListContainer, MapIterator> { + private associative_; + private rend_; + constructor(associative: MapContainer); + protected _Create_iterator(prev: MapIterator, next: MapIterator, val: Pair): MapIterator; + protected _Set_begin(it: MapIterator): void; + associative(): MapContainer; + rbegin(): MapReverseIterator; + rend(): MapReverseIterator; + } +} +declare namespace std { + /** + * An iterator of {@link MapContainer map container}. + * + * + * + * + * @author Jeongho Nam + */ + class MapIterator extends base._ListIteratorBase> implements IComparable> { + /** + * Construct from the {@link MapContainer source map} and {@link ListIterator list iterator}. + * + * @param source The source {@link MapContainer}. + * @param list_iterator A {@link ListIterator} pointing {@link Pair} of key and value. + */ + constructor(source: base._MapElementList, prev: MapIterator, next: MapIterator, val: Pair); + /** + * Get iterator to previous element. + */ + prev(): MapIterator; + /** + * Get iterator to next element. + */ + next(): MapIterator; + /** + * Advances the Iterator by n element positions. + * + * @param step Number of element positions to advance. + * @return An advanced Iterator. + */ + advance(step: number): MapIterator; + /** + * @hidden + */ + source(): base.MapContainer; + /** + * Get first, key element. + */ + readonly first: Key; + /** + * Get second, value element. + */ + /** + * Set second value. + */ + second: T; + /** + * @inheritdoc + */ + less(obj: MapIterator): boolean; + /** + * @inheritdoc + */ + equals(obj: MapIterator): boolean; + /** + * @inheritdoc + */ + hashCode(): number; + /** + * @inheritdoc + */ + swap(obj: MapIterator): void; + } + /** + * A reverse-iterator of {@link MapContainer map container}. + * + * + * + * + * @author Jeongho Nam + */ + class MapReverseIterator extends ReverseIterator, base.MapContainer, MapIterator, MapReverseIterator> { + /** + * Construct from base iterator. + * + * @param base A reference of the base iterator, which iterates in the opposite direction. + */ + constructor(base: MapIterator); + /** + * @hidden + */ + protected _Create_neighbor(base: MapIterator): MapReverseIterator; + /** + * Get first, key element. + */ + readonly first: Key; + /** + * Get second, value element. + */ + /** + * Set second value. + */ + second: T; + } +} +declare namespace std.base { + /** + * An abstract multi-map. + * + * {@link MultiMap MultiMaps} are associative containers that store elements formed by a combination of a + * key value (Key) and a mapped value (T), and which allows for fast retrieval of + * individual elements based on their keys. + * + * In a {@link MapContainer}, the key values are generally used to identify the elements, while the + * mapped values store the content associated to this key. The types of key and + * mapped value may differ, and are grouped together in member type value_type, which is a + * {@link Pair} type combining both: + * + * typedef pair value_type; + * + * {@link UniqueMap} stores elements, keeps sequence and enables indexing by inserting elements into a + * {@link List} and registering {@link ListIterator iterators} of the {@link data_ list container} to an index + * table like {@link RBTree tree} or {@link HashBuckets hash-table}. + * + * + * + * + * ### Container properties + *
+ *
Associative
+ *
+ * Elements in associative containers are referenced by their key and not by their absolute position + * in the container. + *
+ * + *
Map
+ *
+ * Each element associates a key to a mapped value: + * Keys are meant to identify the elements whose main content is the mapped value. + *
+ * + *
Multiple equivalent keys
+ *
Multiple elements in the container can have equivalent keys.
+ *
+ * + * @param Type of the keys. Each element in a map is identified by its key value. + * @param Type of the mapped value. Each element in a map stores some data as its mapped value. + * + * @author Jeongho Nam + */ + abstract class MultiMap extends MapContainer { + /** + * Construct and insert element. + * + * Inserts a new element in the {@link MultiMap}. This new element is constructed in place using args + * as the arguments for the element's constructor. + * + * This effectively increases the container {@link size} by one. + * + * A similar member function exists, {@link insert}, which either copies or moves existing objects into the + * container. + * + * @param key The key used both to look up and to insert if not found. + * @param value Value, the item. + * + * @return An {@link MapIterator iterator} to the newly inserted element. + */ + emplace(key: Key, value: T): MapIterator; + /** + * Construct and insert element. + * + * Inserts a new element in the {@link MultiMap}. This new element is constructed in place using args + * as the arguments for the element's constructor. + * + * This effectively increases the container {@link size} by one. + * + * A similar member function exists, {@link insert}, which either copies or moves existing objects into the + * container. + * + * @param pair A single argument of a {@link Pair} type with a value for the *key* as + * {@link Pair.first first} member, and a *value* for the mapped value as + * {@link Pair.second second}. + * @return An {@link MapIterator iterator} to the newly inserted element. + */ + emplace(pair: Pair): MapIterator; + /** + * Insert elements. + * + * Extends the container by inserting new elements, effectively increasing the container {@link size} by + * the number of elements inserted. + * + * @param pair A single argument of a {@link Pair} type with a value for the *key* as + * {@link Pair.first first} member, and a *value* for the mapped value as + * {@link Pair.second second}. + * + * @return An iterator pointing to the newly inserted element. + */ + insert(pair: Pair): MapIterator; + /** + * Insert elements. + * + * Extends the container by inserting new elements, effectively increasing the container {@link size} by + * the number of elements inserted. + * + * @param tuple Tuple represensts the {@link Pair} to be inserted as an element. + * + * @return An iterator pointing to the newly inserted element. + */ + insert(tuple: [L, U]): MapIterator; + /** + * @inheritdoc + */ + insert(hint: MapIterator, pair: Pair): MapIterator; + /** + * @inheritdoc + */ + insert(hint: MapReverseIterator, pair: Pair): MapReverseIterator; + /** + * @inheritdoc + */ + insert(hint: MapIterator, tuple: [L, U]): MapIterator; + /** + * @inheritdoc + */ + insert(hint: MapReverseIterator, tuple: [L, U]): MapReverseIterator; + /** + * @inheritdoc + */ + insert>>(first: InputIterator, last: InputIterator): void; + /** + * @inheritdoc + */ + merge(source: MapContainer): void; + } +} +declare namespace std.base { + /** + * An abstract set. + * + * {@link SetContainer SetContainers} are containers that store elements allowing fast retrieval of + * individual elements based on their value. + * + * In an {@link SetContainer}, the value of an element is at the same time its key, used to + * identify it. Keys are immutable, therefore, the elements in an {@link SetContainer} cannot be + * modified once in the container - they can be inserted and removed, though. + * + * {@link SetContainer} stores elements, keeps sequence and enables indexing by inserting elements into a + * {@link List} and registering {@link ListIterator iterators} of the {@link data_ list container} to an index + * table like {@link RBTree tree} or {@link HashBuckets hash-table}. + * + * + * + * + * ### Container properties + *
+ *
Associative
+ *
+ * Elements in associative containers are referenced by their key and not by their absolute + * position in the container. + *
+ * + *
Set
+ *
The value of an element is also the key used to identify it.
+ *
+ * + * @param Type of the elements. Each element in a {@link SetContainer} container is also identified + * by this value (each value is itself also the element's key). + * + * @author Jeongho Nam + */ + abstract class SetContainer extends Container { + /** + * {@link List} storing elements. + * + * Storing elements and keeping those sequence of the {@link SetContainer} are implemented by + * {@link data_ this list container}. Implementing index-table is also related with {@link data_ this list} + * by storing {@link ListIterator iterators} ({@link SetIterator} references {@link ListIterator}) who are + * created from {@link data_ here}. + */ + private data_; + /** + * Default Constructor. + */ + protected constructor(); + /** + * @inheritdoc + */ + assign>(begin: Iterator, end: Iterator): void; + /** + * @inheritdoc + */ + clear(): void; + /** + * Get iterator to element. + * + * Searches the container for an element with key as value and returns an iterator to it if found, + * otherwise it returns an iterator to {@link end end()} (the element past the end of the container). + * + * Another member function, {@link count count()}, can be used to just check whether a particular element + * exists. + * + * @param key Key to be searched for. + * + * @return An iterator to the element, if the specified value is found, or {@link end end()} if it is not + * found in the + */ + abstract find(val: T): SetIterator; + /** + * @inheritdoc + */ + begin(): SetIterator; + /** + * @inheritdoc + */ + end(): SetIterator; + /** + * @inheritdoc + */ + rbegin(): SetReverseIterator; + /** + * @inheritdoc + */ + rend(): SetReverseIterator; + /** + * Whether have the item or not. + * + * Indicates whether a set has an item having the specified identifier. + * + * @param key Key value of the element whose mapped value is accessed. + * + * @return Whether the set has an item having the specified identifier. + */ + has(val: T): boolean; + /** + * Count elements with a specific key. + * + * Searches the container for elements with a value of k and returns the number of elements found. + * + * @param key Value of the elements to be counted. + * + * @return The number of elements in the container with a key. + */ + abstract count(val: T): number; + /** + * @inheritdoc + */ + size(): number; + /** + * @inheritdoc + */ + push(...items: T[]): number; + /** + * Insert an element with hint. + * + * Extends the container by inserting new elements, effectively increasing the container size by the + * number of elements inserted. + * + * @param hint Hint for the position where the element can be inserted. + * @param val Value to be inserted as an element. + * + * @return An iterator pointing to either the newly inserted element or to the element that already had its + * same value in the {@link SetContainer}. + */ + insert(hint: SetIterator, val: T): SetIterator; + /** + * Insert an element with hint. + * + * Extends the container by inserting new elements, effectively increasing the container size by the + * number of elements inserted. + * + * @param hint Hint for the position where the element can be inserted. + * @param val Value to be inserted as an element. + * + * @return An iterator pointing to either the newly inserted element or to the element that already had its + * same value in the {@link SetContainer}. + */ + insert(hint: SetReverseIterator, val: T): SetReverseIterator; + /** + * Insert elements with a range of a + * + * Extends the container by inserting new elements, effectively increasing the container size by the + * number of elements inserted. + * + * @param begin An iterator specifying range of the begining element. + * @param end An iterator specifying range of the ending element. + */ + insert>(begin: InputIterator, end: InputIterator): void; + /** + * @hidden + */ + protected abstract _Insert_by_val(val: T): any; + /** + * @hidden + */ + protected abstract _Insert_by_hint(hint: SetIterator, val: T): SetIterator; + /** + * @hidden + */ + protected abstract _Insert_by_range>(begin: InputIterator, end: InputIterator): void; + /** + * Erase an element. + * Removes from the set container the elements whose value is key. + * + * This effectively reduces the container size by the number of elements removed. + * + * @param key Value of the elements to be erased. + * + * @return Number of elements erased. + */ + erase(val: T): number; + /** + * @inheritdoc + */ + erase(it: SetIterator): SetIterator; + /** + * Erase elements. + * Removes from the set container a range of elements.. + * + * This effectively reduces the container size by the number of elements removed. + * + * @param begin An iterator specifying a range of beginning to erase. + * @param end An iterator specifying a range of end to erase. + */ + erase(begin: SetIterator, end: SetIterator): SetIterator; + /** + * @inheritdoc + */ + erase(it: SetReverseIterator): SetReverseIterator; + /** + * Erase elements. + * Removes from the set container a range of elements.. + * + * This effectively reduces the container size by the number of elements removed. + * + * @param begin An iterator specifying a range of beginning to erase. + * @param end An iterator specifying a range of end to erase. + */ + erase(begin: SetReverseIterator, end: SetReverseIterator): SetReverseIterator; + /** + * @hidden + */ + private _Erase_by_iterator(first, last?); + /** + * @hidden + */ + private _Erase_by_val(val); + /** + * @hidden + */ + private _Erase_by_range(first, last); + /** + * @hidden + */ + protected _Swap(obj: SetContainer): void; + /** + * Merge two sets. + * + * Extracts and transfers elements from *source* to this container. + * + * @param source A {@link SetContainer set container} to transfer the elements from. + */ + abstract merge(source: SetContainer): void; + /** + * @hidden + */ + protected abstract _Handle_insert(first: SetIterator, last: SetIterator): void; + /** + * @hidden + */ + protected abstract _Handle_erase(first: SetIterator, last: SetIterator): void; + } + /** + * @hidden + */ + class _SetElementList extends _ListContainer> { + private associative_; + private rend_; + constructor(associative: SetContainer); + protected _Create_iterator(prev: SetIterator, next: SetIterator, val: T): SetIterator; + protected _Set_begin(it: SetIterator): void; + associative(): SetContainer; + rbegin(): SetReverseIterator; + rend(): SetReverseIterator; + } +} +declare namespace std { + /** + * An iterator of a Set. + * + * + * + * + * @author Jeongho Nam + */ + class SetIterator extends base._ListIteratorBase implements IComparable> { + /** + * Construct from source and index number. + * + * #### Note + * Do not create iterator directly. + * + * Use begin(), find() or end() in Map instead. + * + * @param map The source Set to reference. + * @param index Sequence number of the element in the source Set. + */ + constructor(source: base._SetElementList, prev: SetIterator, next: SetIterator, val: T); + /** + * @inheritdoc + */ + source(): base.SetContainer; + /** + * @inheritdoc + */ + prev(): SetIterator; + /** + * @inheritdoc + */ + next(): SetIterator; + /** + * @inheritdoc + */ + advance(size: number): SetIterator; + /** + * @inheritdoc + */ + less(obj: SetIterator): boolean; + /** + * @inheritdoc + */ + equals(obj: SetIterator): boolean; + /** + * @inheritdoc + */ + hashCode(): number; + /** + * @inheritdoc + */ + swap(obj: SetIterator): void; + } + /** + * A reverse-iterator of Set. + * + * + * + * + * @param Type of the elements. + * + * @author Jeongho Nam + */ + class SetReverseIterator extends ReverseIterator, SetIterator, SetReverseIterator> { + /** + * Construct from base iterator. + * + * @param base A reference of the base iterator, which iterates in the opposite direction. + */ + constructor(base: SetIterator); + /** + * @hidden + */ + protected _Create_neighbor(base: SetIterator): SetReverseIterator; + } +} +declare namespace std.base { + /** + * An abstract set. + * + * {@link SetContainer SetContainers} are containers that store elements allowing fast retrieval of + * individual elements based on their value. + * + * In an {@link SetContainer}, the value of an element is at the same time its key, used to + * identify it. Keys are immutable, therefore, the elements in an {@link SetContainer} cannot be + * modified once in the container - they can be inserted and removed, though. + * + * {@link SetContainer} stores elements, keeps sequence and enables indexing by inserting elements into a + * {@link List} and registering {@link ListIterator iterators} of the {@link data_ list container} to an index + * table like {@link RBTree tree} or {@link HashBuckets hash-table}. + * + * + * + * + * ### Container properties + *
+ *
Associative
+ *
+ * Elements in associative containers are referenced by their key and not by their absolute + * position in the container. + *
+ * + *
Set
+ *
The value of an element is also the key used to identify it.
+ * + *
Multiple equivalent keys
+ *
Multiple elements in the container can have equivalent keys.
+ *
+ * + * @param Type of the elements. Each element in a {@link SetContainer} container is also identified + * by this value (each value is itself also the element's key). + * + * @author Jeongho Nam + */ + abstract class MultiSet extends SetContainer { + /** + * Insert an element. + * + * Extends the container by inserting new elements, effectively increasing the container {@link size} by + * the number of elements inserted. + * + * @param key Value to be inserted as an element. + * + * @return An iterator to the newly inserted element. + */ + insert(val: T): SetIterator; + /** + * @inheritdoc + */ + insert(hint: SetIterator, val: T): SetIterator; + /** + * @inheritdoc + */ + insert(hint: SetReverseIterator, val: T): SetReverseIterator; + /** + * @inheritdoc + */ + insert>(begin: InputIterator, end: InputIterator): void; + /** + * @inheritdoc + */ + merge(source: SetContainer): void; + } +} +declare namespace std.base { + /** + * @hidden + */ + enum _Color { + BLACK = 0, + RED = 1, + } +} +declare namespace std.base { + /** + * @hidden + */ + abstract class _XTree { + protected root_: _XTreeNode; + protected constructor(); + clear(): void; + find(val: T): _XTreeNode; + protected _Fetch_maximum(node: _XTreeNode): _XTreeNode; + abstract is_less(left: T, right: T): boolean; + abstract is_equal_to(left: T, right: T): boolean; + insert(val: T): void; + private _Insert_case1(N); + private _Insert_case2(N); + private _Insert_case3(N); + private _Insert_case4(node); + private _Insert_case5(node); + erase(val: T): void; + private _Erase_case1(N); + private _Erase_case2(N); + private _Erase_case3(N); + private _Erase_case4(N); + private _Erase_case5(N); + private _Erase_case6(node); + protected _Rotate_left(node: _XTreeNode): void; + protected _Rotate_right(node: _XTreeNode): void; + protected _Replace_node(oldNode: _XTreeNode, newNode: _XTreeNode): void; + private _Fetch_color(node); + } +} +declare namespace std.base { + /** + * @hidden + */ + class _MapTree extends _XTree> { + private map_; + private compare_; + constructor(map: ITreeMap, compare?: (x: Key, y: Key) => boolean); + find(key: Key): _XTreeNode>; + find(it: MapIterator): _XTreeNode>; + private _Find_by_key(key); + lower_bound(key: Key): MapIterator; + upper_bound(key: Key): MapIterator; + equal_range(key: Key): Pair, MapIterator>; + key_comp(): (x: Key, y: Key) => boolean; + value_comp(): (x: Pair, y: Pair) => boolean; + is_equal_to(left: MapIterator, right: MapIterator): boolean; + is_less(left: MapIterator, right: MapIterator): boolean; + } +} +declare namespace std.base { + /** + * @hidden + */ + class _SetTree extends _XTree> { + private set_; + private compare_; + /** + * Default Constructor. + */ + constructor(set: ITreeSet, compare?: (x: T, y: T) => boolean); + find(val: T): _XTreeNode>; + find(it: SetIterator): _XTreeNode>; + private _Find_by_val(val); + lower_bound(val: T): SetIterator; + upper_bound(val: T): SetIterator; + equal_range(val: T): Pair, SetIterator>; + key_comp(): (x: T, y: T) => boolean; + value_comp(): (x: T, y: T) => boolean; + is_equal_to(left: SetIterator, right: SetIterator): boolean; + is_less(left: SetIterator, right: SetIterator): boolean; + } +} +declare namespace std.base { + /** + * @hidden + */ + class _XTreeNode { + parent: _XTreeNode; + left: _XTreeNode; + right: _XTreeNode; + value: T; + color: _Color; + constructor(value: T, color: _Color); + readonly grandParent: _XTreeNode; + readonly sibling: _XTreeNode; + readonly uncle: _XTreeNode; + } +} +declare namespace std.base { + /** + * An abstract unique-map. + * + * {@link UniqueMap UniqueMaps} are associative containers that store elements formed by a combination of a + * key value (Key) and a mapped value (T), and which allows for fast retrieval of + * individual elements based on their keys. + * + * In a {@link MapContainer}, the key values are generally used to uniquely identify the elements, + * while the mapped values store the content associated to this key. The types of key and + * mapped value may differ, and are grouped together in member type value_type, which is a + * {@link Pair} type combining both: + * + * typedef pair value_type; + * + * {@link UniqueMap} stores elements, keeps sequence and enables indexing by inserting elements into a + * {@link List} and registering {@link ListIterator iterators} of the {@link data_ list container} to an index + * table like {@link RBTree tree} or {@link HashBuckets hash-table}. + * + * + * + * + * ### Container properties + *
+ *
Associative
+ *
+ * Elements in associative containers are referenced by their key and not by their absolute position + * in the container. + *
+ * + *
Map
+ *
+ * Each element associates a key to a mapped value: + * Keys are meant to identify the elements whose main content is the mapped value. + *
+ * + *
Unique keys
+ *
No two elements in the container can have equivalent keys.
+ *
+ * + * @param Type of the keys. Each element in a map is uniquely identified by its key value. + * @param Type of the mapped value. Each element in a map stores some data as its mapped value. + * + * @author Jeongho Nam + */ + abstract class UniqueMap extends MapContainer { + /** + * @inheritdoc + */ + count(key: Key): number; + /** + * Get an element + * + * Returns a reference to the mapped value of the element identified with key. + * + * @param key Key value of the element whose mapped value is accessed. + * + * @throw exception out of range + * + * @return A reference object of the mapped value (_Ty) + */ + get(key: Key): T; + /** + * Set an item as the specified identifier. + * + * If the identifier is already in map, change value of the identifier. If not, then insert the object + * with the identifier. + * + * @param key Key value of the element whose mapped value is accessed. + * @param val Value, the item. + */ + set(key: Key, val: T): void; + /** + * Construct and insert element. + * + * Inserts a new element in the {@link UniqueMap} if its *key* is unique. This new element is constructed in + * place using args as the arguments for the construction of a *value_type* (which is an object of a + * {@link Pair} type). + * + * The insertion only takes place if no other element in the container has a *key equivalent* to the one + * being emplaced (*keys* in a {@link UniqueMap} container are unique). + * + * If inserted, this effectively increases the container {@link size} by one. + * + * A similar member function exists, {@link insert}, which either copies or moves existing objects into the + * container. + * + * @param key The key used both to look up and to insert if not found. + * @param value Value, the item. + * + * @return If the function successfully inserts the element (because no equivalent element existed already in + * the {@link UniqueMap}), the function returns a {@link Pair} of an {@link MapIterator iterator} to + * the newly inserted element and a value of true. Otherwise, it returns an + * {@link MapIterator iterator} to the equivalent element within the container and a value of false. + */ + emplace(key: Key, value: T): Pair, boolean>; + /** + * Construct and insert element. + * + * Inserts a new element in the {@link UniqueMap} if its *key* is unique. This new element is constructed in + * place using args as the arguments for the construction of a *value_type* (which is an object of a + * {@link Pair} type). + * + * The insertion only takes place if no other element in the container has a *key equivalent* to the one + * being emplaced (*keys* in a {@link UniqueMap} container are unique). + * + * If inserted, this effectively increases the container {@link size} by one. + * + * A similar member function exists, {@link insert}, which either copies or moves existing objects into the + * container. + * + * @param pair A single argument of a {@link Pair} type with a value for the *key* as + * {@link Pair.first first} member, and a *value* for the mapped value as + * {@link Pair.second second}. + * + * @return If the function successfully inserts the element (because no equivalent element existed already in + * the {@link UniqueMap}), the function returns a {@link Pair} of an {@link MapIterator iterator} to + * the newly inserted element and a value of true. Otherwise, it returns an + * {@link MapIterator iterator} to the equivalent element within the container and a value of false. + */ + emplace(pair: Pair): Pair, boolean>; + /** + * Insert an element. + * + * Extends the container by inserting new elements, effectively increasing the container {@link size} by + * one. + * + * Because element keys in a {@link UniqueMap} are unique, the insertion operation checks whether + * each inserted element has a key equivalent to the one of an element already in the container, and + * if so, the element is not inserted, returning an iterator to this existing element (if the function + * returns a value). + * + * For a similar container allowing for duplicate elements, see {@link MultiMap}. + * + * @param pair A single argument of a {@link Pair} type with a value for the *key* as + * {@link Pair.first first} member, and a *value* for the mapped value as + * {@link Pair.second second}. + * + * @return A {@link Pair}, with its member {@link Pair.first} set to an iterator pointing to either the newly + * inserted element or to the element with an equivalent key in the {@link UniqueMap}. The + * {@link Pair.second} element in the {@link Pair} is set to true if a new element was inserted or + * false if an equivalent key already existed. + */ + insert(pair: Pair): Pair, boolean>; + /** + * Insert an element. + * + * Extends the container by inserting a new element, effectively increasing the container size by the + * number of elements inserted. + * + * Because element keys in a {@link UniqueMap} are unique, the insertion operation checks whether + * each inserted element has a key equivalent to the one of an element already in the container, and + * if so, the element is not inserted, returning an iterator to this existing element (if the function + * returns a value). + * + * For a similar container allowing for duplicate elements, see {@link MultiMap}. + * + * @param tuple Tuple represensts the {@link Pair} to be inserted as an element. + * + * @return A {@link Pair}, with its member {@link Pair.first} set to an iterator pointing to either the newly + * inserted element or to the element with an equivalent key in the {@link UniqueMap}. The + * {@link Pair.second} element in the {@link Pair} is set to true if a new element was inserted or + * false if an equivalent key already existed. + */ + insert(tuple: [L, U]): Pair, boolean>; + /** + * @inheritdoc + */ + insert(hint: MapIterator, pair: Pair): MapIterator; + /** + * @inheritdoc + */ + insert(hint: MapReverseIterator, pair: Pair): MapReverseIterator; + /** + * @inheritdoc + */ + insert(hint: MapIterator, tuple: [L, U]): MapIterator; + /** + * @inheritdoc + */ + insert(hint: MapReverseIterator, tuple: [L, U]): MapReverseIterator; + /** + * @inheritdoc + */ + insert>>(first: InputIterator, last: InputIterator): void; + /** + * Insert or assign an element. + * + * Inserts an element or assigns to the current element if the key already exists. + * + * Because element keys in a {@link UniqueMap} are unique, the insertion operation checks whether + * each inserted element has a key equivalent to the one of an element already in the container, and + * if so, the element is assigned, returning an iterator to this existing element (if the function returns a + * value). + * + * For a similar container allowing for duplicate elements, see {@link MultiMap}. + * + * @param key The key used both to look up and to insert if not found. + * @param value Value, the item. + * + * @return A {@link Pair}, with its member {@link Pair.first} set to an iterator pointing to either the newly + * inserted element or to the element with an equivalent key in the {@link UniqueMap}. The + * {@link Pair.second} element in the {@link Pair} is set to true if a new element was inserted or + * false if an equivalent key already existed so the value is assigned. + */ + insert_or_assign(key: Key, value: T): Pair, boolean>; + /** + * Insert or assign an element. + * + * Inserts an element or assigns to the current element if the key already exists. + * + * Because element keys in a {@link UniqueMap} are unique, the insertion operation checks whether + * each inserted element has a key equivalent to the one of an element already in the container, and + * if so, the element is assigned, returning an iterator to this existing element (if the function returns a + * value). + * + * For a similar container allowing for duplicate elements, see {@link MultiMap}. + * + * @param hint Hint for the position where the element can be inserted. + * @param key The key used both to look up and to insert if not found. + * @param value Value, the item. + * + * @return An iterator pointing to either the newly inserted element or to the element that already had an + * equivalent key in the {@link UniqueMap}. + */ + insert_or_assign(hint: MapIterator, key: Key, value: T): MapIterator; + /** + * Insert or assign an element. + * + * Inserts an element or assigns to the current element if the key already exists. + * + * Because element keys in a {@link UniqueMap} are unique, the insertion operation checks whether + * each inserted element has a key equivalent to the one of an element already in the container, and + * if so, the element is assigned, returning an iterator to this existing element (if the function returns a + * value). + * + * For a similar container allowing for duplicate elements, see {@link MultiMap}. + * + * @param hint Hint for the position where the element can be inserted. + * @param key The key used both to look up and to insert if not found. + * @param value Value, the item. + * + * @return An iterator pointing to either the newly inserted element or to the element that already had an + * equivalent key in the {@link UniqueMap}. + */ + insert_or_assign(hint: MapReverseIterator, key: Key, value: T): MapReverseIterator; + /** + * @hidden + */ + private _Insert_or_assign_with_key_value(key, value); + /** + * @hidden + */ + private _Insert_or_assign_with_hint(hint, key, value); + /** + * Extract an element. + * + * Extracts the element pointed to by key and erases it from the {@link UniqueMap}. + * + * @param key Key value of the element whose mapped value is accessed. + * + * @return A {@link Pair} containing the value pointed to by key. + */ + extract(key: Key): Pair; + /** + * Extract an element. + * + * Extracts the element pointed to by key and erases it from the {@link UniqueMap}. + * + * @param it An iterator pointing an element to extract. + * + * @return An iterator pointing to the element immediately following it prior to the element being + * erased. If no such element exists,returns {@link end end()}. + */ + extract(it: MapIterator): MapIterator; + /** + * Extract an element. + * + * Extracts the element pointed to by key and erases it from the {@link UniqueMap}. + * + * @param it An iterator pointing an element to extract. + * + * @return An iterator pointing to the element immediately following it prior to the element being + * erased. If no such element exists,returns {@link end end()}. + */ + extract(it: MapReverseIterator): MapReverseIterator; + /** + * @hidden + */ + private _Extract_by_key(key); + /** + * @hidden + */ + private _Extract_by_iterator(it); + /** + * @hidden + */ + private _Extract_by_reverse_iterator(it); + /** + * Merge two maps. + * + * Attempts to extract each element in *source* and insert it into this container. If there's an element in this + * container with key equivalent to the key of an element from *source*, tnen that element is not extracted from + * the *source*. Otherwise, no element with same key exists in this container, then that element will be + * transfered from the *source* to this container. + * + * @param source A {@link MapContainer map container} to transfer the elements from. + */ + merge(source: MapContainer): void; + } +} +declare namespace std.base { + /** + * An abstract set. + * + * {@link SetContainer SetContainers} are containers that store elements allowing fast retrieval of + * individual elements based on their value. + * + * In an {@link SetContainer}, the value of an element is at the same time its key, used to uniquely + * identify it. Keys are immutable, therefore, the elements in an {@link SetContainer} cannot be modified + * once in the container - they can be inserted and removed, though. + * + * {@link SetContainer} stores elements, keeps sequence and enables indexing by inserting elements into a + * {@link List} and registering {@link ListIterator iterators} of the {@link data_ list container} to an index + * table like {@link RBTree tree} or {@link HashBuckets hash-table}. + * + * + * + * + * ### Container properties + *
+ *
Associative
+ *
+ * Elements in associative containers are referenced by their key and not by their absolute + * position in the container. + *
+ * + *
Set
+ *
The value of an element is also the key used to identify it.
+ * + *
Unique keys
+ *
No two elements in the container can have equivalent keys.
+ *
+ * + * @param Type of the elements. Each element in a {@link SetContainer} container is also identified + * by this value (each value is itself also the element's key). + * + * @author Jeongho Nam + */ + abstract class UniqueSet extends SetContainer { + /** + * @inheritdoc + */ + count(key: T): number; + /** + * Insert an element. + * + * Extends the container by inserting new elements, effectively increasing the container {@link size} by + * the number of element inserted (zero or one). + * + * Because elements in a {@link UniqueSet UniqueSets} are unique, the insertion operation checks whether + * each inserted element is equivalent to an element already in the container, and if so, the element is not + * inserted, returning an iterator to this existing element (if the function returns a value). + * + * For a similar container allowing for duplicate elements, see {@link MultiSet}. + * + * @param key Value to be inserted as an element. + * + * @return A {@link Pair}, with its member {@link Pair.first} set to an iterator pointing to either the newly + * inserted element or to the equivalent element already in the {@link UniqueSet}. The + * {@link Pair.second} element in the {@link Pair} is set to true if a new element was inserted or + * false if an equivalent element already existed. + */ + insert(val: T): Pair, boolean>; + /** + * @inheritdoc + */ + insert(hint: SetIterator, val: T): SetIterator; + /** + * @inheritdoc + */ + insert(hint: SetReverseIterator, val: T): SetReverseIterator; + /** + * @inheritdoc + */ + insert>(begin: InputIterator, end: InputIterator): void; + /** + * Extract an element. + * + * Extracts the element pointed to by val and erases it from the {@link UniqueSet}. + * + * @param val Value to be extracted. + * + * @return A value. + */ + extract(val: T): T; + /** + * Extract an element. + * + * Extracts the element pointed to by key and erases it from the {@link UniqueMap}. + * + * @param it An iterator pointing an element to extract. + * + * @return An iterator pointing to the element immediately following it prior to the element being + * erased. If no such element exists,returns {@link end end()}. + */ + extract(it: SetIterator): SetIterator; + /** + * Extract an element. + * + * Extracts the element pointed to by key and erases it from the {@link UniqueMap}. + * + * @param it An iterator pointing an element to extract. + * + * @return An iterator pointing to the element immediately following it prior to the element being + * erased. If no such element exists,returns {@link end end()}. + */ + extract(it: SetReverseIterator): SetReverseIterator; + /** + * @hidden + */ + private _Extract_by_key(val); + /** + * @hidden + */ + private _Extract_by_iterator(it); + /** + * @hidden + */ + private _Extract_by_reverse_iterator(it); + /** + * Merge two sets. + * + * Attempts to extract each element in *source* and insert it into this container. If there's an element in this + * container with key equivalent to the key of an element from *source*, tnen that element is not extracted from + * the *source*. Otherwise, no element with same key exists in this container, then that element will be + * transfered from the *source* to this container. + * + * @param source A {@link SetContainer set container} to transfer the elements from. + */ + merge(source: SetContainer): void; + } +} +declare namespace std.Deque { + type iterator = DequeIterator; + type reverse_iterator = DequeReverseIterator; +} +declare namespace std { + /** + * Double ended queue. + * + * {@link Deque} (usually pronounced like "deck") is an irregular acronym of + * double-ended queue. Double-ended queues are sequence containers with dynamic sizes that can be + * expanded or contracted on both ends (either its front or its back). + * + * Specific libraries may implement deques in different ways, generally as some form of dynamic array. But in any + * case, they allow for the individual elements to be accessed directly through random access iterators, with storage + * handled automatically by expanding and contracting the container as needed. + * + * Therefore, they provide a functionality similar to vectors, but with efficient insertion and deletion of + * elements also at the beginning of the sequence, and not only at its end. But, unlike {@link Vector Vectors}, + * {@link Deque Deques} are not guaranteed to store all its elements in contiguous storage locations: accessing + * elements in a deque by offsetting a pointer to another element causes undefined behavior. + * + * Both {@link Vector}s and {@link Deque}s provide a very similar interface and can be used for similar purposes, + * but internally both work in quite different ways: While {@link Vector}s use a single array that needs to be + * occasionally reallocated for growth, the elements of a {@link Deque} can be scattered in different chunks of + * storage, with the container keeping the necessary information internally to provide direct access to any of its + * elements in constant time and with a uniform sequential interface (through iterators). Therefore, + * {@link Deque Deques} are a little more complex internally than {@link Vector}s, but this allows them to grow more + * efficiently under certain circumstances, especially with very long sequences, where reallocations become more + * expensive. + * + * For operations that involve frequent insertion or removals of elements at positions other than the beginning or + * the end, {@link Deque Deques} perform worse and have less consistent iterators and references than + * {@link List Lists}. + * + * + * + * + * + * ### Container properties + *
+ *
Sequence
+ *
Elements in sequence containers are ordered in a strict linear sequence. Individual elements + * are accessed by their position in this sequence.
+ * + *
Dynamic array
+ *
Generally implemented as a dynamic array, it allows direct access to any element in the + * sequence and provides relatively fast addition/removal of elements at the beginning or the end + * of the sequence.
+ *
+ * + * @param Type of the elements. + * + * @reference http://www.cplusplus.com/reference/deque/deque/ + * @author Jeongho Nam + */ + class Deque extends base.Container implements base.IArrayContainer, base.IDequeContainer { + /** + * @hidden + */ + private matrix_; + /** + * @hidden + */ + private size_; + /** + * @hidden + */ + private capacity_; + /** + * @hidden + */ + private begin_; + /** + * @hidden + */ + private end_; + /** + * @hidden + */ + private rend_; + /** + * Default Constructor. + * + * Constructs an empty container, with no elements. + */ + constructor(); + /** + * Initializer list Constructor. + * + * Constructs a container with a copy of each of the elements in array, in the same order. + * + * @param array An array containing elements to be copied and contained. + */ + constructor(items: Array); + /** + * Fill Constructor. + * + * Constructs a container with n elements. Each element is a copy of val (if provided). + * + * @param n Initial container size (i.e., the number of elements in the container at construction). + * @param val Value to fill the container with. Each of the n elements in the container is + * initialized to a copy of this value. + */ + constructor(size: number, val: T); + /** + * Copy Constructor. + * + * Constructs a container with a copy of each of the elements in container, in the same order. + * + * @param container Another container object of the same type (with the same class template + * arguments T), whose contents are either copied or acquired. + */ + constructor(container: Deque); + /** + * Range Constructor. + * + * Constructs a container with as many elements as the range (begin, end), with each + * element emplace-constructed from its corresponding element in that range, in the same order. + * + * @param begin Input interator of the initial position in a sequence. + * @param end Input interator of the final position in a sequence. + */ + constructor(begin: Iterator, end: Iterator); + /** + * @inheritdoc + */ + assign>(begin: InputIterator, end: InputIterator): void; + /** + * @inheritdoc + */ + assign(n: number, val: T): void; + /** + * Request a change in capacity. + * + * Requests that the {@link Deque container} {@link capacity} be at least enough to contain + * n elements. + * + * If n is greater than the current {@link Deque container} {@link capacity}, the + * function causes the {@link Deque container} to reallocate its storage increasing its + * {@link capacity} to n (or greater). + * + * In all other cases, the function call does not cause a reallocation and the + * {@link Deque container} {@link capacity} is not affected. + * + * This function has no effect on the {@link Deque container} {@link size} and cannot alter + * its elements. + * + * @param n Minimum {@link capacity} for the {@link Deque container}. + * Note that the resulting {@link capacity} may be equal or greater than n. + */ + reserve(capacity: number): void; + /** + * @inheritdoc + */ + clear(): void; + /** + * @inheritdoc + */ + size(): number; + /** + * @inheritdoc + */ + empty(): boolean; + /** + * Return size of allocated storage capacity. + * + * Returns the size of the storage space currently allocated for the {@link Deque container}, + * expressed in terms of elements. + * + * This {@link capacity} is not necessarily equal to the {@link Deque container} {@link size}. + * It can be equal or greater, with the extra space allowing to accommodate for growth without the + * need to reallocate on each insertion. + * + * Notice that this {@link capacity} does not suppose a limit on the {@link size} of the + * {@link Deque container}. When this {@link capacity} is exhausted and more is needed, it is + * automatically expanded by the {@link Deque container} (reallocating it storage space). + * The theoretical limit on the {@link size} of a {@link Deque container} is given by member + * {@link max_size}. + * + * The {@link capacity} of a {@link Deque container} can be explicitly altered by calling member + * {@link Deque.reserve}. + * + * @return The size of the currently allocated storage capacity in the {@link Deque container}, + * measured in terms of the number elements it can hold. + */ + capacity(): number; + /** + * @inheritdoc + */ + front(): T; + /** + * @inheritdoc + */ + back(): T; + /** + * @inheritdoc + */ + begin(): DequeIterator; + /** + * @inheritdoc + */ + end(): DequeIterator; + /** + * @inheritdoc + */ + rbegin(): DequeReverseIterator; + /** + * @inheritdoc + */ + rend(): DequeReverseIterator; + /** + * @inheritdoc + */ + at(index: number): T; + /** + * @inheritdoc + */ + set(index: number, val: T): void; + /** + * @hidden + */ + private _Fetch_index(index); + /** + * @hidden + */ + private _Compute_col_size(capacity?); + /** + * @inheritdoc + */ + push(...items: T[]): number; + /** + * @inheritdoc + */ + push_front(val: T): void; + /** + * @inheritdoc + */ + push_back(val: T): void; + /** + * @inheritdoc + */ + pop_front(): void; + /** + * @inheritdoc + */ + pop_back(): void; + /** + * @inheritdoc + */ + insert(position: DequeIterator, val: T): DequeIterator; + /** + * @inheritdoc + */ + insert(position: DequeIterator, n: number, val: T): DequeIterator; + /** + * @inheritdoc + */ + insert>(position: DequeIterator, begin: InputIterator, end: InputIterator): DequeIterator; + /** + * @inheritdoc + */ + insert(position: DequeReverseIterator, val: T): DequeReverseIterator; + /** + * @inheritdoc + */ + insert(position: DequeReverseIterator, n: number, val: T): DequeReverseIterator; + /** + * @inheritdoc + */ + insert>(position: DequeReverseIterator, begin: InputIterator, end: InputIterator): DequeReverseIterator; + /** + * @hidden + */ + private _Insert_by_val(position, val); + /** + * @hidden + */ + private _Insert_by_repeating_val(position, n, val); + /** + * @hidden + */ + protected _Insert_by_range>(pos: DequeIterator, first: InputIterator, last: InputIterator): DequeIterator; + /** + * @hidden + */ + private _Insert_to_middle(pos, first, last); + /** + * @hidden + */ + private _Insert_to_end(first, last); + /** + * @hidden + */ + private _Try_expand_capacity(size); + /** + * @hidden + */ + private _Try_add_row_at_front(); + /** + * @hidden + */ + private _Try_add_row_at_back(); + /** + * @inheritdoc + */ + erase(position: DequeIterator): DequeIterator; + /** + * @inheritdoc + */ + erase(first: DequeIterator, last: DequeIterator): DequeIterator; + /** + * @inheritdoc + */ + erase(position: DequeReverseIterator): DequeReverseIterator; + /** + * @inheritdoc + */ + erase(first: DequeReverseIterator, last: DequeReverseIterator): DequeReverseIterator; + /** + * @hidden + */ + protected _Erase_by_range(first: DequeIterator, last: DequeIterator): DequeIterator; + /** + * Swap content. + * + * Exchanges the content of the container by the content of obj, which is another + * {@link Deque container} object with same type of elements. Sizes and container type may differ. + * + * After the call to this member function, the elements in this container are those which were in obj + * before the call, and the elements of obj are those which were in this. All iterators, references and + * pointers remain valid for the swapped objects. + * + * Notice that a non-member function exists with the same name, {@link swap swap}, overloading that + * algorithm with an optimization that behaves like this member function. + * + * @param obj Another {@link Deque container} of the same type of elements (i.e., instantiated + * with the same template parameter, T) whose content is swapped with that of this + * {@link Deque container}. + */ + swap(obj: Deque): void; + /** + * @inheritdoc + */ + swap(obj: base.Container): void; + /** + * @hidden + */ + private static readonly ROW_SIZE; + /** + * @hidden + */ + private static readonly MIN_CAPACITY; + /** + * @hidden + */ + private static readonly MAGNIFIER; + } +} +declare namespace std { + /** + * An iterator of {@link Deque}. + * + * + * + * + * @author Jeongho Nam + */ + class DequeIterator extends Iterator implements base.IArrayIterator { + /** + * @hidden + */ + private index_; + /** + * Construct from the source {@link Deque container}. + * + * #### Note + * Do not create the iterator directly, by yourself. + * + * Use {@link Deque.begin begin()}, {@link Deque.end end()} in {@link Deque container} instead. + * + * @param source The source {@link Deque container} to reference. + * @param index Sequence number of the element in the source {@link Deque}. + */ + constructor(source: Deque, index: number); + /** + * @inheritdoc + */ + source(): Deque; + /** + * @inheritdoc + */ + index(): number; + /** + * @inheritdoc + */ + /** + * Set value of the iterator is pointing to. + * + * @param val Value to set. + */ + value: T; + /** + * @inheritdoc + */ + prev(): DequeIterator; + /** + * @inheritdoc + */ + next(): DequeIterator; + /** + * @inheritdoc + */ + advance(n: number): DequeIterator; + /** + * @inheritdoc + */ + equals(obj: DequeIterator): boolean; + /** + * @inheritdoc + */ + swap(obj: DequeIterator): void; + } +} +declare namespace std { + /** + * A reverse-iterator of Deque. + * + * + * + * + * @param Type of the elements. + * + * @author Jeongho Nam + */ + class DequeReverseIterator extends ReverseIterator, DequeIterator, DequeReverseIterator> implements base.IArrayIterator { + /** + * Construct from base iterator. + * + * @param base A reference of the base iterator, which iterates in the opposite direction. + */ + constructor(base: DequeIterator); + /** + * @hidden + */ + protected _Create_neighbor(base: DequeIterator): DequeReverseIterator; + /** + * @inheritdoc + */ + index(): number; + /** + * @inheritdoc + */ + /** + * Set value of the iterator is pointing to. + * + * @param val Value to set. + */ + value: T; + } +} +declare namespace std { + /** + * Function handling termination on exception + * + * Calls the current terminate handler. + * + * By default, the terminate handler calls abort. But this behavior can be redefined by calling + * {@link set_terminate}. + * + * This function is automatically called when no catch handler can be found for a thrown exception, + * or for some other exceptional circumstance that makes impossible to continue the exception handling process. + * + * This function is provided so that the terminate handler can be explicitly called by a program that needs to + * abnormally terminate, and works even if {@link set_terminate} has not been used to set a custom terminate handler + * (calling abort in this case). + */ + function terminate(): void; + /** + * Set terminate handler function. + * + * A terminate handler function is a function automatically called when the exception handling process has + * to be abandoned for some reason. This happens when no catch handler can be found for a thrown exception, or for + * some other exceptional circumstance that makes impossible to continue the exception handling process. + * + * Before this function is called by the program for the first time, the default behavior is to call abort. + * + * A program may explicitly call the current terminate handler function by calling {@link terminate}. + * + * @param f Function that takes no parameters and returns no value (void). + */ + function set_terminate(f: () => void): void; + /** + * Get terminate handler function. + * + * The terminate handler function is automatically called when no catch handler can be found + * for a thrown exception, or for some other exceptional circumstance that makes impossible to continue the exception + * handling process. + * + * If no such function has been set by a previous call to {@link set_terminate}, the function returns a + * null-pointer. + * + * @return If {@link set_terminate} has previously been called by the program, the function returns the current + * terminate handler function. Otherwise, it returns a null-pointer. + */ + function get_terminate(): () => void; + /** + * Standard exception class. + * + * Base class for standard exceptions. + * + * All objects thrown by components of the standard library are derived from this class. + * Therefore, all standard exceptions can be caught by catching this type by reference. + * + * + * + * + * @reference http://www.cplusplus.com/reference/exception/exception + * @author Jeongho Nam + */ + class Exception { + /** + * @hidden + */ + private message_; + /** + * Default Constructor. + */ + constructor(); + /** + * Construct from a message. + * + * @param message A message representing specification about the Exception. + */ + constructor(message: string); + /** + * Get string identifying exception. + * + * Returns a string that may be used to identify the exception. + * + * The particular representation pointed by the returned value is implementation-defined. + * As a virtual function, derived classes may redefine this function so that specify value are + * returned. + */ + what(): string; + } + /** + * Logic error exception. + * + * This class defines the type of objects thrown as exceptions to report errors in the internal + * logical of the program, such as violation of logical preconditions or class invariants. + * + * These errors are presumably detectable before the program executes. + * + * It is used as a base class for several logical error exceptions. + * + * + * + * + * @reference http://www.cplusplus.com/reference/stdexcept/logic_error + * @author Jeongho Nam + */ + class LogicError extends Exception { + /** + * Construct from a message. + * + * @param message A message representing specification about the Exception. + */ + constructor(message: string); + } + /** + * Domain error exception. + * + * This class defines the type of objects thrown as exceptions to report domain errors. + * + * Generally, the domain of a mathematical function is the subset of values that it is defined for. + * For example, the square root function is only defined for non-negative numbers. Thus, a negative number + * for such a function would qualify as a domain error. + * + * No component of the standard library throws exceptions of this type. It is designed as a standard + * exception to be thrown by programs. + * + * + *

+ * + * @reference http://www.cplusplus.com/reference/stdexcept/domain_error + * @author Jeongho Nam + */ + class DomainError extends LogicError { + /** + * Construct from a message. + * + * @param message A message representing specification about the Exception. + */ + constructor(message: string); + } + /** + * Invalid argument exception. + * + * This class defines the type of objects thrown as exceptions to report an invalid argument. + * + * It is a standard exception that can be thrown by programs. Some components of the standard library + * also throw exceptions of this type to signal invalid arguments. + * + * + * + * + * @reference http://www.cplusplus.com/reference/stdexcept/invalid_argument + * @author Jeongho Nam + */ + class InvalidArgument extends LogicError { + /** + * Construct from a message. + * + * @param message A message representing specification about the Exception. + */ + constructor(message: string); + } + /** + * Length error exception. + * + * This class defines the type of objects thrown as exceptions to report a length error. + * + * It is a standard exception that can be thrown by programs. Some components of the standard library, + * such as vector and string also throw exceptions of this type to signal errors resizing. + * + * + * + * + * @reference http://www.cplusplus.com/reference/stdexcept/length_error + * @author Jeongho Nam + */ + class LengthError extends LogicError { + /** + * Construct from a message. + * + * @param message A message representing specification about the Exception. + */ + constructor(message: string); + } + /** + * Out-of-range exception. + * + * This class defines the type of objects thrown as exceptions to report an out-of-range error. + * + * It is a standard exception that can be thrown by programs. Some components of the standard library, + * such as vector, deque, string and bitset also throw exceptions of this type to signal arguments + * out of range. + * + * + * + * + * @reference http://www.cplusplus.com/reference/stdexcept/out_of_range + * @author Jeongho Nam + */ + class OutOfRange extends LogicError { + /** + * Construct from a message. + * + * @param message A message representing specification about the Exception. + */ + constructor(message: string); + } + /** + * Runtime error exception. + * + * This class defines the type of objects thrown as exceptions to report errors that can only be + * detected during runtime. + * + * It is used as a base class for several runtime error exceptions. + * + * + * + * + * @reference http://www.cplusplus.com/reference/stdexcept/runtime_error + * @author Jeongho Nam + */ + class RuntimeError extends Exception { + /** + * Construct from a message. + * + * @param message A message representing specification about the Exception. + */ + constructor(message: string); + } + /** + * Overflow error exception. + * + * This class defines the type of objects thrown as exceptions to arithmetic overflow errors. + * + * It is a standard exception that can be thrown by programs. Some components of the standard library + * also throw exceptions of this type to signal range errors. + * + * + * + * + * @reference http://www.cplusplus.com/reference/stdexcept/overflow_error + * @author Jeongho Nam + */ + class OverflowError extends RuntimeError { + /** + * Construct from a message. + * + * @param message A message representing specification about the Exception. + */ + constructor(message: string); + } + /** + * Underflow error exception. + * + * This class defines the type of objects thrown as exceptions to arithmetic underflow errors. + * + * No component of the standard library throws exceptions of this type. It is designed as a standard + * exception to be thrown by programs. + * + * + * + * + * @reference http://www.cplusplus.com/reference/stdexcept/underflow_error + * @author Jeongho Nam + */ + class UnderflowError extends RuntimeError { + /** + * Construct from a message. + * + * @param message A message representing specification about the Exception. + */ + constructor(message: string); + } + /** + * Range error exception. + * + * This class defines the type of objects thrown as exceptions to report range errors in internal + * computations. + * + * It is a standard exception that can be thrown by programs. Some components of the standard library + * also throw exceptions of this type to signal range errors. + * + * + * + * + * @reference http://www.cplusplus.com/reference/stdexcept/range_error + * @author Jeongho Nam + */ + class RangeError extends RuntimeError { + /** + * Construct from a message. + * + * @param message A message representing specification about the Exception. + */ + constructor(message: string); + } +} +declare namespace std { + /** + * Function object class for equality comparison. + * + * Binary function object class whose call returns whether its two arguments compare equal (as returned by + * operator ==). + * + * Generically, function objects are instances of a class with member function {@link IComparable.equal_to equal_to} + * defined. This member function allows the object to be used with the same syntax as a function call. + * + * @param x First element to compare. + * @param y Second element to compare. + * + * @return Whether the arguments are equal. + */ + function equal_to(x: T, y: T): boolean; + /** + * Function object class for non-equality comparison. + * + * Binary function object class whose call returns whether its two arguments compare not equal (as returned + * by operator operator!=). + * + * Generically, function objects are instances of a class with member function {@link IComparable.equal_to equal_to} + * defined. This member function allows the object to be used with the same syntax as a function call. + * + * @param x First element to compare. + * @param y Second element to compare. + * + * @return Whether the arguments are not equal. + */ + function not_equal_to(x: T, y: T): boolean; + /** + * Function for less-than inequality comparison. + * + * Binary function returns whether the its first argument compares less than the second. + * + * Generically, function objects are instances of a class with member function {@link IComparable.less less} + * defined. If an object doesn't have the method, then its own uid will be used to compare insteadly. + * This member function allows the object to be used with the same syntax as a function call. + * + * Objects of this class can be used on standard algorithms such as {@link sort sort()}, + * {@link merge merge()} or {@link TreeMap.lower_bound lower_bound()}. + * + * @param Type of arguments to compare by the function call. The type shall supporrt the operation + * operator<() or method {@link IComparable.less less}. + * + * @param x First element, the standard of comparison. + * @param y Second element compare with the first. + * + * @return Whether the first parameter is less than the second. + */ + function less(x: T, y: T): boolean; + /** + * Function object class for less-than-or-equal-to comparison. + * + * Binary function object class whose call returns whether the its first argument compares {@link less less than} or + * {@link equal_to equal to} the second (as returned by operator <=). + * + * Generically, function objects are instances of a class with member function {@link IComparable.less less} + * and {@link IComparable.equal_to equal_to} defined. This member function allows the object to be used with the same + * syntax as a function call. + * + * @param x First element, the standard of comparison. + * @param y Second element compare with the first. + * + * @return Whether the x is {@link less less than} or {@link equal_to equal to} the y. + */ + function less_equal(x: T, y: T): boolean; + /** + * Function for greater-than inequality comparison. + * + * Binary function returns whether the its first argument compares greater than the second. + * + * Generically, function objects are instances of a class with member function {@link less} and + * {@link equal_to equal_to()} defined. If an object doesn't have those methods, then its own uid will be used + * to compare insteadly. This member function allows the object to be used with the same syntax as a function + * call. + * + * Objects of this class can be used on standard algorithms such as {@link sort sort()}, + * {@link merge merge()} or {@link TreeMap.lower_bound lower_bound()}. + * + * @param Type of arguments to compare by the function call. The type shall supporrt the operation + * operator>() or method {@link IComparable.greater greater}. + * + * @return Whether the x is greater than the y. + */ + function greater(x: T, y: T): boolean; + /** + * Function object class for greater-than-or-equal-to comparison. + * + * Binary function object class whose call returns whether the its first argument compares + * {@link greater greater than} or {@link equal_to equal to} the second (as returned by operator >=). + * + * Generically, function objects are instances of a class with member function {@link IComparable.less less} + * defined. If an object doesn't have the method, then its own uid will be used to compare insteadly. + * This member function allows the object to be used with the same syntax as a function call. + * + * @param x First element, the standard of comparison. + * @param y Second element compare with the first. + * + * @return Whether the x is {@link greater greater than} or {@link equal_to equal to} the y. + */ + function greater_equal(x: T, y: T): boolean; + /** + * Logical AND function object class. + * + * Binary function object class whose call returns the result of the logical "and" operation between its two + * arguments (as returned by operator &&). + * + * Generically, function objects are instances of a class with member function operator() defined. This member + * function allows the object to be used with the same syntax as a function call. + * + * @param x First element. + * @param y Second element. + * + * @return Result of logical AND operation. + */ + function logical_and(x: T, y: T): boolean; + /** + * Logical OR function object class. + * + * Binary function object class whose call returns the result of the logical "or" operation between its two + * arguments (as returned by operator ||). + * + * Generically, function objects are instances of a class with member function operator() defined. This member + * function allows the object to be used with the same syntax as a function call. + * + * @param x First element. + * @param y Second element. + * + * @return Result of logical OR operation. + */ + function logical_or(x: T, y: T): boolean; + /** + * Logical NOT function object class. + * + * Unary function object class whose call returns the result of the logical "not" operation on its argument + * (as returned by operator !). + * + * Generically, function objects are instances of a class with member function operator() defined. This member + * function allows the object to be used with the same syntax as a function call. + * + * @param x Target element. + * + * @return Result of logical NOT operation. + */ + function logical_not(x: T): boolean; + /** + * Bitwise AND function object class. + * + * Binary function object class whose call returns the result of applying the bitwise "and" operation between + * its two arguments (as returned by operator &). + * + * @param x First element. + * @param y Second element. + * + * @return Result of bitwise AND operation. + */ + function bit_and(x: number, y: number): number; + /** + * Bitwise OR function object class. + * + * Binary function object class whose call returns the result of applying the bitwise "and" operation between + * its two arguments (as returned by operator &). + * + * @param x First element. + * @param y Second element. + * + * @return Result of bitwise OR operation. + */ + function bit_or(x: number, y: number): number; + /** + * Bitwise XOR function object class. + * + * Binary function object class whose call returns the result of applying the bitwise "exclusive or" + * operation between its two arguments (as returned by operator ^). + * + * @param x First element. + * @param y Second element. + * + * @return Result of bitwise XOR operation. + */ + function bit_xor(x: number, y: number): number; + /** + * Default hash function for number. + * + * Unary function that defines the default hash function used by the standard library. + * + * The functional call returns a hash value of its argument: A hash value is a value that depends solely on + * its argument, returning always the same value for the same argument (for a given execution of a program). The + * value returned shall have a small likelihood of being the same as the one returned for a different argument. + * + * + * @param val Value to be hashed. + * + * @return Returns a hash value for its argument, as a value of type number. The number is an unsigned integer. + */ + function hash(val: number): number; + /** + * Default hash function for string. + * + * Unary function that defines the default hash function used by the standard library. + * + * The functional call returns a hash value of its argument: A hash value is a value that depends solely on + * its argument, returning always the same value for the same argument (for a given execution of a program). The + * value returned shall have a small likelihood of being the same as the one returned for a different argument. + * + * @param str A string to be hashed. + * + * @return Returns a hash value for its argument, as a value of type number. The number is an unsigned integer. + */ + function hash(str: string): number; + /** + * Default hash function for Object. + * + * Unary function that defines the default hash function used by the standard library. + * + * The functional call returns a hash value of its argument: A hash value is a value that depends solely on + * its argument, returning always the same value for the same argument (for a given execution of a program). The + * value returned shall have a small likelihood of being the same as the one returned for a different argument. + * + * + * The default {@link hash} function of Object returns a value returned from {@link hash hash(number)} with + * an unique id of each Object. If you want to specify {@link hash} function of a specific class, then + * define a member function public hashCode(): number in the class. + * + * @param obj Object to be hashed. + * + * @return Returns a hash value for its argument, as a value of type number. The number is an unsigned integer. + */ + function hash(obj: Object): number; + /** + * Exchange contents of {@link IContainers containers}. + * + * The contents of container left are exchanged with those of right. Both container objects must have + * same type of elements (same template parameters), although sizes may differ. + * + * After the call to this member function, the elements in left are those which were in right before + * the call, and the elements of right are those which were in left. All iterators, references and + * pointers remain valid for the swapped objects. + * + * This is an overload of the generic algorithm swap that improves its performance by mutually transferring + * ownership over their assets to the other container (i.e., the containers exchange references to their data, without + * actually performing any element copy or movement): It behaves as if left. + * {@link Container.swap swap}(right) was called. + * + * @param left A {@link Container container} to swap its contents. + * @param right A {@link Container container} to swap its contents. + */ + function swap(left: base.Container, right: base.Container): void; + /** + * Exchange contents of queues. + * + * Exchanges the contents of left and right. + * + * @param left A {@link Queue} container of the same type. Size may differ. + * @param right A {@link Queue} container of the same type. Size may differ. + */ + function swap(left: Queue, right: Queue): void; + /** + * Exchange contents of {@link PriorityQueue PriorityQueues}. + * + * Exchanges the contents of left and right. + * + * @param left A {@link PriorityQueue} container of the same type. Size may differ. + * @param right A {@link PriorityQueue} container of the same type. Size may differ. + */ + function swap(left: PriorityQueue, right: PriorityQueue): void; + /** + * Exchange contents of {@link Stack Stacks}. + * + * Exchanges the contents of left and right. + * + * @param left A {@link Stack} container of the same type. Size may differ. + * @param right A {@link Stack} container of the same type. Size may differ. + */ + function swap(left: Stack, right: Stack): void; + /** + * Exchanges the contents of two {@link UniqueMap unique maps}. + * + * The contents of container left are exchanged with those of right. Both container objects must + * be of the same type (same template parameters), although sizes may differ. + * + * After the call to this member function, the elements in left are those which were in right + * before the call, and the elements of right are those which were in left. All iterators, references + * and pointers remain valid for the swapped objects. + * + * This is an overload of the generic algorithm swap that improves its performance by mutually transferring + * ownership over their assets to the other container (i.e., the containers exchange references to their data, + * without actually performing any element copy or movement): It behaves as if + * left.{@link UniqueMap.swap swap}(right) was called. + * + * @param left An {@link UniqueMap unique map} to swap its conents. + * @param right An {@link UniqueMap unique map} to swap its conents. + */ + function swap(left: base.UniqueMap, right: base.UniqueMap): void; + /** + * Exchanges the contents of two {@link MultiMap multi maps}. + * + * The contents of container left are exchanged with those of right. Both container objects must + * be of the same type (same template parameters), although sizes may differ. + * + * After the call to this member function, the elements in left are those which were in right + * before the call, and the elements of right are those which were in left. All iterators, references + * and pointers remain valid for the swapped objects. + * + * This is an overload of the generic algorithm swap that improves its performance by mutually transferring + * ownership over their assets to the other container (i.e., the containers exchange references to their data, + * without actually performing any element copy or movement): It behaves as if + * left.{@link MultiMap.swap swap}(right) was called. + * + * @param left A {@link MultiMap multi map} to swap its conents. + * @param right A {@link MultiMap multi map} to swap its conents. + */ + function swap(left: base.MultiMap, right: base.MultiMap): void; +} +declare namespace std { + /** + * Bind function arguments. + * + * Returns a function object based on fn, but with its arguments bound to args. + * + * Each argument may either be bound to a value or be a {@link placeholders placeholder}: + *
    + *
  • If bound to a value, calling the returned function object will always use that value as argument.
  • + *
  • + * If a {@link placeholders placeholder}, calling the returned function object forwards an argument passed to the + * call (the one whose order number is specified by the placeholder). + *
  • + *
+ * + * Calling the returned object returns the same type as fn. + * + * @param fn A function object, pointer to function or pointer to member. + * @param args List of arguments to bind: either values, or {@link placeholders}. + * + * @return A function object that, when called, calls fn with its arguments bound to args. If fn is + * a pointer to member, the first argument expected by the returned function is an object of the class fn + * is a member. + */ + function bind(fn: (...args: any[]) => Ret, ...args: any[]): (...args: any[]) => Ret; + /** + * Bind function arguments. + * + * Returns a function object based on fn, but with its arguments bound to args. + * + * Each argument may either be bound to a value or be a {@link placeholders placeholder}: + *
    + *
  • If bound to a value, calling the returned function object will always use that value as argument.
  • + *
  • + * If a {@link placeholders placeholder}, calling the returned function object forwards an argument passed to the + * call (the one whose order number is specified by the placeholder). + *
  • + *
+ * + * Calling the returned object returns the same type as fn. + * + * @param fn A function object, pointer to function or pointer to member. + * @param thisArg This argument, owner object of the member method fn. + * @param args List of arguments to bind: either values, or {@link placeholders}. + * + * @return A function object that, when called, calls fn with its arguments bound to args. If fn is + * a pointer to member, the first argument expected by the returned function is an object of the class fn + * is a member. + */ + function bind(fn: (...args: any[]) => Ret, thisArg: T, ...args: any[]): (...args: any[]) => Ret; +} +/** + * Bind argument placeholders. + * + * This namespace declares an unspecified number of objects: _1, _2, _3, ...
, which are + * used to specify placeholders in calls to function {@link bind}. + * + * When the function object returned by bind is called, an argument with placeholder {@link _1} is replaced by the + * first argument in the call, {@link _2} is replaced by the second argument in the call, and so on... For example: + * + * + * let vec: Vector = new Vector(); + * + * let bind = bind(Vector.insert, _1, vec.end(), _2, _3); + * bind.apply(vec, 5, 1); // vec.insert(vec.end(), 5, 1); + * // [1, 1, 1, 1, 1] + * + * + * When a call to {@link bind} is used as a subexpression in another call to bind, the {@link placeholders} + * are relative to the outermost {@link bind} expression. + * + * @reference http://www.cplusplus.com/reference/functional/placeholders/ + * @author Jeongho Nam + */ +declare namespace std.placeholders { + /** + * @hidden + */ + class PlaceHolder { + private index_; + constructor(index: number); + index(): number; + } + /** + * Replaced by the first argument in the function call. + */ + const _1: PlaceHolder; + /** + * Replaced by the second argument in the function call. + */ + const _2: PlaceHolder; + /** + * Replaced by the third argument in the function call. + */ + const _3: PlaceHolder; + const _4: PlaceHolder; + const _5: PlaceHolder; + const _6: PlaceHolder; + const _7: PlaceHolder; + const _8: PlaceHolder; + const _9: PlaceHolder; + const _10: PlaceHolder; + const _11: PlaceHolder; + const _12: PlaceHolder; + const _13: PlaceHolder; + const _14: PlaceHolder; + const _15: PlaceHolder; + const _16: PlaceHolder; + const _17: PlaceHolder; + const _18: PlaceHolder; + const _19: PlaceHolder; + const _20: PlaceHolder; +} +declare namespace std.HashMap { + type iterator = MapIterator; + type reverse_iterator = MapReverseIterator; +} +declare namespace std { + /** + * Hashed, unordered map. + * + * {@link HashMap}s are associative containers that store elements formed by the combination of a key value + * and a mapped value, and which allows for fast retrieval of individual elements based on their keys. + * + * In an {@link HashMap}, the key value is generally used to uniquely identify the element, while the + * mapped value is an object with the content associated to this key. Types of key and + * mapped value may differ. + * + * Internally, the elements in the {@link HashMap} are not sorted in any particular order with respect to either + * their key or mapped values, but organized into buckets depending on their hash values to allow + * for fast access to individual elements directly by their key values (with a constant average time complexity + * on average). + * + * {@link HashMap} containers are faster than {@link TreeMap} containers to access individual elements by their + * key, although they are generally less efficient for range iteration through a subset of their elements. + * + * + * + * + * ### Container properties + *
+ *
Associative
+ *
Elements in associative containers are referenced by their key and not by their absolute + * position in the container.
+ * + *
Hashed
+ *
Hashed containers organize their elements using hash tables that allow for fast access to elements + * by their key.
+ * + *
Map
+ *
Each element associates a key to a mapped value: + * Keys are meant to identify the elements whose main content is the mapped value.
+ * + *
Unique keys
+ *
No two elements in the container can have equivalent keys.
+ *
+ * + * @param Type of the key values. + * Each element in an {@link HashMap} is uniquely identified by its key value. + * @param Type of the mapped value. + * Each element in an {@link HashMap} is used to store some data as its mapped value. + * + * @reference http://www.cplusplus.com/reference/unordered_map/unordered_map + * @author Jeongho Nam + */ + class HashMap extends base.UniqueMap implements base.IHashMap { + /** + * @hidden + */ + private hash_buckets_; + /** + * Default Constructor. + */ + constructor(); + /** + * Construct from elements. + */ + constructor(items: Pair[]); + /** + * Contruct from tuples. + * + * @param array Tuples to be contained. + */ + constructor(array: [Key, T][]); + /** + * Copy Constructor. + */ + constructor(container: HashMap); + /** + * Construct from range iterators. + */ + constructor(begin: Iterator>, end: Iterator>); + /** + * @inheritdoc + */ + clear(): void; + /** + * @inheritdoc + */ + find(key: Key): MapIterator; + /** + * @inheritdoc + */ + begin(): MapIterator; + /** + * @inheritdoc + */ + begin(index: number): MapIterator; + /** + * @inheritdoc + */ + end(): MapIterator; + /** + * @inheritdoc + */ + end(index: number): MapIterator; + /** + * @inheritdoc + */ + rbegin(): MapReverseIterator; + /** + * @inheritdoc + */ + rbegin(index: number): MapReverseIterator; + /** + * @inheritdoc + */ + rend(): MapReverseIterator; + /** + * @inheritdoc + */ + rend(index: number): MapReverseIterator; + /** + * @inheritdoc + */ + bucket_count(): number; + /** + * @inheritdoc + */ + bucket_size(index: number): number; + /** + * @inheritdoc + */ + max_load_factor(): number; + /** + * @inheritdoc + */ + max_load_factor(z: number): void; + /** + * @inheritdoc + */ + bucket(key: Key): number; + /** + * @inheritdoc + */ + reserve(n: number): void; + /** + * @inheritdoc + */ + rehash(n: number): void; + /** + * @hidden + */ + protected _Insert_by_pair(pair: Pair): any; + /** + * @hidden + */ + protected _Insert_by_hint(hint: MapIterator, pair: Pair): MapIterator; + /** + * @hidden + */ + protected _Insert_by_range>>(first: InputIterator, last: InputIterator): void; + /** + * @hidden + */ + protected _Handle_insert(first: MapIterator, last: MapIterator): void; + /** + * @hidden + */ + protected _Handle_erase(first: MapIterator, last: MapIterator): void; + /** + * Swap content. + * + * Exchanges the content of the container by the content of obj, which is another + * {@link HashMap map} of the same type. Sizes abd container type may differ. + * + * After the call to this member function, the elements in this container are those which were + * in obj before the call, and the elements of obj are those which were in this. All + * iterators, references and pointers remain valid for the swapped objects. + * + * Notice that a non-member function exists with the same name, {@link swap swap}, overloading that + * algorithm with an optimization that behaves like this member function. + * + * @param obj Another {@link HashMap map container} of the same type of elements as this (i.e., + * with the same template parameters, Key and T) whose content is swapped + * with that of this {@link HashMap container}. + */ + swap(obj: HashMap): void; + /** + * @inheritdoc + */ + swap(obj: base.Container>): void; + } +} +declare namespace std.HashMultiMap { + type iterator = MapIterator; + type reverse_iterator = MapReverseIterator; +} +declare namespace std { + /** + * Hashed, unordered Multimap. + * + * {@link HashMultiMap}s are associative containers that store elements formed by the combination of + * a key value and a mapped value, much like {@link HashMultiMap} containers, but allowing + * different elements to have equivalent keys. + * + * In an {@link HashMultiMap}, the key value is generally used to uniquely identify the + * element, while the mapped value is an object with the content associated to this key. + * Types of key and mapped value may differ. + * + * Internally, the elements in the {@link HashMultiMap} are not sorted in any particular order with + * respect to either their key or mapped values, but organized into buckets depending on + * their hash values to allow for fast access to individual elements directly by their key values + * (with a constant average time complexity on average). + * + * Elements with equivalent keys are grouped together in the same bucket and in such a way that + * an iterator can iterate through all of them. Iterators in the container are doubly linked iterators. + * + * + * + * + * ### Container properties + *
+ *
Associative
+ *
Elements in associative containers are referenced by their key and not by their absolute + * position in the container.
+ * + *
Hashed
+ *
Hashed containers organize their elements using hash tables that allow for fast access to elements + * by their key.
+ * + *
Map
+ *
Each element associates a key to a mapped value: + * Keys are meant to identify the elements whose main content is the mapped value.
+ * + *
Multiple equivalent keys
+ *
The container can hold multiple elements with equivalent keys.
+ *
+ * + * @param Type of the key values. + * Each element in an {@link HashMultiMap} is identified by a key value. + * @param Type of the mapped value. + * Each element in an {@link HashMultiMap} is used to store some data as its mapped value. + * + * @reference http://www.cplusplus.com/reference/unordered_map/unordered_multimap + * @author Jeongho Nam + */ + class HashMultiMap extends base.MultiMap { + /** + * @hidden + */ + private hash_buckets_; + /** + * Default Constructor. + */ + constructor(); + /** + * Construct from elements. + */ + constructor(items: Pair[]); + /** + * Contruct from tuples. + * + * @param array Tuples to be contained. + */ + constructor(array: [Key, T][]); + /** + * Copy Constructor. + */ + constructor(container: HashMultiMap); + /** + * Construct from range iterators. + */ + constructor(begin: Iterator>, end: Iterator>); + /** + * @inheritdoc + */ + clear(): void; + /** + * @inheritdoc + */ + find(key: Key): MapIterator; + /** + * @inheritdoc + */ + count(key: Key): number; + /** + * @inheritdoc + */ + begin(): MapIterator; + /** + * @inheritdoc + */ + begin(index: number): MapIterator; + /** + * @inheritdoc + */ + end(): MapIterator; + /** + * @inheritdoc + */ + end(index: number): MapIterator; + /** + * @inheritdoc + */ + rbegin(): MapReverseIterator; + /** + * @inheritdoc + */ + rbegin(index: number): MapReverseIterator; + /** + * @inheritdoc + */ + rend(): MapReverseIterator; + /** + * @inheritdoc + */ + rend(index: number): MapReverseIterator; + /** + * @inheritdoc + */ + bucket_count(): number; + /** + * @inheritdoc + */ + bucket_size(n: number): number; + /** + * @inheritdoc + */ + max_load_factor(): number; + /** + * @inheritdoc + */ + max_load_factor(z: number): void; + /** + * @inheritdoc + */ + bucket(key: Key): number; + /** + * @inheritdoc + */ + reserve(n: number): void; + /** + * @inheritdoc + */ + rehash(n: number): void; + /** + * @hidden + */ + protected _Insert_by_pair(pair: Pair): any; + /** + * @hidden + */ + protected _Insert_by_hint(hint: MapIterator, pair: Pair): MapIterator; + /** + * @hidden + */ + protected _Insert_by_range>>(first: InputIterator, last: InputIterator): void; + /** + * @hidden + */ + protected _Handle_insert(first: MapIterator, last: MapIterator): void; + /** + * @hidden + */ + protected _Handle_erase(first: MapIterator, last: MapIterator): void; + /** + * Swap content. + * + * Exchanges the content of the container by the content of obj, which is another + * {@link HashMultiMap map} of the same type. Sizes abd container type may differ. + * + * After the call to this member function, the elements in this container are those which were + * in obj before the call, and the elements of obj are those which were in this. All + * iterators, references and pointers remain valid for the swapped objects. + * + * Notice that a non-member function exists with the same name, {@link swap swap}, overloading that + * algorithm with an optimization that behaves like this member function. + * + * @param obj Another {@link HashMultiMap map container} of the same type of elements as this (i.e., + * with the same template parameters, Key and T) whose content is swapped + * with that of this {@link HashMultiMap container}. + */ + swap(obj: HashMultiMap): void; + /** + * @inheritdoc + */ + swap(obj: base.Container>): void; + } +} +declare namespace std.HashMultiSet { + type iterator = SetIterator; + type reverse_iterator = SetReverseIterator; +} +declare namespace std { + /** + * Hashed, unordered Multiset. + * + * {@link HashMultiSet HashMultiSets} are containers that store elements in no particular order, allowing fast + * retrieval of individual elements based on their value, much like {@link HashMultiSet} containers, + * but allowing different elements to have equivalent values. + * + * In an {@link HashMultiSet}, the value of an element is at the same time its key, used to + * identify it. Keys are immutable, therefore, the elements in an {@link HashMultiSet} cannot be + * modified once in the container - they can be inserted and removed, though. + * + * Internally, the elements in the {@link HashMultiSet} are not sorted in any particular, but + * organized into buckets depending on their hash values to allow for fast access to individual + * elements directly by their values (with a constant average time complexity on average). + * + * Elements with equivalent values are grouped together in the same bucket and in such a way that an + * iterator can iterate through all of them. Iterators in the container are doubly linked iterators. + * + * + * + * + * ### Container properties + *
+ *
Associative
+ *
Elements in associative containers are referenced by their key and not by their absolute + * position in the container.
+ * + *
Hashed
+ *
Hashed containers organize their elements using hash tables that allow for fast access to elements + * by their key.
+ * + *
Set
+ *
The value of an element is also the key used to identify it.
+ * + *
Multiple equivalent keys
+ *
The container can hold multiple elements with equivalent keys.
+ *
+ * + * @param Type of the elements. + * Each element in an {@link UnorderedMultiSet} is also identified by this value.. + * + * @reference http://www.cplusplus.com/reference/unordered_set/unordered_multiset + * @author Jeongho Nam + */ + class HashMultiSet extends base.MultiSet { + /** + * @hidden + */ + private hash_buckets_; + /** + * Default Constructor. + */ + constructor(); + /** + * Construct from elements. + */ + constructor(items: T[]); + /** + * Copy Constructor. + */ + constructor(container: HashMultiSet); + /** + * Construct from range iterators. + */ + constructor(begin: Iterator, end: Iterator); + /** + * @inheritdoc + */ + clear(): void; + /** + * @inheritdoc + */ + find(key: T): SetIterator; + /** + * @inheritdoc + */ + count(key: T): number; + /** + * @inheritdoc + */ + begin(): SetIterator; + /** + * @inheritdoc + */ + begin(index: number): SetIterator; + /** + * @inheritdoc + */ + end(): SetIterator; + /** + * @inheritdoc + */ + end(index: number): SetIterator; + /** + * @inheritdoc + */ + rbegin(): SetReverseIterator; + /** + * @inheritdoc + */ + rbegin(index: number): SetReverseIterator; + /** + * @inheritdoc + */ + rend(): SetReverseIterator; + /** + * @inheritdoc + */ + rend(index: number): SetReverseIterator; + /** + * @inheritdoc + */ + bucket_count(): number; + /** + * @inheritdoc + */ + bucket_size(n: number): number; + /** + * @inheritdoc + */ + max_load_factor(): number; + /** + * @inheritdoc + */ + max_load_factor(z: number): void; + /** + * @inheritdoc + */ + bucket(key: T): number; + /** + * @inheritdoc + */ + reserve(n: number): void; + /** + * @inheritdoc + */ + rehash(n: number): void; + /** + * @hidden + */ + protected _Insert_by_val(val: T): any; + /** + * @hidden + */ + protected _Insert_by_hint(hint: SetIterator, val: T): SetIterator; + /** + * @hidden + */ + protected _Insert_by_range>(first: InputIterator, last: InputIterator): void; + /** + * @hidden + */ + protected _Handle_insert(first: SetIterator, last: SetIterator): void; + /** + * @hidden + */ + protected _Handle_erase(first: SetIterator, last: SetIterator): void; + /** + * Swap content. + * + * Exchanges the content of the container by the content of obj, which is another + * {@link HashMultiSet set} of the same type. Sizes abd container type may differ. + * + * After the call to this member function, the elements in this container are those which were + * in obj before the call, and the elements of obj are those which were in this. All + * iterators, references and pointers remain valid for the swapped objects. + * + * Notice that a non-member function exists with the same name, {@link swap swap}, overloading that + * algorithm with an optimization that behaves like this member function. + * + * @param obj Another {@link HashMultiSet set container} of the same type of elements as this (i.e., + * with the same template parameters, Key and T) whose content is swapped + * with that of this {@link HashMultiSet container}. + */ + swap(obj: HashMultiSet): void; + /** + * @inheritdoc + */ + swap(obj: base.Container): void; + } +} +declare namespace std.HashSet { + type iterator = SetIterator; + type reverse_iterator = SetReverseIterator; +} +declare namespace std { + /** + * Hashed, unordered set. + * + * {@link HashSet}s are containers that store unique elements in no particular order, and which + * allow for fast retrieval of individual elements based on their value. + * + * In an {@link HashSet}, the value of an element is at the same time its key, that + * identifies it uniquely. Keys are immutable, therefore, the elements in an {@link HashSet} cannot be + * modified once in the container - they can be inserted and removed, though. + * + * Internally, the elements in the {@link HashSet} are not sorted in any particular order, but + * organized into buckets depending on their hash values to allow for fast access to individual elements + * directly by their values (with a constant average time complexity on average). + * + * {@link HashSet} containers are faster than {@link TreeSet} containers to access individual + * elements by their key, although they are generally less efficient for range iteration through a + * subset of their elements. + * + * + * + * + * ### Container properties + *
+ *
Associative
+ *
Elements in associative containers are referenced by their key and not by their absolute + * position in the container.
+ * + *
Hashed
+ *
Hashed containers organize their elements using hash tables that allow for fast access to elements + * by their key.
+ * + *
Set
+ *
The value of an element is also the key used to identify it.
+ * + *
Unique keys
+ *
No two elements in the container can have equivalent keys.
+ *
+ * + * @param Type of the elements. + * Each element in an {@link HashSet} is also uniquely identified by this value. + * + * @reference http://www.cplusplus.com/reference/unordered_set/unordered_set + * @author Jeongho Nam + */ + class HashSet extends base.UniqueSet implements base.IHashSet { + /** + * @hidden + */ + private hash_buckets_; + /** + * Default Constructor. + */ + constructor(); + /** + * Construct from elements. + */ + constructor(items: T[]); + /** + * Copy Constructor. + */ + constructor(container: HashSet); + /** + * Construct from range iterators. + */ + constructor(begin: Iterator, end: Iterator); + /** + * @inheritdoc + */ + clear(): void; + /** + * @inheritdoc + */ + find(key: T): SetIterator; + /** + * @inheritdoc + */ + begin(): SetIterator; + /** + * @inheritdoc + */ + begin(index: number): SetIterator; + /** + * @inheritdoc + */ + end(): SetIterator; + /** + * @inheritdoc + */ + end(index: number): SetIterator; + /** + * @inheritdoc + */ + rbegin(): SetReverseIterator; + /** + * @inheritdoc + */ + rbegin(index: number): SetReverseIterator; + /** + * @inheritdoc + */ + rend(): SetReverseIterator; + /** + * @inheritdoc + */ + rend(index: number): SetReverseIterator; + /** + * @inheritdoc + */ + bucket_count(): number; + /** + * @inheritdoc + */ + bucket_size(n: number): number; + /** + * @inheritdoc + */ + max_load_factor(): number; + /** + * @inheritdoc + */ + max_load_factor(z: number): void; + /** + * @inheritdoc + */ + bucket(key: T): number; + /** + * @inheritdoc + */ + reserve(n: number): void; + /** + * @inheritdoc + */ + rehash(n: number): void; + /** + * @hidden + */ + protected _Insert_by_val(val: T): any; + /** + * @hidden + */ + protected _Insert_by_hint(hint: SetIterator, val: T): SetIterator; + /** + * @hidden + */ + protected _Insert_by_range>(first: InputIterator, last: InputIterator): void; + /** + * @hidden + */ + protected _Handle_insert(first: SetIterator, last: SetIterator): void; + /** + * @hidden + */ + protected _Handle_erase(first: SetIterator, last: SetIterator): void; + /** + * Swap content. + * + * Exchanges the content of the container by the content of obj, which is another + * {@link HashSet set} of the same type. Sizes abd container type may differ. + * + * After the call to this member function, the elements in this container are those which were + * in obj before the call, and the elements of obj are those which were in this. All + * iterators, references and pointers remain valid for the swapped objects. + * + * Notice that a non-member function exists with the same name, {@link swap swap}, overloading that + * algorithm with an optimization that behaves like this member function. + * + * @param obj Another {@link HashSet set container} of the same type of elements as this (i.e., + * with the same template parameters, Key and T) whose content is swapped + * with that of this {@link HashSet container}. + */ + swap(obj: HashSet): void; + /** + * @inheritdoc + */ + swap(obj: base.Container): void; + } +} +declare namespace std { + /** + * Comparable instance. + * + * {@link IComparable} is a common interface for objects who can compare each other. + * + * @reference https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html + * @author Jeongho Nam + */ + interface IComparable extends Object { + /** + * Indicates whether some other object is "equal to" this one. + * + * The {@link equal_to} method implements an equivalence relation on non-null object references: + * + *
    + *
  • + * It is reflexive: for any non-null reference value x, x.equal_to(x) + * should return true. + *
  • + *
  • + * It is symmetric: for any non-null reference values x and y, + * x.equal_to(y) should return true if and only if y.equal_to(x) + * returns true.
  • + *
  • + * It is transitive: for any non-null reference values x, y, and + * z, if x.equal_to(y) returns true and y.equal_to(z) + * returns true, then x.equal_to(z) should return true. + *
  • + *
  • + * It is consistent: for any non-null reference values x and y, multiple + * invocations of x.equal_to(y) consistently return true or consistently return + * false, provided no information used in equal_to comparisons on the objects is modified. + *
  • + *
  • + * For any non-null reference value x, x.equal_to(null) should return + * false. + *
  • + *
+ * + * The {@link equal_to} method for interface {@link IComparable} implements the most discriminating possible + * equivalence relation on objects; that is, for any non-null reference values x and + * y, this method returns true if and only if x and y + * refer to the same object (x == y has the value true). + * + * Note that it is generally necessary to override the {@link hash_code} method whenever this method is + * overridden, so as to maintain the general contract for the {@link hash_code} method, which states that + * equal objects must have equal hash codes. + * + * - {@link IComparable.equal_to} is called by {@link equal_to}. + * + * @param obj the reference object with which to compare. + * + * @return true if this object is the same as the obj argument; false otherwise. + */ + equals(obj: T): boolean; + /** + * Less-than inequality comparison. + * + * Binary method returns whether the the instance compares less than the obj. + * + *
    + *
  • + * {@link IComparable.less} is called by {@link less}. Also, this method can be used on standard + * algorithms such as {@link sort sort()}, {@link merge merge()} or + * {@link TreeMap.lower_bound lower_bound()}. + *
  • + *
+ * + * @param obj the reference object with which to compare. + * + * @return Whether the first parameter is less than the second. + */ + less(obj: T): boolean; + /** + * Issue a hash code. + * + * Returns a hash code value for the object. This method is supported for the benefit of hash tables such + * as those provided by hash containers; {@link HashSet}, {@link HashMap}, {@link MultiHashSet} and + * {@link MultiHashMap}. + * + * As much as is reasonably practical, the {@link hash_code} method defined by interface + * {@link IComparable} does return distinct integers for distinct objects. (This is typically implemented by + * converting the internal address of the object into an integer, but this implementation technique is not + * required by the JavaScript programming language.) + * + *
    + *
  • + * {@link IComparable.hash_code} is called by {@link hash_code}. If you want to keep basically + * provided hash function, then returns {@link Hash.code}; return Hash.code(this); + *
  • + *
+ * + * @return An hash code who represents the object. + */ + hashCode?(): number; + } +} +declare namespace std.List { + type iterator = ListIterator; + type reverse_iterator = ListReverseIterator; +} +declare namespace std { + /** + * Doubly linked list. + * + * {@link List}s are sequence containers that allow constant time insert and erase operations anywhere within the + * sequence, and iteration in both directions. + * + * List containers are implemented as doubly-linked lists; Doubly linked lists can store each of the elements they + * contain in different and unrelated storage locations. The ordering is kept internally by the association to each + * element of a link to the element preceding it and a link to the element following it. + * + * Compared to other base standard sequence containers (array, vector and deque), lists perform generally better + * in inserting, extracting and moving elements in any position within the container for which an iterator has already + * been obtained, and therefore also in algorithms that make intensive use of these, like sorting algorithms. + * + * The main drawback of lists and forward_lists compared to these other sequence containers is that they lack + * direct access to the elements by their position; For example, to access the sixth element in a list, one has to + * iterate from a known position (like the beginning or the end) to that position, which takes linear time in the + * distance between these. They also consume some extra memory to keep the linking information associated to each + * element (which may be an important factor for large lists of small-sized elements). + * + * + * + * + * + * ### Container properties + *
+ *
Sequence
+ *
Elements in sequence containers are ordered in a strict linear sequence. Individual elements are accessed by + * their position in this sequence.
+ * + *
Doubly-linked list
+ *
Each element keeps information on how to locate the next and the previous elements, allowing constant time + * insert and erase operations before or after a specific element (even of entire ranges), but no direct random + * access.
+ *
+ * + * @param Type of the elements. + * + * @reference http://www.cplusplus.com/reference/list/list/ + * @author Jeongho Nam + */ + class List extends base._ListContainer> { + private rend_; + /** + * Default Constructor. + * + * Constructs an empty container, with no elements. + */ + constructor(); + /** + * Initializer list Constructor. + * + * Constructs a container with a copy of each of the elements in array, in the same order. + * + * @param array An array containing elements to be copied and contained. + */ + constructor(items: Array); + /** + * Fill Constructor. + * + * Constructs a container with n elements. Each element is a copy of val (if provided). + * + * @param n Initial container size (i.e., the number of elements in the container at construction). + * @param val Value to fill the container with. Each of the n elements in the container is + * initialized to a copy of this value. + */ + constructor(size: number, val: T); + /** + * Copy Constructor. + * + * Constructs a container with a copy of each of the elements in container, in the same order. + * + * @param container Another container object of the same type (with the same class template + * arguments T), whose contents are either copied or acquired. + */ + constructor(container: List); + /** + * Range Constructor. + * + * Constructs a container with as many elements as the range (begin, end), with each + * element emplace-constructed from its corresponding element in that range, in the same order. + * + * @param begin Input interator of the initial position in a sequence. + * @param end Input interator of the final position in a sequence. + */ + constructor(begin: Iterator, end: Iterator); + /** + * @hidden + */ + protected _Create_iterator(prev: ListIterator, next: ListIterator, val: T): ListIterator; + /** + * @hidden + */ + protected _Set_begin(it: ListIterator): void; + /** + * @inheritdoc + */ + assign(n: number, val: T): void; + /** + * @inheritdoc + */ + assign>(begin: InputIterator, end: InputIterator): void; + /** + * @inheritdoc + */ + rbegin(): ListReverseIterator; + /** + * @inheritdoc + */ + rend(): ListReverseIterator; + /** + * @inheritdoc + */ + front(): T; + /** + * @inheritdoc + */ + back(): T; + /** + * Insert an element. + * + * The container is extended by inserting a new element before the element at the specified + * position. This effectively increases the {@link List.size List size} by the amount of elements + * inserted. + * + * Unlike other standard sequence containers, {@link List} is specifically designed to be efficient + * inserting and removing elements in any position, even in the middle of the sequence. + * + * @param position Position in the container where the new element is inserted. + * {@link iterator}> is a member type, defined as a + * {@link ListIterator bidirectional iterator} type that points to elements. + * @param val Value to be inserted as an element. + * + * @return An iterator that points to the newly inserted element; val. + */ + insert(position: ListIterator, val: T): ListIterator; + /** + * Insert elements by repeated filling. + * + * The container is extended by inserting a new element before the element at the specified + * position. This effectively increases the {@link List.size List size} by the amount of elements + * inserted. + * + * Unlike other standard sequence containers, {@link List} is specifically designed to be efficient + * inserting and removing elements in any position, even in the middle of the sequence. + * + * @param position Position in the container where the new elements are inserted. The {@link iterator} is a + * member type, defined as a {@link ListIterator bidirectional iterator} type that points to + * elements. + * @param size Number of elements to insert. + * @param val Value to be inserted as an element. + * + * @return An iterator that points to the first of the newly inserted elements. + */ + insert(position: ListIterator, size: number, val: T): ListIterator; + /** + * Insert elements by range iterators. + * + * The container is extended by inserting a new element before the element at the specified + * position. This effectively increases the {@link List.size List size} by the amount of elements + * inserted. + * + * Unlike other standard sequence containers, {@link List} is specifically designed to be efficient + * inserting and removing elements in any position, even in the middle of the sequence. + * + * @param position Position in the container where the new elements are inserted. The {@link iterator} is a + * member type, defined as a {@link ListIterator bidirectional iterator} type that points to + * elements. + * @param begin An iterator specifying range of the begining element. + * @param end An iterator specifying range of the ending element. + * + * @return An iterator that points to the first of the newly inserted elements. + */ + insert>(position: ListIterator, begin: InputIterator, end: InputIterator): ListIterator; + /** + * Insert an element. + * + * The container is extended by inserting a new element before the element at the specified + * position. This effectively increases the {@link List.size List size} by the amount of elements + * inserted. + * + * Unlike other standard sequence containers, {@link List} is specifically designed to be efficient + * inserting and removing elements in any position, even in the middle of the sequence. + * + * @param position Position in the container where the new element is inserted. + * {@link iterator}> is a member type, defined as a + * {@link ListReverseIterator bidirectional iterator} type that points to elements. + * @param val Value to be inserted as an element. + * + * @return An iterator that points to the newly inserted element; val. + */ + insert(position: ListReverseIterator, val: T): ListReverseIterator; + /** + * Insert elements by repeated filling. + * + * The container is extended by inserting a new element before the element at the specified + * position. This effectively increases the {@link List.size List size} by the amount of elements + * inserted. + * + * Unlike other standard sequence containers, {@link List} is specifically designed to be efficient + * inserting and removing elements in any position, even in the middle of the sequence. + * + * @param position Position in the container where the new elements are inserted. The {@link iterator} is a + * member type, defined as a {@link ListReverseIterator bidirectional iterator} type that points to + * elements. + * @param size Number of elements to insert. + * @param val Value to be inserted as an element. + * + * @return An iterator that points to the first of the newly inserted elements. + */ + insert(position: ListReverseIterator, size: number, val: T): ListReverseIterator; + /** + * Insert elements by range iterators. + * + * The container is extended by inserting a new element before the element at the specified + * position. This effectively increases the {@link List.size List size} by the amount of elements + * inserted. + * + * Unlike other standard sequence containers, {@link List} is specifically designed to be efficient + * inserting and removing elements in any position, even in the middle of the sequence. + * + * @param position Position in the container where the new elements are inserted. The {@link iterator} is a + * member type, defined as a {@link ListReverseIterator bidirectional iterator} type that points to + * elements. + * @param begin An iterator specifying range of the begining element. + * @param end An iterator specifying range of the ending element. + * + * @return An iterator that points to the first of the newly inserted elements. + */ + insert>(position: ListReverseIterator, begin: InputIterator, end: InputIterator): ListReverseIterator; + /** + * Erase an element. + * + * Removes from the {@link List} either a single element; position. + * + * This effectively reduces the container size by the number of element removed. + * + * Unlike other standard sequence containers, {@link List} objects are specifically designed to be + * efficient inserting and removing elements in any position, even in the middle of the sequence. + * + * @param position Iterator pointing to a single element to be removed from the {@link List}. + * + * @return An iterator pointing to the element that followed the last element erased by the function call. + * This is the {@link end end()} if the operation erased the last element in the sequence. + */ + erase(position: ListIterator): ListIterator; + /** + * Erase elements. + * + * Removes from the {@link List} container a range of elements. + * + * This effectively reduces the container {@link size} by the number of elements removed. + * + * Unlike other standard sequence containers, {@link List} objects are specifically designed to be + * efficient inserting and removing elements in any position, even in the middle of the sequence. + * + * @param begin An iterator specifying a range of beginning to erase. + * @param end An iterator specifying a range of end to erase. + * + * @return An iterator pointing to the element that followed the last element erased by the function call. + * This is the {@link end end()} if the operation erased the last element in the sequence. + */ + erase(begin: ListIterator, end: ListIterator): ListIterator; + /** + * Erase an element. + * + * Removes from the {@link List} either a single element; position. + * + * This effectively reduces the container size by the number of element removed. + * + * Unlike other standard sequence containers, {@link List} objects are specifically designed to be + * efficient inserting and removing elements in any position, even in the middle of the sequence. + * + * @param position Iterator pointing to a single element to be removed from the {@link List}. + * + * @return An iterator pointing to the element that followed the last element erased by the function call. + * This is the {@link rend rend()} if the operation erased the last element in the sequence. + */ + erase(position: ListReverseIterator): ListReverseIterator; + /** + * Erase elements. + * + * Removes from the {@link List} container a range of elements. + * + * This effectively reduces the container {@link size} by the number of elements removed. + * + * Unlike other standard sequence containers, {@link List} objects are specifically designed to be + * efficient inserting and removing elements in any position, even in the middle of the sequence. + * + * @param begin An iterator specifying a range of beginning to erase. + * @param end An iterator specifying a range of end to erase. + * + * @return An iterator pointing to the element that followed the last element erased by the function call. + * This is the {@link rend rend()} if the operation erased the last element in the sequence. + */ + erase(begin: ListReverseIterator, end: ListReverseIterator): ListReverseIterator; + /** + * Remove duplicate values. + * + * Removes all but the first element from every consecutive group of equal elements in the + * + * Notice that an element is only removed from the {@link List} container if it compares equal to the + * element immediately preceding it. Thus, this function is especially useful for sorted lists. + */ + unique(): void; + /** + * Remove duplicate values. + * + * Removes all but the first element from every consecutive group of equal elements in the + * + * The argument binary_pred is a specific comparison function that determine the uniqueness + * of an element. In fact, any behavior can be implemented (and not only an equality comparison), but notice + * that the function will call binary_pred(it.value, it.prev().value) for all pairs of elements + * (where it is an iterator to an element, starting from the second) and remove it + * from the {@link List} if the predicate returns true. + * + * Notice that an element is only removed from the {@link List} container if it compares equal to the + * element immediately preceding it. Thus, this function is especially useful for sorted lists. + * + * @param binary_pred Binary predicate that, taking two values of the same type than those contained in the + * {@link List}, returns true to remove the element passed as first argument + * from the container, and false otherwise. This shall be a function pointer + * or a function object. + */ + unique(binary_pred: (left: T, right: T) => boolean): void; + /** + * Remove elements with specific value. + * + * Removes from the container all the elements that compare equal to val. This calls the + * destructor of these objects and reduces the container {@link size} by the number of elements removed. + * + * Unlike member function {@link List.erase}, which erases elements by their position (using an + * iterator), this function ({@link List.remove}) removes elements by their value. + * + * A similar function, {@link List.remove_if}, exists, which allows for a condition other than an + * equality comparison to determine whether an element is removed. + * + * @param val Value of the elements to be removed. + */ + remove(val: T): void; + /** + * Remove elements fulfilling condition. + * + * Removes from the container all the elements for which pred returns true. This + * calls the destructor of these objects and reduces the container {@link size} by the number of elements + * removed. + * + * The function calls pred(it.value) for each element (where it is an iterator + * to that element). Any of the elements in the list for which this returns true, are removed + * from the + * + * @param pred Unary predicate that, taking a value of the same type as those contained in the forward_list + * object, returns true for those values to be removed from the container, and + * false for those remaining. This can either be a function pointer or a function + * object. + */ + remove_if(pred: (val: T) => boolean): void; + /** + * Merge sorted {@link List Lists}. + * + * Merges obj into the {@link List} by transferring all of its elements at their respective + * ordered positions into the container (both containers shall already be ordered). + * + * + * This effectively removes all the elements in obj (which becomes {@link empty}), and inserts + * them into their ordered position within container (which expands in {@link size} by the number of elements + * transferred). The operation is performed without constructing nor destroying any element: they are + * transferred, no matter whether obj is an lvalue or an rvalue, or whether the value_type supports + * move-construction or not. + * + * This function requires that the {@link List} containers have their elements already ordered by value + * ({@link less}) before the call. For an alternative on unordered {@link List Lists}, see + * {@link List.splice}. + * + * Assuming such ordering, each element of obj is inserted at the position that corresponds to its + * value according to the strict weak ordering defined by {@link less}. The resulting order of equivalent + * elements is stable (i.e., equivalent elements preserve the relative order they had before the call, and + * existing elements precede those equivalent inserted from obj). + * + * The function does nothing if this == obj. + * + * @param obj A {@link List} object of the same type (i.e., with the same template parameters, T). + * Note that this function modifies obj no matter whether an lvalue or rvalue reference is + * passed. + */ + merge(obj: List): void; + /** + * Merge sorted {@link List Lists}. + * + * Merges obj into the {@link List} by transferring all of its elements at their respective + * ordered positions into the container (both containers shall already be ordered). + * + * + * This effectively removes all the elements in obj (which becomes {@link empty}), and inserts + * them into their ordered position within container (which expands in {@link size} by the number of elements + * transferred). The operation is performed without constructing nor destroying any element: they are + * transferred, no matter whether obj is an lvalue or an rvalue, or whether the value_type supports + * move-construction or not. + * + * The argument compare is a specific predicate to perform the comparison operation between + * elements. This comparison shall produce a strict weak ordering of the elements (i.e., a consistent + * transitive comparison, without considering its reflexiveness). + * + * This function requires that the {@link List} containers have their elements already ordered by + * compare before the call. For an alternative on unordered {@link List Lists}, see + * {@link List.splice}. + * + * Assuming such ordering, each element of obj is inserted at the position that corresponds to its + * value according to the strict weak ordering defined by compare. The resulting order of equivalent + * elements is stable (i.e., equivalent elements preserve the relative order they had before the call, and + * existing elements precede those equivalent inserted from obj). + * + * The function does nothing if this == obj. + * + * @param obj A {@link List} object of the same type (i.e., with the same template parameters, T). + * Note that this function modifies obj no matter whether an lvalue or rvalue reference is + * passed. + * @param compare Binary predicate that, taking two values of the same type than those contained in the + * {@link list}, returns true if the first argument is considered to go before + * the second in the strict weak ordering it defines, and false otherwise. + * This shall be a function pointer or a function object. + */ + merge(obj: List, compare: (left: T, right: T) => boolean): void; + /** + * Transfer elements from {@link List} to {@link List}. + * + * Transfers elements from obj into the container, inserting them at position. + * + * This effectively inserts all elements into the container and removes them from obj, altering + * the sizes of both containers. The operation does not involve the construction or destruction of any + * element. They are transferred, no matter whether obj is an lvalue or an rvalue, or whether the + * value_type supports move-construction or not. + * + * This first version (1) transfers all the elements of obj into the + * + * @param position Position within the container where the elements of obj are inserted. + * @param obj A {@link List} object of the same type (i.e., with the same template parameters, T). + */ + splice(position: ListIterator, obj: List): void; + /** + * Transfer an element from {@link List} to {@link List}. + * + * Transfers an element from obj, which is pointed by an {@link ListIterator iterator} it, + * into the container, inserting the element at specified position. + * + * This effectively inserts an element into the container and removes it from obj, altering the + * sizes of both containers. The operation does not involve the construction or destruction of any element. + * They are transferred, no matter whether obj is an lvalue or an rvalue, or whether the value_type + * supports move-construction or not. + * + * This second version (2) transfers only the element pointed by it from obj into the + * + * + * @param position Position within the container where the element of obj is inserted. + * @param obj A {@link List} object of the same type (i.e., with the same template parameters, T). + * This parameter may be this if position points to an element not actually + * being spliced. + * @param it {@link ListIterator Iterator} to an element in obj. Only this single element is + * transferred. + */ + splice(position: ListIterator, obj: List, it: ListIterator): void; + /** + * Transfer elements from {@link List} to {@link List}. + * + * Transfers elements from obj into the container, inserting them at position. + * + * This effectively inserts those elements into the container and removes them from obj, altering + * the sizes of both containers. The operation does not involve the construction or destruction of any + * element. They are transferred, no matter whether obj is an lvalue or an rvalue, or whether the + * value_type supports move-construction or not. + * + * This third version (3) transfers the range [begin, end) from obj into the + * + * + * @param position Position within the container where the elements of obj are inserted. + * @param obj A {@link List} object of the same type (i.e., with the same template parameters, T). + * This parameter may be this if position points to an element not actually + * being spliced. + * @param begin {@link ListIterator An Iterator} specifying initial position of a range of elements in + * obj. Transfers the elements in the range [begin, end) to + * position. + * @param end {@link ListIterator An Iterator} specifying final position of a range of elements in + * obj. Transfers the elements in the range [begin, end) to + * position. Notice that the range includes all the elements between begin and + * end, including the element pointed by begin but not the one pointed by end. + */ + splice(position: ListIterator, obj: List, begin: ListIterator, end: ListIterator): void; + /** + * Sort elements in + * + * Sorts the elements in the {@link List}, altering their position within the + * + * The sorting is performed by applying an algorithm that uses {@link less}. This comparison shall + * produce a strict weak ordering of the elements (i.e., a consistent transitive comparison, without + * considering its reflexiveness). + * + * The resulting order of equivalent elements is stable: i.e., equivalent elements preserve the relative + * order they had before the call. + * + * The entire operation does not involve the construction, destruction or copy of any element object. + * Elements are moved within the + */ + sort(): void; + /** + * Sort elements in + * + * Sorts the elements in the {@link List}, altering their position within the + * + * The sorting is performed by applying an algorithm that uses compare. This comparison shall + * produce a strict weak ordering of the elements (i.e., a consistent transitive comparison, without + * considering its reflexiveness). + * + * The resulting order of equivalent elements is stable: i.e., equivalent elements preserve the relative + * order they had before the call. + * + * The entire operation does not involve the construction, destruction or copy of any element object. + * Elements are moved within the + * + * @param compare Binary predicate that, taking two values of the same type of those contained in the + * {@link List}, returns true if the first argument goes before the second + * argument in the strict weak ordering it defines, and false otherwise. This + * shall be a function pointer or a function object. + */ + sort(compare: (left: T, right: T) => boolean): void; + /** + * @hidden + */ + private _Quick_sort(first, last, compare); + /** + * @hidden + */ + private _Quick_sort_partition(first, last, compare); + /** + * Reverse the order of elements. + * + * Reverses the order of the elements in the list container. + */ + reverse(): void; + /** + * Swap content. + * + * Exchanges the content of the container by the content of obj, which is another + * {@link List container} object with same type of elements. Sizes and container type may differ. + * + * After the call to this member function, the elements in this container are those which were in obj + * before the call, and the elements of obj are those which were in this. All iterators, references and + * pointers remain valid for the swapped objects. + * + * Notice that a non-member function exists with the same name, {@link swap swap}, overloading that + * algorithm with an optimization that behaves like this member function. + * + * @param obj Another {@link List container} of the same type of elements (i.e., instantiated + * with the same template parameter, T) whose content is swapped with that of this + * {@link List container}. + */ + swap(obj: List): void; + /** + * @inheritdoc + */ + swap(obj: base.Container): void; + } +} +declare namespace std { + /** + * An iterator, node of a List. + * + * + * + * + * @author Jeongho Nam + */ + class ListIterator extends base._ListIteratorBase { + /** + * Initializer Constructor. + * + * #### Note + * Do not create the iterator directly, by yourself. + * + * Use {@link List.begin begin()}, {@link List.end end()} in {@link List container} instead. + * + * @param source The source {@link List container} to reference. + * @param prev A refenrece of previous node ({@link ListIterator iterator}). + * @param next A refenrece of next node ({@link ListIterator iterator}). + * @param value Value to be stored in the node (iterator). + */ + constructor(source: List, prev: ListIterator, next: ListIterator, value: T); + /** + * @inheritdoc + */ + source(): List; + /** + * @inheritdoc + */ + /** + * Set value of the iterator is pointing to. + * + * @param val Value to set. + */ + value: T; + /** + * @inheritdoc + */ + prev(): ListIterator; + /** + * @inheritdoc + */ + next(): ListIterator; + /** + * @inheritdoc + */ + advance(step: number): ListIterator; + /** + * @inheritdoc + */ + equals(obj: ListIterator): boolean; + /** + * @inheritdoc + */ + swap(obj: ListIterator): void; + } +} +declare namespace std { + /** + * A reverse-iterator of List. + * + * + * + * + * @param Type of the elements. + * + * @author Jeongho Nam + */ + class ListReverseIterator extends ReverseIterator, ListIterator, ListReverseIterator> implements base.ILinearIterator { + /** + * Construct from base iterator. + * + * @param base A reference of the base iterator, which iterates in the opposite direction. + */ + constructor(base: ListIterator); + /** + * @hidden + */ + protected _Create_neighbor(base: ListIterator): ListReverseIterator; + /** + * @inheritdoc + */ + /** + * Set value of the iterator is pointing to. + * + * @param val Value to set. + */ + value: T; + } +} +declare namespace std.Vector { + type iterator = VectorIterator; + type reverse_iterator = VectorReverseIterator; +} +declare namespace std { + /** + * Vector, the dynamic array. + * + * {@link Vector}s are sequence containers representing arrays that can change in size. + * + * Just like arrays, {@link Vector}s use contiguous storage locations for their elements, which means that + * their elements can also be accessed using offsets on regular pointers to its elements, and just as efficiently + * as in arrays. But unlike arrays, their size can change dynamically, with their storage being handled + * automatically by the container. + * + * Internally, {@link Vector}s use a dynamically allocated array to store their elements. This array may need + * to be reallocated in order to grow in size when new elements are inserted, which implies allocating a new + * array and moving all elements to it. This is a relatively expensive task in terms of processing time, and + * thus, {@link Vector}s do not reallocate each time an element is added to the container. + * + * Compared to the other dynamic sequence containers ({@link Deque}s, {@link List}s), {@link Vector Vectors} + * are very efficient accessing its elements (just like arrays) and relatively efficient adding or removing + * elements from its end. For operations that involve inserting or removing elements at positions other than the + * end, they perform worse than the others, and have less consistent iterators and references than {@link List}s. + * + * + * + * + * + * ### Container properties + *
+ *
Sequence
+ *
+ * Elements in sequence containers are ordered in a strict linear sequence. Individual elements are + * accessed by their position in this sequence. + *
+ * + *
Dynamic array
+ *
+ * Allows direct access to any element in the sequence, even through pointer arithmetics, and provides + * relatively fast addition/removal of elements at the end of the sequence. + *
+ *
+ * + * @param Type of the elements. + * + * @reference http://www.cplusplus.com/reference/vector/vector + * @author Jeongho Nam + */ + class Vector extends base.Container implements base.IArrayContainer { + /** + * @hidden + */ + private data_; + /** + * @hidden + */ + private begin_; + /** + * @hidden + */ + private end_; + /** + * @hidden + */ + private rend_; + /** + * Default Constructor. + * + * Constructs an empty container, with no elements. + */ + constructor(); + /** + * @inheritdoc + */ + constructor(array: Array); + /** + * Initializer list Constructor. + * + * Constructs a container with a copy of each of the elements in array, in the same order. + * + * @param array An array containing elements to be copied and contained. + */ + constructor(n: number); + /** + * Fill Constructor. + * + * Constructs a container with n elements. Each element is a copy of val (if provided). + * + * @param n Initial container size (i.e., the number of elements in the container at construction). + * @param val Value to fill the container with. Each of the n elements in the container is + * initialized to a copy of this value. + */ + constructor(n: number, val: T); + /** + * Copy Constructor. + * + * Constructs a container with a copy of each of the elements in container, in the same order. + * + * @param container Another container object of the same type (with the same class template + * arguments T), whose contents are either copied or acquired. + */ + constructor(container: Vector); + /** + * Range Constructor. + * + * Constructs a container with as many elements as the range (begin, end), with each + * element emplace-constructed from its corresponding element in that range, in the same order. + * + * @param begin Input interator of the initial position in a sequence. + * @param end Input interator of the final position in a sequence. + */ + constructor(begin: Iterator, end: Iterator); + /** + * @inheritdoc + */ + assign>(begin: InputIterator, end: InputIterator): void; + /** + * @inheritdoc + */ + assign(n: number, val: T): void; + /** + * @inheritdoc + */ + clear(): void; + /** + * @inheritdoc + */ + begin(): VectorIterator; + /** + * @inheritdoc + */ + end(): VectorIterator; + /** + * @inheritdoc + */ + rbegin(): VectorReverseIterator; + /** + * @inheritdoc + */ + rend(): VectorReverseIterator; + /** + * @inheritdoc + */ + size(): number; + /** + * @inheritdoc + */ + empty(): boolean; + /** + * @inheritdoc + */ + at(index: number): T; + /** + * @inheritdoc + */ + set(index: number, val: T): T; + /** + * @inheritdoc + */ + front(): T; + /** + * @inheritdoc + */ + back(): T; + /** + * Access data. + * + * Returns a direct array which is used internally by the {@link vector} to store its owned elements. + * + * @returns An array. + */ + data(): Array; + /** + * @inheritdoc + */ + push(...items: T[]): number; + /** + * @inheritdoc + */ + push_back(val: T): void; + /** + * Insert an element. + * + * The {@link Vector} is extended by inserting new element before the element at the specified + * position, effectively increasing the container size by one. + * + * Because {@link Vector}s use an Array as their underlying storage, inserting element in + * positions other than the {@link end end()} causes the container to relocate all the elements that were + * after position to its new position. This is generally an inefficient operation compared to the one + * performed for the same operation by other kinds of sequence containers (such as {@link List}). + * + * @param position Position in the {@link Vector} where the new element is inserted. + * {@link iterator} is a member type, defined as a + * {@link VectorIterator random access iterator} type that points to elements. + * @param val Value to be copied to the inserted element. + * + * @return An iterator that points to the newly inserted element. + */ + insert(position: VectorIterator, val: T): VectorIterator; + /** + * Insert elements by repeated filling. + * + * The {@link Vector} is extended by inserting new elements before the element at the specified + * position, effectively increasing the container size by the number of elements inserted. + * + * Because {@link Vector}s use an Array as their underlying storage, inserting elements in + * positions other than the {@link end end()} causes the container to relocate all the elements that were + * after position to their new positions. This is generally an inefficient operation compared to the + * one performed for the same operation by other kinds of sequence containers (such as {@link List}). + * + * @param position Position in the {@link Vector} where the new elements are inserted. + * {@link iterator} is a member type, defined as a + * {@link VectorIterator random access iterator} type that points to elements. + * @param n Number of elements to insert. Each element is initialized to a copy of val. + * @param val Value to be copied (or moved) to the inserted elements. + * + * @return An iterator that points to the first of the newly inserted elements. + */ + insert(position: VectorIterator, n: number, val: T): VectorIterator; + /** + * Insert elements by range iterators. + * + * The {@link Vector} is extended by inserting new elements before the element at the specified + * position, effectively increasing the container size by the number of elements inserted by range + * iterators. + * + * Because {@link Vector}s use an Array as their underlying storage, inserting elements in + * positions other than the {@link end end()} causes the container to relocate all the elements that were + * after position to their new positions. This is generally an inefficient operation compared to the + * one performed for the same operation by other kinds of sequence containers (such as {@link List}). + * + * @param position Position in the {@link Vector} where the new elements are inserted. + * {@link iterator} is a member type, defined as a + * {@link VectorIterator random access iterator} type that points to elements. + * @param begin Input interator of the initial position in a sequence. + * @param end Input interator of the final position in a sequence. + * + * @return An iterator that points to the first of the newly inserted elements. + */ + insert>(position: VectorIterator, begin: InputIterator, end: InputIterator): VectorIterator; + /** + * Insert an element. + * + * The {@link Vector} is extended by inserting new element before the element at the specified + * position, effectively increasing the container size by one. + * + * Because {@link Vector}s use an Array as their underlying storage, inserting element in + * positions other than the {@link end end()} causes the container to relocate all the elements that were + * after position to its new position. This is generally an inefficient operation compared to the one + * performed for the same operation by other kinds of sequence containers (such as {@link List}). + * + * @param position Position in the {@link Vector} where the new element is inserted. + * {@link iterator} is a member type, defined as a + * {@link VectorIterator random access iterator} type that points to elements. + * @param val Value to be copied to the inserted element. + * + * @return An iterator that points to the newly inserted element. + */ + insert(position: VectorReverseIterator, val: T): VectorReverseIterator; + /** + * Insert elements by repeated filling. + * + * The {@link Vector} is extended by inserting new elements before the element at the specified + * position, effectively increasing the container size by the number of elements inserted. + * + * Because {@link Vector}s use an Array as their underlying storage, inserting elements in + * positions other than the {@link end end()} causes the container to relocate all the elements that were + * after position to their new positions. This is generally an inefficient operation compared to the + * one performed for the same operation by other kinds of sequence containers (such as {@link List}). + * + * @param position Position in the {@link Vector} where the new elements are inserted. + * {@link iterator} is a member type, defined as a + * {@link VectorIterator random access iterator} type that points to elements. + * @param n Number of elements to insert. Each element is initialized to a copy of val. + * @param val Value to be copied (or moved) to the inserted elements. + * + * @return An iterator that points to the first of the newly inserted elements. + */ + insert(position: VectorReverseIterator, n: number, val: T): VectorReverseIterator; + /** + * Insert elements by range iterators. + * + * The {@link Vector} is extended by inserting new elements before the element at the specified + * position, effectively increasing the container size by the number of elements inserted by range + * iterators. + * + * Because {@link Vector}s use an Array as their underlying storage, inserting elements in + * positions other than the {@link end end()} causes the container to relocate all the elements that were + * after position to their new positions. This is generally an inefficient operation compared to the + * one performed for the same operation by other kinds of sequence containers (such as {@link List}). + * + * @param position Position in the {@link Vector} where the new elements are inserted. + * {@link iterator} is a member type, defined as a + * {@link VectorIterator random access iterator} type that points to elements. + * @param begin Input interator of the initial position in a sequence. + * @param end Input interator of the final position in a sequence. + * + * @return An iterator that points to the first of the newly inserted elements. + */ + insert>(position: VectorReverseIterator, begin: InputIterator, end: InputIterator): VectorReverseIterator; + /** + * @hidden + */ + private _Insert_by_val(position, val); + /** + * @hidden + */ + private _Insert_by_repeating_val(position, n, val); + /** + * @hidden + */ + protected _Insert_by_range>(position: VectorIterator, first: InputIterator, last: InputIterator): VectorIterator; + /** + * @inheritdoc + */ + pop_back(): void; + /** + * Erase element. + * + * Removes from the {@link Vector} either a single element; position. + * + * This effectively reduces the container size by the number of element removed. + * + * Because {@link Vector}s use an Array as their underlying storage, erasing an element in + * position other than the {@link end end()} causes the container to relocate all the elements after the + * segment erased to their new positions. This is generally an inefficient operation compared to the one + * performed for the same operation by other kinds of sequence containers (such as {@link List}). + * + * @param position Iterator pointing to a single element to be removed from the {@link Vector}. + * + * @return An iterator pointing to the new location of the element that followed the last element erased by + * the function call. This is the {@link end end()} if the operation erased the last element in the + * sequence. + */ + erase(position: VectorIterator): VectorIterator; + /** + * Erase element. + * + * Removes from the Vector either a single element; position. + * + * This effectively reduces the container size by the number of elements removed. + * + * Because {@link Vector}s use an Array as their underlying storage, erasing elements in + * position other than the {@link end end()} causes the container to relocate all the elements after the + * segment erased to their new positions. This is generally an inefficient operation compared to the one + * performed for the same operation by other kinds of sequence containers (such as {@link List}). + * + * @param begin An iterator specifying a range of beginning to erase. + * @param end An iterator specifying a range of end to erase. + * + * @return An iterator pointing to the new location of the element that followed the last element erased by + * the function call. This is the {@link rend rend()} if the operation erased the last element in the + * sequence. + */ + erase(first: VectorIterator, last: VectorIterator): VectorIterator; + /** + * Erase element. + * + * Removes from the {@link Vector} either a single element; position. + * + * This effectively reduces the container size by the number of element removed. + * + * Because {@link Vector}s use an Array as their underlying storage, erasing an element in + * position other than the {@link end end()} causes the container to relocate all the elements after the + * segment erased to their new positions. This is generally an inefficient operation compared to the one + * performed for the same operation by other kinds of sequence containers (such as {@link List}). + * + * @param position Iterator pointing to a single element to be removed from the {@link Vector}. + * + * @return An iterator pointing to the new location of the element that followed the last element erased by + * the function call. This is the {@link rend rend()} if the operation erased the last element in the + * sequence. + */ + erase(position: VectorReverseIterator): VectorReverseIterator; + /** + * Erase element. + * + * Removes from the Vector either a single element; position. + * + * This effectively reduces the container size by the number of elements removed. + * + * Because {@link Vector}s use an Array as their underlying storage, erasing elements in + * position other than the {@link end end()} causes the container to relocate all the elements after the + * segment erased to their new positions. This is generally an inefficient operation compared to the one + * performed for the same operation by other kinds of sequence containers (such as {@link List}). + * + * @param begin An iterator specifying a range of beginning to erase. + * @param end An iterator specifying a range of end to erase. + * + * @return An iterator pointing to the new location of the element that followed the last element erased by + * the function call. This is the {@link end end()} if the operation erased the last element in the + * sequence. + */ + erase(first: VectorReverseIterator, last: VectorReverseIterator): VectorReverseIterator; + /** + * @hidden + */ + protected _Erase_by_range(first: VectorIterator, last: VectorIterator): VectorIterator; + /** + * Swap content. + * + * Exchanges the content of the container by the content of obj, which is another + * {@link Vector container} object with same type of elements. Sizes and container type may differ. + * + * After the call to this member function, the elements in this container are those which were in obj + * before the call, and the elements of obj are those which were in this. All iterators, references and + * pointers remain valid for the swapped objects. + * + * Notice that a non-member function exists with the same name, {@link swap swap}, overloading that + * algorithm with an optimization that behaves like this member function. + * + * @param obj Another {@link Vector container} of the same type of elements (i.e., instantiated + * with the same template parameter, T) whose content is swapped with that of this + * {@link Vector container}. + */ + swap(obj: Vector): void; + /** + * @inheritdoc + */ + swap(obj: base.Container): void; + } +} +declare namespace std { + /** + * An iterator of Vector. + * + * + * + * + * @param Type of the elements. + * + * @author Jeongho Nam + */ + class VectorIterator extends Iterator implements base.IArrayIterator { + /** + * @hidden + */ + private index_; + /** + * Construct from the source {@link Vector container}. + * + * #### Note + * Do not create the iterator directly, by yourself. + * + * Use {@link Vector.begin begin()}, {@link Vector.end end()} in {@link Vector container} instead. + * + * @param source The source {@link Vector container} to reference. + * @param index Sequence number of the element in the source {@link Vector}. + */ + constructor(source: Vector, index: number); + /** + * @inheritdoc + */ + source(): Vector; + /** + * @inheritdoc + */ + index(): number; + /** + * @inheritdoc + */ + /** + * Set value of the iterator is pointing to. + * + * @param val Value to set. + */ + value: T; + /** + * @inheritdoc + */ + prev(): VectorIterator; + /** + * @inheritdoc + */ + next(): VectorIterator; + /** + * @inheritdoc + */ + advance(n: number): VectorIterator; + /** + * @inheritdoc + */ + equals(obj: VectorIterator): boolean; + /** + * @inheritdoc + */ + swap(obj: VectorIterator): void; + } +} +declare namespace std { + /** + * A reverse-iterator of Vector. + * + * + * + * + * @param Type of the elements. + * + * @author Jeongho Nam + */ + class VectorReverseIterator extends ReverseIterator, VectorIterator, VectorReverseIterator> implements base.IArrayIterator { + /** + * Construct from base iterator. + * + * @param base A reference of the base iterator, which iterates in the opposite direction. + */ + constructor(base: VectorIterator); + /** + * @hidden + */ + protected _Create_neighbor(base: VectorIterator): VectorReverseIterator; + /** + * @inheritdoc + */ + index(): number; + /** + * @inheritdoc + */ + /** + * Set value of the iterator is pointing to. + * + * @param val Value to set. + */ + value: T; + } +} +declare namespace std { + /** + * FIFO queue. + * + * {@link Queue}s are a type of container adaptor, specifically designed to operate in a FIFO context + * (first-in first-out), where elements are inserted into one end of the container and extracted from the other. + * + * {@link Queue}s are implemented as containers adaptors, which are classes that use an encapsulated object of + * a specific container class as its underlying container, providing a specific set of member functions to access + * its elements. Elements are pushed into the {@link IDeque.back back()} of the specific container and popped from + * its {@link IDeque.front front()}. + * + * {@link container_ The underlying container} may be one of the standard container class template or some + * other specifically designed container class. This underlying container shall support at least the following + * operations: + * + * - {@link IDequeContainer.empty empty} + * - {@link IDequeContainer.size size} + * - {@link IDequeContainer.front front} + * - {@link IDequeContainer.back back} + * - {@link IDequeContainer.push_back push_back} + * - {@link IDequeContainer.pop_front pop_front} + * + * The standard container classes {@link Deque} and {@link List} fulfill these requirements. + * By default, if no container class is specified for a particular {@link Queue} class instantiation, the standard + * container {@link List} is used. + * + * + * + * + * @param Type of elements. + * + * @reference http://www.cplusplus.com/reference/queue/queue + * @author Jeongho Nam + */ + class Queue { + /** + * The underlying object for implementing the FIFO + */ + private container_; + /** + * Default Constructor. + */ + constructor(); + /** + * Copy Constructor. + */ + constructor(container: Queue); + /** + * Return size. + * + * Returns the number of elements in the {@link Queue}. + * + * This member function effectively calls member {@link IDeque.size size()} of the + * {@link container_ underlying container} object. + * + * @return The number of elements in the {@link container_ underlying container}. + */ + size(): number; + /** + * Test whether container is empty. + * + * returns whether the {@link Queue} is empty: i.e. whether its size is zero. + * + * This member function efeectively calls member {@link IDeque.empty empty()} of the + * {@link container_ underlying container} object. + * + * @return true if the {@link container_ underlying container}'s size is 0, + * false otherwise. + */ + empty(): boolean; + /** + * Access next element. + * + * Returns a value of the next element in the {@link Queue}. + * + * The next element is the "oldest" element in the {@link Queue} and the same element that is popped out + * from the queue when {@link pop Queue.pop()} is called. + * + * This member function effectively calls member {@link IDeque.front front()} of the + * {@link container_ underlying container} object. + * + * @return A value of the next element in the {@link Queue}. + */ + front(): T; + /** + * Access last element. + * + * Returns a vaue of the last element in the queue. This is the "newest" element in the queue (i.e. the + * last element pushed into the queue). + * + * This member function effectively calls the member function {@link IDeque.back back()} of the + * {@link container_ underlying container} object. + * + * @return A value of the last element in the {@link Queue}. + */ + back(): T; + /** + * Insert element. + * + * Inserts a new element at the end of the {@link Queue}, after its current last element. + * The content of this new element is initialized to val. + * + * This member function effectively calls the member function {@link IDeque.push_back push_back()} of the + * {@link container_ underlying container} object. + * + * @param val Value to which the inserted element is initialized. + */ + push(val: T): void; + /** + * Remove next element. + * + * Removes the next element in the {@link Queue}, effectively reducing its size by one. + * + * The element removed is the "oldest" element in the {@link Queue} whose value can be retrieved by calling + * member {@link front Queue.front()}. + * + * This member function effectively calls the member function {@link IDeque.pop_front pop_front()} of the + * {@link container_ underlying container} object. + */ + pop(): void; + /** + * Swap contents. + * + * Exchanges the contents of the container adaptor (this) by those of obj. + * + * This member function calls the non-member function {@link Container.swap swap} (unqualified) to swap + * the {@link container_ underlying containers}. + * + * @param obj Another {@link Queue} container adaptor of the same type (i.e., instantiated with the same + * template parameter, T). Sizes may differ. + */ + swap(obj: Queue): void; + } +} +declare namespace std { + /** + * Priority queue. + * + * {@link PriorityQueue Priority queues} are a type of container adaptors, specifically designed such that its + * first element is always the greatest of the elements it contains, according to some strict weak ordering + * criterion. + * + * This context is similar to a heap, where elements can be inserted at any moment, and only the + * max heap element can be retrieved (the one at the top in the {@link PriorityQueue priority queue}). + * + * {@link PriorityQueue Priority queues} are implemented as container adaptors, which are classes that + * use an encapsulated object of a specific container class as its {@link container_ underlying container}, + * providing a specific set of member functions to access its elements. Elements are popped from the "back" + * of the specific container, which is known as the top of the {@link PriorityQueue Priority queue}. + * + * The {@link container_ underlying container} may be any of the standard container class templates or some + * other specifically designed container class. The container shall be accessible through + * {@link IArrayIterator random access iterators} and support the following operations: + * + * - {@link IArrayContainer.empty empty()} + * - {@link IArrayContainer.size size()} + * - {@link IArrayContainer.front front()} + * - {@link IArrayContainer.push_back push_back()} + * - {@link IArrayContainer.pop_back pop_back()} + * + * The standard container classes {@link Vector} and {@link Deque} fulfill these requirements. By default, if + * no container class is specified for a particular {@link PriorityQueue} class instantiation, the standard + * container {@link Vector} is used. + * + * Support of {@link IArrayIterator random access iterators} is required to keep a heap structure internally + * at all times. This is done automatically by the container adaptor by automatically calling the algorithm + * functions make_heap, push_heap and pop_heap when needed. + * + * @param Type of the elements. + * + * @reference http://www.cplusplus.com/reference/queue/priority_queue/ + * @author Jeongho Nam + */ + class PriorityQueue { + /** + * @hidden + */ + private container_; + /** + * Default Constructor. + */ + constructor(); + /** + * Construct from compare. + * + * @param compare A binary predicate determines order of elements. + */ + constructor(compare: (left: T, right: T) => boolean); + /** + * Contruct from elements. + * + * @param array Elements to be contained. + */ + constructor(array: Array); + /** + * Contruct from elements with compare. + * + * @param array Elements to be contained. + * @param compare A binary predicate determines order of elements. + */ + constructor(array: Array, compare: (left: T, right: T) => boolean); + /** + * Copy Constructor. + */ + constructor(container: base.Container); + /** + * Copy Constructor with compare. + * + * @param container A container to be copied. + * @param compare A binary predicate determines order of elements. + */ + constructor(container: base.Container, compare: (left: T, right: T) => boolean); + /** + * Range Constructor. + * + * @param begin Input interator of the initial position in a sequence. + * @param end Input interator of the final position in a sequence. + */ + constructor(begin: Iterator, end: Iterator); + /** + * Range Constructor with compare. + * + * @param begin Input interator of the initial position in a sequence. + * @param end Input interator of the final position in a sequence. + * @param compare A binary predicate determines order of elements. + */ + constructor(begin: Iterator, end: Iterator, compare: (left: T, right: T) => boolean); + /** + * Return size. + * + * Returns the number of elements in the {@link PriorityQueue}. + * + * This member function effectively calls member {@link IArrayContainer.size size} of the + * {@link IArrayContainer underlying container} object. + * + * @return The number of elements in the underlying + */ + size(): number; + /** + * Test whether container is empty. + * + * Returns whether the {@link PriorityQueue} is empty: i.e. whether its {@link size} is zero. + * + * This member function effectively calls member {@link IARray.empty empty} of the + * {@link IArrayContainer underlying container} object. + */ + empty(): boolean; + /** + * Access top element. + * + * Returns a constant reference to the top element in the {@link PriorityQueue}. + * + * The top element is the element that compares higher in the {@link PriorityQueue}, and the next that is + * removed from the container when {@link PriorityQueue.pop} is called. + * + * This member function effectively calls member {@link IArrayContainer.front front} of the + * {@link IArrayContainer underlying container} object. + * + * @return A reference to the top element in the {@link PriorityQueue}. + */ + top(): T; + /** + * Insert element. + * + * Inserts a new element in the {@link PriorityQueue}. The content of this new element is initialized to + * val. + * + * This member function effectively calls the member function {@link IArrayContainer.push_back push_back} of the + * {@link IArrayContainer underlying container} object, and then reorders it to its location in the heap by calling + * the push_heap algorithm on the range that includes all the elements of the + * + * @param val Value to which the inserted element is initialized. + */ + push(val: T): void; + /** + * Remove top element. + * + * Removes the element on top of the {@link PriorityQueue}, effectively reducing its {@link size} by one. + * The element removed is the one with the highest (or lowest) value. + * + * The value of this element can be retrieved before being popped by calling member + * {@link PriorityQueue.top}. + * + * This member function effectively calls the pop_heap algorithm to keep the heap property of + * {@link PriorityQueue PriorityQueues} and then calls the member function {@link IArrayContainer.pop_back pop_back} of + * the {@link IArrayContainer underlying container} object to remove the element. + */ + pop(): void; + /** + * Swap contents. + * + * Exchanges the contents of the container adaptor by those of obj, swapping both the + * {@link IArrayContainer underlying container} value and their comparison function using the corresponding + * {@link swap swap} non-member functions (unqualified). + * + * This member function has a noexcept specifier that matches the combined noexcept of the + * {@link IArrayContainer.swap swap} operations on the {@link IArrayContainer underlying container} and the comparison + * functions. + * + * @param obj {@link PriorityQueue} container adaptor of the same type (i.e., instantiated with the same + * template parameters, T). Sizes may differ. + */ + swap(obj: PriorityQueue): void; + } +} +declare namespace std { + /** + * LIFO stack. + * + * {@link Stack}s are a type of container adaptor, specifically designed to operate in a LIFO context + * (last-in first-out), where elements are inserted and extracted only from one end of the + * + * {@link Stack}s are implemented as containers adaptors, which are classes that use an encapsulated object of + * a specific container class as its underlying container, providing a specific set of member functions to + * access its elements. Elements are pushed/popped from the {@link ILinearContainer.back back()} of the + * {@link ILinearContainer specific container}, which is known as the top of the {@link Stack}. + * + * {@link container_ The underlying container} may be any of the standard container class templates or some + * other specifically designed container class. The container shall support the following operations: + * + * - {@link ILinearContainer.empty empty} + * - {@link ILinearContainer.size size} + * - {@link ILinearContainer.front front} + * - {@link ILinearContainer.back back} + * - {@link ILinearContainer.push_back push_back} + * - {@link ILinearContainer.pop_back pop_back} + * + * The standard container classes {@link Vector}, {@link Deque} and {@link List} fulfill these requirements. + * By default, if no container class is specified for a particular {@link Stack} class instantiation, the standard + * container {@link List} is used. + * + * + * + * + * @param Type of elements. + * + * @reference http://www.cplusplus.com/reference/stack/stack + * @author Jeongho Nam + */ + class Stack { + /** + * The underlying object for implementing the LIFO + */ + private container_; + /** + * Default Constructor. + */ + constructor(); + /** + * Copy Constructor. + */ + constructor(stack: Stack); + /** + * Return size. + * + * Returns the number of elements in the {@link Stack}. + * + * This member function effectively calls member {@link ILinearContainer.size size()} of the + * {@link container_ underlying container} object. + * + * @return The number of elements in the {@link container_ underlying container}. + */ + size(): number; + /** + * Test whether container is empty. + * + * returns whether the {@link Stack} is empty: i.e. whether its size is zero. + * + * This member function effectively calls member {@link ILinearContainer.empty empty()} of the + * {@link container_ underlying container} object. + * + * @return true if the underlying container's size is 0, + * false otherwise. + */ + empty(): boolean; + /** + * Access next element. + * + * Returns a value of the top element in the {@link Stack}. + * + * Since {@link Stack}s are last-in first-out containers, the top element is the last element inserted into + * the {@link Stack}. + * + * This member function effectively calls member {@link ILinearContainer.back back()} of the + * {@link container_ underlying container} object. + * + * @return A value of the top element in the {@link Stack}. + */ + top(): T; + /** + * Insert element. + * + * Inserts a new element at the top of the {@link Stack}, above its current top element. + * + * This member function effectively calls the member function + * {@link ILinearContainer.push_back push_back()} of the {@link container_ underlying container} object. + * + * @param val Value to which the inserted element is initialized. + */ + push(val: T): void; + /** + * Remove top element. + * + * Removes the element on top of the {@link Stack}, effectively reducing its size by one. + * + * The element removed is the latest element inserted into the {@link Stack}, whose value can be retrieved + * by calling member {@link top Stack.top()}. + * + * This member function effectively calls the member function {@link ILinearContainer.pop_back pop_back()} + * of the {@link container_ underlying container} object. + */ + pop(): void; + /** + * Swap contents. + * + * Exchanges the contents of the container adaptor (this) by those of obj. + * + * This member function calls the non-member function {@link Container.swap swap} (unqualified) to swap + * the {@link container_ underlying containers}. + * + * @param obj Another {@link Stack} container adaptor of the same type (i.e., instantiated with the same + * template parameter, T). Sizes may differ. + */ + swap(obj: Stack): void; + } +} +declare namespace std.TreeSet { + type iterator = SetIterator; + type reverse_iterator = SetReverseIterator; +} +declare namespace std { + /** + * Tree-structured set, std::set of STL. + * + * {@link TreeSet}s are containers that store unique elements following a specific order. + * + * In a {@link TreeSet}, the value of an element also identifies it (the value is itself the + * key, of type T), and each value must be unique. The value of the elements in a + * {@link TreeSet} cannot be modified once in the container (the elements are always const), but they + * can be inserted or removed from the container. + * + * Internally, the elements in a {@link TreeSet} are always sorted following a specific strict weak + * ordering criterion indicated by its internal comparison method (of {@link less}). + * + * {@link TreeSet} containers are generally slower than {@link HashSet} containers to access + * individual elements by their key, but they allow the direct iteration on subsets based on their + * order. + * + * {@link TreeSet}s are typically implemented as binary search trees. + * + * + *

+ * + * ### Container properties + *
+ *
Associative
+ *
+ * Elements in associative containers are referenced by their key and not by their absolute + * position in the container. + *
+ * + *
Ordered
+ *
+ * The elements in the container follow a strict order at all times. All inserted elements are + * given a position in this order. + *
+ * + *
Set
+ *
The value of an element is also the key used to identify it.
+ * + *
Unique keys
+ *
No two elements in the container can have equivalent keys.
+ *
+ * + * @param Type of the elements. + * Each element in an {@link TreeSet} is also uniquely identified by this value. + * + * @reference http://www.cplusplus.com/reference/set/set + * @author Jeongho Nam + */ + class TreeSet extends base.UniqueSet implements base.ITreeSet { + /** + * @hidden + */ + private tree_; + /** + * Default Constructor. + */ + constructor(); + /** + * Construct from compare. + * + * @param compare A binary predicate determines order of elements. + */ + constructor(compare: (x: T, y: T) => boolean); + /** + * Contruct from elements. + * + * @param array Elements to be contained. + */ + constructor(array: Array); + /** + * Contruct from elements with compare. + * + * @param array Elements to be contained. + * @param compare A binary predicate determines order of elements. + */ + constructor(array: Array, compare: (x: T, y: T) => boolean); + /** + * Copy Constructor. + */ + constructor(container: TreeMultiSet); + /** + * Copy Constructor with compare. + * + * @param container A container to be copied. + * @param compare A binary predicate determines order of elements. + */ + constructor(container: TreeMultiSet, compare: (x: T, y: T) => boolean); + /** + * Range Constructor. + * + * @param begin Input interator of the initial position in a sequence. + * @param end Input interator of the final position in a sequence. + */ + constructor(begin: Iterator, end: Iterator); + /** + * Construct from range and compare. + * + * @param begin Input interator of the initial position in a sequence. + * @param end Input interator of the final position in a sequence. + * @param compare A binary predicate determines order of elements. + */ + constructor(begin: Iterator, end: Iterator, compare: (x: T, y: T) => boolean); + /** + * @inheritdoc + */ + clear(): void; + /** + * @inheritdoc + */ + find(val: T): SetIterator; + /** + * @inheritdoc + */ + key_comp(): (x: T, y: T) => boolean; + /** + * @inheritdoc + */ + value_comp(): (x: T, y: T) => boolean; + /** + * @inheritdoc + */ + lower_bound(val: T): SetIterator; + /** + * @inheritdoc + */ + upper_bound(val: T): SetIterator; + /** + * @inheritdoc + */ + equal_range(val: T): Pair, SetIterator>; + /** + * @hidden + */ + protected _Insert_by_val(val: T): any; + protected _Insert_by_hint(hint: SetIterator, val: T): SetIterator; + /** + * @hidden + */ + protected _Insert_by_range>(first: InputIterator, last: InputIterator): void; + /** + * @hidden + */ + protected _Handle_insert(first: SetIterator, last: SetIterator): void; + /** + * @hidden + */ + protected _Handle_erase(first: SetIterator, last: SetIterator): void; + /** + * Swap content. + * + * Exchanges the content of the container by the content of obj, which is another + * {@link TreeSet set} of the same type. Sizes abd container type may differ. + * + * After the call to this member function, the elements in this container are those which were + * in obj before the call, and the elements of obj are those which were in this. All + * iterators, references and pointers remain valid for the swapped objects. + * + * Notice that a non-member function exists with the same name, {@link swap swap}, overloading that + * algorithm with an optimization that behaves like this member function. + * + * @param obj Another {@link TreeSet set container} of the same type of elements as this (i.e., + * with the same template parameters, Key and T) whose content is swapped + * with that of this {@link TreeSet container}. + */ + swap(obj: TreeSet): void; + /** + * @inheritdoc + */ + swap(obj: base.Container): void; + } +} +declare namespace std.TreeMap { + type iterator = MapIterator; + type reverse_iterator = MapReverseIterator; +} +declare namespace std { + /** + * Tree-structured map, std::map of STL. + * + * {@link TreeMap TreeMaps} are associative containers that store elements formed by a combination of a + * key value (Key) and a mapped value (T), following order. + * + * In a {@link TreeMap}, the key values are generally used to sort and uniquely identify the elements, + * while the mapped values store the content associated to this key. The types of key and + * mapped value may differ, and are grouped together in member type value_type, which is a {@link Pair} + * type combining both: + * + * typedef Pair value_type; + * + * Internally, the elements in a {@link TreeMap} are always sorted by its key following a + * strict weak ordering criterion indicated by its internal comparison method {@link less}. + * + * {@link TreeMap} containers are generally slower than {@link HashMap HashMap} containers to access individual + * elements by their key, but they allow the direct iteration on subsets based on their order. + * + * {@link TreeMap}s are typically implemented as binary search trees. + * + * + *

+ * + * ### Container properties + *
+ *
Associative
+ *
Elements in associative containers are referenced by their key and not by their absolute + * position in the container.
+ * + *
Ordered
+ *
The elements in the container follow a strict order at all times. All inserted elements are + * given a position in this order.
+ * + *
Map
+ *
Each element associates a key to a mapped value: + * Keys are meant to identify the elements whose main content is the mapped value.
+ * + *
Unique keys
+ *
No two elements in the container can have equivalent keys.
+ *
+ * + * @param Type of the keys. Each element in a map is uniquely identified by its key value. + * @param Type of the mapped value. Each element in a map stores some data as its mapped value. + * + * @reference http://www.cplusplus.com/reference/map/map + * @author Jeongho Nam + */ + class TreeMap extends base.UniqueMap implements base.ITreeMap { + /** + * @hidden + */ + private tree_; + /** + * Default Constructor. + */ + constructor(); + /** + * Construct from compare. + * + * @param compare A binary predicate determines order of elements. + */ + constructor(compare: (x: Key, y: Key) => boolean); + /** + * Contruct from elements. + * + * @param array Elements to be contained. + */ + constructor(array: Array>); + /** + * Contruct from elements. + * + * @param array Elements to be contained. + * @param compare A binary predicate determines order of elements. + */ + constructor(array: Array>, compare: (x: Key, y: Key) => boolean); + /** + * Contruct from tuples. + * + * @param array Tuples to be contained. + */ + constructor(array: Array<[Key, T]>); + /** + * Contruct from tuples. + * + * @param array Tuples to be contained. + * @param compare A binary predicate determines order of elements. + */ + constructor(array: Array<[Key, T]>, compare: (x: Key, y: Key) => boolean); + /** + * Copy Constructor. + * + * @param container Another map to copy. + */ + constructor(container: TreeMap); + /** + * Copy Constructor. + * + * @param container Another map to copy. + * @param compare A binary predicate determines order of elements. + */ + constructor(container: TreeMap, compare: (x: Key, y: Key) => boolean); + /** + * Range Constructor. + * + * @param begin nput interator of the initial position in a sequence. + * @param end Input interator of the final position in a sequence. + */ + constructor(begin: Iterator>, end: Iterator>); + /** + * Range Constructor. + * + * @param begin nput interator of the initial position in a sequence. + * @param end Input interator of the final position in a sequence. + * @param compare A binary predicate determines order of elements. + */ + constructor(begin: Iterator>, end: Iterator>, compare: (x: Key, y: Key) => boolean); + /** + * @inheritdoc + */ + clear(): void; + /** + * @inheritdoc + */ + find(key: Key): MapIterator; + /** + * @inheritdoc + */ + key_comp(): (x: Key, y: Key) => boolean; + /** + * @inheritdoc + */ + value_comp(): (x: Pair, y: Pair) => boolean; + /** + * @inheritdoc + */ + lower_bound(key: Key): MapIterator; + /** + * @inheritdoc + */ + upper_bound(key: Key): MapIterator; + /** + * @inheritdoc + */ + equal_range(key: Key): Pair, MapIterator>; + /** + * @hidden + */ + protected _Insert_by_pair(pair: Pair): any; + /** + * @hidden + */ + protected _Insert_by_hint(hint: MapIterator, pair: Pair): MapIterator; + /** + * @hidden + */ + protected _Insert_by_range>>(first: InputIterator, last: InputIterator): void; + /** + * @hidden + */ + protected _Handle_insert(first: MapIterator, last: MapIterator): void; + /** + * @hidden + */ + protected _Handle_erase(first: MapIterator, last: MapIterator): void; + /** + * Swap content. + * + * Exchanges the content of the container by the content of obj, which is another + * {@link TreeMap map} of the same type. Sizes abd container type may differ. + * + * After the call to this member function, the elements in this container are those which were + * in obj before the call, and the elements of obj are those which were in this. All + * iterators, references and pointers remain valid for the swapped objects. + * + * Notice that a non-member function exists with the same name, {@link swap swap}, overloading that + * algorithm with an optimization that behaves like this member function. + * + * @param obj Another {@link TreeMap map container} of the same type of elements as this (i.e., + * with the same template parameters, Key and T) whose content is swapped + * with that of this {@link TreeMap container}. + */ + swap(obj: TreeMap): void; + /** + * @inheritdoc + */ + swap(obj: base.Container>): void; + } +} +declare namespace std.TreeMultiSet { + type iterator = SetIterator; + type reverse_iterator = SetReverseIterator; +} +declare namespace std { + /** + * Tree-structured multiple-key set. + * + * {@link TreeMultiSet TreeMultiSets} are containers that store elements following a specific order, and + * where multiple elements can have equivalent values. + * + * In a {@link TreeMultiSet}, the value of an element also identifies it (the value is itself + * the key, of type T). The value of the elements in a {@link TreeMultiSet} cannot + * be modified once in the container (the elements are always const), but they can be inserted or removed + * from the container. + * + * Internally, the elements in a {@link TreeMultiSet TreeMultiSets} are always sorted following a strict + * weak ordering criterion indicated by its internal comparison method (of {@link IComparable.less less}). + * + * {@link TreeMultiSet} containers are generally slower than {@link HashMultiSet} containers + * to access individual elements by their key, but they allow the direct iteration on subsets based on + * their order. + * + * {@link TreeMultiSet TreeMultiSets} are typically implemented as binary search trees. + * + * + *

+ * + * ### Container properties + *
+ *
Associative
+ *
+ * Elements in associative containers are referenced by their key and not by their absolute + * position in the container. + *
+ * + *
Ordered
+ *
+ * The elements in the container follow a strict order at all times. All inserted elements are + * given a position in this order. + *
+ * + *
Set
+ *
The value of an element is also the key used to identify it.
+ * + *
Multiple equivalent keys
+ *
Multiple elements in the container can have equivalent keys.
+ *
+ * + * @param Type of the elements. Each element in a {@link TreeMultiSet} container is also identified + * by this value (each value is itself also the element's key). + * + * @reference http://www.cplusplus.com/reference/set/multiset + * @author Jeongho Nam + */ + class TreeMultiSet extends base.MultiSet implements base.ITreeSet { + /** + * @hidden + */ + private tree_; + /** + * Default Constructor. + */ + constructor(); + /** + * Construct from compare. + * + * @param compare A binary predicate determines order of elements. + */ + constructor(compare: (x: T, y: T) => boolean); + /** + * Contruct from elements. + * + * @param array Elements to be contained. + */ + constructor(array: Array); + /** + * Contruct from elements with compare. + * + * @param array Elements to be contained. + * @param compare A binary predicate determines order of elements. + */ + constructor(array: Array, compare: (x: T, y: T) => boolean); + /** + * Copy Constructor. + */ + constructor(container: TreeMultiSet); + /** + * Copy Constructor with compare. + * + * @param container A container to be copied. + * @param compare A binary predicate determines order of elements. + */ + constructor(container: TreeMultiSet, compare: (x: T, y: T) => boolean); + /** + * Range Constructor. + * + * @param begin Input interator of the initial position in a sequence. + * @param end Input interator of the final position in a sequence. + */ + constructor(begin: Iterator, end: Iterator); + /** + * Construct from range and compare. + * + * @param begin Input interator of the initial position in a sequence. + * @param end Input interator of the final position in a sequence. + * @param compare A binary predicate determines order of elements. + */ + constructor(begin: Iterator, end: Iterator, compare: (x: T, y: T) => boolean); + /** + * @inheritdoc + */ + clear(): void; + /** + * @inheritdoc + */ + find(val: T): SetIterator; + /** + * @inheritdoc + */ + count(val: T): number; + /** + * @inheritdoc + */ + key_comp(): (x: T, y: T) => boolean; + /** + * @inheritdoc + */ + value_comp(): (x: T, y: T) => boolean; + /** + * @inheritdoc + */ + lower_bound(val: T): SetIterator; + /** + * @inheritdoc + */ + upper_bound(val: T): SetIterator; + /** + * @inheritdoc + */ + equal_range(val: T): Pair, SetIterator>; + /** + * @hidden + */ + protected _Insert_by_val(val: T): any; + /** + * @hidden + */ + protected _Insert_by_hint(hint: SetIterator, val: T): SetIterator; + /** + * @hidden + */ + protected _Insert_by_range>(first: InputIterator, last: InputIterator): void; + /** + * @hidden + */ + protected _Handle_insert(first: SetIterator, last: SetIterator): void; + /** + * @hidden + */ + protected _Handle_erase(first: SetIterator, last: SetIterator): void; + /** + * Swap content. + * + * Exchanges the content of the container by the content of obj, which is another + * {@link TreeMultiSet set} of the same type. Sizes abd container type may differ. + * + * After the call to this member function, the elements in this container are those which were + * in obj before the call, and the elements of obj are those which were in this. All + * iterators, references and pointers remain valid for the swapped objects. + * + * Notice that a non-member function exists with the same name, {@link swap swap}, overloading that + * algorithm with an optimization that behaves like this member function. + * + * @param obj Another {@link TreeMultiSet set container} of the same type of elements as this (i.e., + * with the same template parameters, Key and T) whose content is swapped + * with that of this {@link TreeMultiSet container}. + */ + swap(obj: TreeMultiSet): void; + /** + * @inheritdoc + */ + swap(obj: base.Container): void; + } +} +declare namespace std.TreeMultiMap { + type iterator = MapIterator; + type reverse_iterator = MapReverseIterator; +} +declare namespace std { + /** + * Tree-structured multiple-key map. + * + * {@link TreeMultiMap TreeMultiMaps} are associative containers that store elements formed by a combination of + * a key value and a mapped value, following a specific order, and where multiple elements can + * have equivalent keys. + * + * In a {@link TreeMultiMap}, the key values are generally used to sort and uniquely identify + * the elements, while the mapped values store the content associated to this key. The types of + * key and mapped value may differ, and are grouped together in member type + * value_type, which is a {@link Pair} type combining both: + * + * typedef Pair value_type; + * + * Internally, the elements in a {@link TreeMultiMap}are always sorted by its key following a + * strict weak ordering criterion indicated by its internal comparison method (of {@link less}). + * + * {@link TreeMultiMap}containers are generally slower than {@link HashMap} containers + * to access individual elements by their key, but they allow the direct iteration on subsets based + * on their order. + * + * {@link TreeMultiMap TreeMultiMaps} are typically implemented as binary search trees. + * + * < + * img src="http://samchon.github.io/tstl/images/design/class_diagram/map_containers.png" style="max-width: 100%" />

+ * + * ### Container properties + *
+ *
Associative
+ *
+ * Elements in associative containers are referenced by their key and not by their absolute + * position in the container. + *
+ * + *
Ordered
+ *
+ * The elements in the container follow a strict order at all times. All inserted elements are + * given a position in this order. + *
+ * + *
Map
+ *
+ * Each element associates a key to a mapped value: + * Keys are meant to identify the elements whose main content is the mapped value. + *
+ * + *
Multiple equivalent keys
+ *
Multiple elements in the container can have equivalent keys.
+ *
+ * + * @param Type of the keys. Each element in a map is uniquely identified by its key value. + * @param Type of the mapped value. Each element in a map stores some data as its mapped value. + * + * @reference http://www.cplusplus.com/reference/map/multimap + * @author Jeongho Nam + */ + class TreeMultiMap extends base.MultiMap implements base.ITreeMap { + /** + * @hidden + */ + private tree_; + /** + * Default Constructor. + */ + constructor(); + /** + * Construct from compare. + * + * @param compare A binary predicate determines order of elements. + */ + constructor(compare: (x: Key, y: Key) => boolean); + /** + * Contruct from elements. + * + * @param array Elements to be contained. + */ + constructor(array: Array>); + /** + * Contruct from elements. + * + * @param array Elements to be contained. + * @param compare A binary predicate determines order of elements. + */ + constructor(array: Array>, compare: (x: Key, y: Key) => boolean); + /** + * Contruct from tuples. + * + * @param array Tuples to be contained. + */ + constructor(array: Array<[Key, T]>); + /** + * Contruct from tuples. + * + * @param array Tuples to be contained. + * @param compare A binary predicate determines order of elements. + */ + constructor(array: Array<[Key, T]>, compare: (x: Key, y: Key) => boolean); + /** + * Copy Constructor. + * + * @param container Another map to copy. + */ + constructor(container: TreeMultiMap); + /** + * Copy Constructor. + * + * @param container Another map to copy. + * @param compare A binary predicate determines order of elements. + */ + constructor(container: TreeMultiMap, compare: (x: Key, y: Key) => boolean); + /** + * Range Constructor. + * + * @param begin nput interator of the initial position in a sequence. + * @param end Input interator of the final position in a sequence. + */ + constructor(begin: Iterator>, end: Iterator>); + /** + * Range Constructor. + * + * @param begin nput interator of the initial position in a sequence. + * @param end Input interator of the final position in a sequence. + * @param compare A binary predicate determines order of elements. + */ + constructor(begin: Iterator>, end: Iterator>, compare: (x: Key, y: Key) => boolean); + /** + * @inheritdoc + */ + clear(): void; + /** + * @inheritdoc + */ + find(key: Key): MapIterator; + /** + * @inheritdoc + */ + count(key: Key): number; + /** + * @inheritdoc + */ + key_comp(): (x: Key, y: Key) => boolean; + /** + * @inheritdoc + */ + value_comp(): (x: Pair, y: Pair) => boolean; + /** + * @inheritdoc + */ + lower_bound(key: Key): MapIterator; + /** + * @inheritdoc + */ + upper_bound(key: Key): MapIterator; + /** + * @inheritdoc + */ + equal_range(key: Key): Pair, MapIterator>; + /** + * @hidden + */ + protected _Insert_by_pair(pair: Pair): any; + /** + * @hidden + */ + protected _Insert_by_hint(hint: MapIterator, pair: Pair): MapIterator; + /** + * @hidden + */ + protected _Insert_by_range>>(first: InputIterator, last: InputIterator): void; + /** + * @hidden + */ + protected _Handle_insert(first: MapIterator, last: MapIterator): void; + /** + * @hidden + */ + protected _Handle_erase(first: MapIterator, last: MapIterator): void; + /** + * Swap content. + * + * Exchanges the content of the container by the content of obj, which is another + * {@link TreeMapMulti map} of the same type. Sizes abd container type may differ. + * + * After the call to this member function, the elements in this container are those which were + * in obj before the call, and the elements of obj are those which were in this. All + * iterators, references and pointers remain valid for the swapped objects. + * + * Notice that a non-member function exists with the same name, {@link swap swap}, overloading that + * algorithm with an optimization that behaves like this member function. + * + * @param obj Another {@link TreeMapMulti map container} of the same type of elements as this (i.e., + * with the same template parameters, Key and T) whose content is swapped + * with that of this {@link TreeMapMulti container}. + */ + swap(obj: TreeMultiMap): void; + /** + * @inheritdoc + */ + swap(obj: base.Container>): void; + } +} +declare namespace std { + /** + * System error exception. + * + * This class defines the type of objects thrown as exceptions to report conditions originating during + * runtime from the operating system or other low-level application program interfaces which have an + * associated {@link ErrorCode}. + * + * The class inherits from {@link RuntimeError}, to which it adds an {@link ErrorCode} as + * member code (and defines a specialized what member). + * + * + * + * + * @reference http://www.cplusplus.com/reference/system_error/system_error + * @author Jeongho Nam + */ + class SystemError extends RuntimeError { + /** + * @hidden + */ + protected code_: ErrorCode; + /** + * Construct from an error code. + * + * @param code An {@link ErrorCode} object. + */ + constructor(code: ErrorCode); + /** + * Construct from an error code and message. + * + * @param code An {@link ErrorCode} object. + * @param message A message incorporated in the string returned by member {@link what what()}. + */ + constructor(code: ErrorCode, message: string); + /** + * Construct from a numeric value and error category. + * + * @param val A numerical value identifying an error code. + * @param category A reference to an {@link ErrorCode} object. + */ + constructor(val: number, category: ErrorCategory); + /** + * Construct from a numeric value, error category and message. + * + * @param val A numerical value identifying an error code. + * @param category A reference to an {@link ErrorCode} object. + * @param message A message incorporated in the string returned by member {@link what what()}. + */ + constructor(val: number, category: ErrorCategory, message: string); + /** + * Get error code. + * + * Returns the {@link ErrorCode} object associated with the exception. + * + * This value is either the {@link ErrorCode} passed to the construction or its equivalent + * (if constructed with a value and a {@link category}. + * + * @return The {@link ErrorCode} associated with the object. + */ + code(): ErrorCode; + } +} +declare namespace std { + /** + * Error category. + * + * This type serves as a base class for specific category types. + * + * Category types are used to identify the source of an error. They also define the relation between + * {@link ErrorCode} and {@link ErrorCondition}objects of its category, as well as the message set for {@link ErrorCode} + * objects. + * + * Objects of these types have no distinct values and are not-copyable and not-assignable, and thus can only be + * passed by reference. As such, only one object of each of these types shall exist, each uniquely identifying its own + * category: all error codes and conditions of a same category shall return a reference to same object. + * + * + * + * + * @reference http://www.cplusplus.com/reference/system_error/error_category + * @author Jeongho Nam + */ + abstract class ErrorCategory { + /** + * Default Constructor. + */ + constructor(); + /** + * Return category name. + * + * In derived classes, the function returns a string naming the category. + * + * In {@link ErrorCategory}, it is a pure virtual member function. + * + *
    + *
  • In the {@link GenericCategory} object, it returns "generic".
  • + *
  • In the {@link SystemCategory} object, it returns "system".
  • + *
  • In the {@link IOStreamCategory} object, it returns "iostream".
  • + *
+ * + * @return The category name. + */ + abstract name(): string; + /** + * Error message. + * + * In derived classes, the function returns a string object with a message describing the error condition + * denoted by val. + * + * In {@link ErrorCategory}, it is a pure virtual member function. + * + * This function is called both by {@link ErrorCode.message ErrorCode.message()} and + * {@link ErrorCondition.message ErrorCondition.message()} to obtain the corresponding message in the + * {@link category}. Therefore, numerical values used by custom error codes and + * {@link ErrorCondition error conditions} should only match for a category if they describe the same error. + * + * @param val A numerical value identifying an error condition. + * If the {@link ErrorCategory} object is the {@link GenericCategory}, this argument is equivalent to an + * {@link errno} value. + * + * @return A string object with the message. + */ + abstract message(val: number): string; + /** + * Default error condition. + * + * Returns the default {@link ErrorCondition}object of this category that is associated with the + * {@link ErrorCode} identified by a value of val. + * + * Its definition in the base class {@link ErrorCategory} returns the same as constructing an + * {@link ErrorCondition} object with: + * + * new ErrorCondition(val, *this); + * + * As a virtual member function, this behavior can be overriden in derived classes. + * + * This function is called by the default definition of member {@link equivalent equivalent()}, which is used to + * compare {@link ErrorCondition error conditions} with error codes. + * + * @param val A numerical value identifying an error condition. + * + * @return The default {@link ErrorCondition}object associated with condition value val for this category. + */ + default_error_condition(val: number): ErrorCondition; + /** + * Check error code equivalence. + * + * Checks whether, for the category, an {@link ErrorCode error code} is equivalent to an + * {@link ErrorCondition error condition. + * + * This function is called by the overloads of comparison operators when an {@link ErrorCondition} object is + * compared to an {@link ErrorCode} object to check for equality or inequality. If either one of those objects' + * {@link ErrorCategory categories} considers the other equivalent using this function, they are considered + * equivalent by the operator. + * + * As a virtual member function, this behavior can be overridden in derived classes to define a different + * correspondence mechanism for each {@link ErrorCategory} type. + * + * @param val_code A numerical value identifying an error code. + * @param cond An object of an {@link ErrorCondition} type. + * + * @return true if the arguments are considered equivalent. false otherwise. + */ + equivalent(val_code: number, cond: ErrorCondition): boolean; + /** + * Check error code equivalence. + * + * Checks whether, for the category, an {@link ErrorCode error code} is equivalent to an + * {@link ErrorCondition error condition. + * + * This function is called by the overloads of comparison operators when an {@link ErrorCondition} object is + * compared to an {@link ErrorCode} object to check for equality or inequality. If either one of those objects' + * {@link ErrorCategory categories} considers the other equivalent using this function, they are considered + * equivalent by the operator. + * + * As a virtual member function, this behavior can be overridden in derived classes to define a different + * correspondence mechanism for each {@link ErrorCategory} type. + * + * @param code An object of an {@link ErrorCode} type. + * @param val_cond A numerical value identifying an error code. + * + * @return true if the arguments are considered equivalent. false otherwise. + */ + equivalent(code: ErrorCode, val_cond: number): boolean; + } +} +declare namespace std { + /** + * Error condition. + * + * Objects of this type hold a condition {@link value} associated with a {@link category}. + * + * Objects of this type describe errors in a generic way so that they may be portable across different + * systems. This is in contrast with {@link ErrorCode} objects, that may contain system-specific + * information. + * + * Because {@link ErrorCondition}objects can be compared with error_code objects directly by using + * relational operators, {@link ErrorCondition}objects are generally used to check whether + * a particular {@link ErrorCode} obtained from the system matches a specific error condition no matter + * the system. + * + * The {@link ErrorCategory categories} associated with the {@link ErrorCondition} and the + * {@link ErrorCode} define the equivalences between them. + * + * + * + * + * @reference http://www.cplusplus.com/reference/system_error/error_condition + * @author Jeongho Nam + */ + class ErrorCondition extends base.ErrorInstance { + /** + * Default Constructor. + */ + constructor(); + /** + * Construct from a numeric value and error category. + * + * @param val A numerical value identifying an error condition. + * @param category A reference to an {@link ErrorCategory} object. + */ + constructor(val: number, category: ErrorCategory); + } +} +declare namespace std { + /** + * Error code. + * + * Objects of this type hold an error code {@link value} associated with a {@link category}. + * + * The operating system and other low-level applications and libraries generate numerical error codes to + * represent possible results. These numerical values may carry essential information for a specific platform, + * but be non-portable from one platform to another. + * + * Objects of this class associate such numerical codes to {@link ErrorCategory error categories}, so that they + * can be interpreted when needed as more abstract (and portable) {@link ErrorCondition error conditions}. + * + * + * + * + * @reference http://www.cplusplus.com/reference/system_error/error_code + * @author Jeongho Nam + */ + class ErrorCode extends base.ErrorInstance { + /** + * Default Constructor. + */ + constructor(); + /** + * Construct from a numeric value and error category. + * + * @param val A numerical value identifying an error code. + * @param category A reference to an {@link ErrorCategory} object. + */ + constructor(val: number, category: ErrorCategory); + } +} +declare namespace std { + /** + * Running on Node. + * + * Test whether the JavaScript is running on Node. + * + * @references http://stackoverflow.com/questions/17575790/environment-detection-node-js-or-browser + */ + function is_node(): boolean; + /** + * Pair of values. + * + * This class couples together a pair of values, which may be of different types (T1 and + * T2). The individual values can be accessed through its public members {@link first} and + * {@link second}. + * + * @param Type of member {@link first}. + * @param Type of member {@link second}. + * + * @reference http://www.cplusplus.com/reference/utility/pair + * @author Jeongho Nam + */ + class Pair implements IComparable> { + /** + * A first value in the Pair. + */ + first: T1; + /** + * A second value in the Pair. + */ + second: T2; + /** + * Construct from pair values. + * + * @param first The first value of the Pair + * @param second The second value of the Pair + */ + constructor(first: T1, second: T2); + /** + * Whether a Pair is equal with the Pair. + * + * Compare each first and second value of two Pair(s) and returns whether they are equal or not. + * + * If stored key and value in a Pair are not number or string but an object like a class or struct, + * the comparison will be executed by a member method (SomeObject)::equals(). If the object does not have + * the member method equal_to(), only address of pointer will be compared. + * + * @param obj A Map to compare + * @return Indicates whether equal or not. + */ + equals(pair: Pair): boolean; + /** + * @inheritdoc + */ + less(pair: Pair): boolean; + } + /** + * Construct {@link Pair} object. + * + * Constructs a {@link Pair} object with its {@link Pair.first first} element set to x and its + * {@link Pair.second second} element set to y. + * + * The template types can be implicitly deduced from the arguments passed to {@link make_pair}. + * + * {@link Pair} objects can be constructed from other {@link Pair} objects containing different types, if the + * respective types are implicitly convertible. + * + * @param x Value for member {@link Pair.first first}. + * @param y Value for member {@link Pair.second second}. + * + * @return A {@link Pair} object whose elements {@link Pair.first first} and {@link Pair.second second} are set to + * x and y respectivelly. + */ + function make_pair(x: T1, y: T2): Pair; +} +declare namespace std { + /** + * Type definition of {@link Vector} and it's the original name used in C++. + */ + export import vector = Vector; + /** + * Type definition of {@link List} and it's the original name used in C++. + */ + export import list = List; + /** + * Type definition of {@link Deque} and it's the original name used in C++. + */ + export import deque = Deque; + /** + * Type definition of {@link Stack} and it's the original name used in C++. + */ + type stack = Stack; + /** + * Type definition of {@link Queue} and it's the original name used in C++. + */ + type queue = Queue; + /** + * Type definition of {@link PriorityQueue} and it's the original name used in C++. + */ + type priority_queue = PriorityQueue; + var stack: typeof Stack; + var queue: typeof Queue; + var priority_queue: typeof PriorityQueue; + /** + * Type definition of {@link TreeSet} and it's the original name used in C++. + */ + export import set = TreeSet; + /** + * Type definition of {@link TreeMultiSet} and it's the original name used in C++. + */ + export import multiset = TreeMultiSet; + /** + * Type definition of {@link HashSet} and it's the original name used in C++. + */ + export import unordered_set = HashSet; + /** + * Type definition of {@link HashMultiSet} and it's the original name used in C++. + */ + export import unordered_multiset = HashMultiSet; + /** + * Type definition of {@link TreeMap} and it's the original name used in C++. + */ + export import map = TreeMap; + /** + * Type definition of {@link TreeMultiMap} and it's the original name used in C++. + */ + export import multimap = TreeMultiMap; + /** + * Type definition of {@link HashMap} and it's the original name used in C++. + */ + export import unordered_map = HashMap; + /** + * Type definition of {@link HashMultiMap} and it's the original name used in C++. + */ + export import unordered_multimap = HashMultiMap; + type exception = Exception; + type logic_error = LogicError; + type domain_error = DomainError; + type invalid_argument = InvalidArgument; + type length_error = LengthError; + type out_of_range = OutOfRange; + type runtime_error = RuntimeError; + type overflow_error = OverflowError; + type underflow_error = UnderflowError; + type range_error = RangeError; + type system_error = SystemError; + type error_category = ErrorCategory; + type error_condition = ErrorCondition; + type error_code = ErrorCode; + var exception: typeof Exception; + var logic_error: typeof LogicError; + var domain_error: typeof DomainError; + var invalid_argument: typeof InvalidArgument; + var length_error: typeof LengthError; + var out_of_range: typeof OutOfRange; + var runtime_error: typeof RuntimeError; + var overflow_error: typeof OverflowError; + var underflow_error: typeof UnderflowError; + var range_error: typeof RangeError; + var system_error: typeof SystemError; + var error_category: typeof ErrorCategory; + var error_condition: typeof ErrorCondition; + var error_code: typeof ErrorCode; +} diff --git a/tstl/tsconfig.json b/tstl/tsconfig.json new file mode 100644 index 0000000000..b5f47406d8 --- /dev/null +++ b/tstl/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "tstl-tests.ts" + ] +} \ No newline at end of file diff --git a/tstl/tstl-tests.ts b/tstl/tstl-tests.ts new file mode 100644 index 0000000000..ec42d087b4 --- /dev/null +++ b/tstl/tstl-tests.ts @@ -0,0 +1,2 @@ +import std = require("tstl"); +console.log(std); \ No newline at end of file diff --git a/typescript-stl/index.d.ts b/typescript-stl/index.d.ts index bd6886deed..bbd6c5ca57 100644 --- a/typescript-stl/index.d.ts +++ b/typescript-stl/index.d.ts @@ -1,12485 +1,13 @@ -// Type definitions for TypeScript-STL v1.2.4 -// Project: https://github.com/samchon/typescript-stl +// Type definitions for TSTL v1.3.x +// Project: https://github.com/samchon/tstl // Definitions by: Jeongho Nam // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +/// +// TypeScript-STL is renamed to TSTL + declare module "typescript-stl" { + import std = require("tstl"); export = std; -} - -/** - *

TypeScript-STL

- *

- *

- * - *

STL (Standard Template Library) Containers and Algorithms for TypeScript.

- * - *

TypeScript-STL is a TypeScript's Standard Template Library who is migrated from C++ STL. Most of classes - * and functions of STL have implemented. Just enjoy it.

- * - * @git https://github.com/samchon/typescript-stl - * @author Jeongho Nam - */ -declare namespace std { -} -/** - * Base classes composing STL in background. - * - * @author Jeongho Nam - */ -declare namespace std.base { -} -declare namespace std { - /** - *

Apply function to range.

- * - *

Applies function fn to each of the elements in the range [first, last).

- * - * @param first An {@link Iterator} to the initial position in a sequence. - * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), - * which contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - * @param fn Unary function that accepts an element in the range as argument. This can either be a function p - * ointer or a move constructible function object. Its return value, if any, is ignored. - */ - function for_each, Func extends (val: T) => any>(first: InputIterator, last: InputIterator, fn: Func): Func; - /** - * Apply function to range. - * - * Applies function *fn* to each of the elements in the range [*first*, *first + n*). - * - * @param first An {@link Iterator} to the initial position in a sequence. - * @param n the number of elements to apply the function to - * @param fn Unary function that accepts an element in the range as argument. This can either be a function p - * ointer or a move constructible function object. Its return value, if any, is ignored. - * - * @return first + n - */ - function for_each_n>(first: InputIterator, n: number, fn: (val: T) => any): InputIterator; - /** - *

Test condition on all elements in range.

- * - *

Returns true if pred returns true for all the elements in the range - * [first, last) or if the range is {@link IContainer.empty empty}, and false otherwise. - *

- * - * @param first An {@link Iterator} to the initial position in a sequence. - * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), - * which contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - * @param pred Unary function that accepts an element in the range as argument and returns a value convertible to - * boolean. The value returned indicates whether the element fulfills the condition - * checked by this function. The function shall not modify its argument. - * - * @return true if pred returns true for all the elements in the range or if the range is - * {@link IContainer.empty empty}, and false otherwise. - */ - function all_of>(first: InputIterator, last: InputIterator, pred: (val: T) => boolean): boolean; - /** - *

Test if any element in range fulfills condition.

- * - *

Returns true if pred returns true for any of the elements in the range - * [first, last), and false otherwise.

- * - *

If [first, last) is an {@link IContainer.empty empty} range, the function returns - * false.

- * - * @param first An {@link Iterator} to the initial position in a sequence. - * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), - * which contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - * @param pred Unary function that accepts an element in the range as argument and returns a value convertible to - * boolean. The value returned indicates whether the element fulfills the condition - * checked by this function. The function shall not modify its argument. - * - * @return true if pred returns true for any of the elements in the range - * [first, last), and false otherwise. If [first, last) is an - * {@link IContainer.empty empty} range, the function returns false. - */ - function any_of>(first: InputIterator, last: InputIterator, pred: (val: T) => boolean): boolean; - /** - *

Test if no elements fulfill condition.

- * - *

Returns true if pred returns false for all the elements in the range - * [first, last) or if the range is {@link IContainer.empty empty}, and false otherwise. - *

- * - * @param first An {@link Iterator} to the initial position in a sequence. - * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), - * which contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - * @param pred Unary function that accepts an element in the range as argument and returns a value convertible to - * boolean. The value returned indicates whether the element fulfills the condition - * checked by this function. The function shall not modify its argument. - * - * @return true if pred returns false for all the elements in the range - * [first, last) or if the range is {@link IContainer.empty empty}, and false - * otherwise. - */ - function none_of>(first: InputIterator, last: InputIterator, pred: (val: T) => boolean): boolean; - /** - *

Test whether the elements in two ranges are equal.

- * - *

Compares the elements in the range [first1, last1) with those in the range beginning at - * first2, and returns true if all of the elements in both ranges match.

- * - * @param first1 An {@link Iterator} to the initial position of the first sequence. - * @param last1 An {@link Iterator} to the final position in a sequence. The range used is - * [first1, last1), including the element pointed by first1, but not the element - * pointed by last1. - * @param first2 An {@link Iterator} to the initial position of the second sequence. The comparison includes up to - * as many elements of this sequence as those in the range [first1, last1). - * - * @return true if all the elements in the range [first1, last1) compare equal to those - * of the range starting at first2, and false otherwise. - */ - function equal>(first1: InputIterator, last1: InputIterator, first2: Iterator): boolean; - /** - *

Test whether the elements in two ranges are equal.

- * - *

Compares the elements in the range [first1, last1) with those in the range beginning at - * first2, and returns true if all of the elements in both ranges match.

- * - * @param first1 An {@link Iterator} to the initial position of the first sequence. - * @param last1 An {@link Iterator} to the final position in a sequence. The range used is - * [first1, last1), including the element pointed by first1, but not the element - * pointed by last1. - * @param first2 An {@link Iterator} to the initial position of the second sequence. The comparison includes up to - * as many elements of this sequence as those in the range [first1, last1). - * @param pred Binary function that accepts two elements as argument (one of each of the two sequences, in the same - * order), and returns a value convertible to bool. The value returned indicates whether - * the elements are considered to match in the context of this function. - * - * @return true if all the elements in the range [first1, last1) compare equal to those - * of the range starting at first2, and false otherwise. - */ - function equal>(first1: InputIterator, last1: InputIterator, first2: Iterator, pred: (x: T, y: T) => boolean): boolean; - /** - *

Lexicographical less-than comparison.

- * - *

Returns true if the range [first1, last1) compares lexicographically less - * than the range [first2, last2).

- * - *

A lexicographical comparison is the kind of comparison generally used to sort words alphabetically in - * dictionaries; It involves comparing sequentially the elements that have the same position in both ranges against - * each other until one element is not equivalent to the other. The result of comparing these first non-matching - * elements is the result of the lexicographical comparison.

- * - *

If both sequences compare equal until one of them ends, the shorter sequence is lexicographically less - * than the longer one.

- * - * @param first1 An {@link Iterator} to the initial position of the first sequence. - * @param last1 An {@link Iterator} to the final position in a sequence. The range used is - * [first1, last1), including the element pointed by first1, but not the element - * pointed by last1. - * @param first2 An {@link Iterator} to the initial position of the second sequence. - * @param last2 An {@link Iterator} to the final position of the second sequence. The ranged used is - * [first2, last2). - * - * @return true if the first range compares lexicographically less than than the second. - * false otherwise (including when all the elements of both ranges are equivalent). - */ - function lexicographical_compare, Iterator2 extends Iterator>(first1: Iterator1, last1: Iterator1, first2: Iterator2, last2: Iterator2): boolean; - /** - *

Lexicographical comparison.

- * - *

Returns true if the range [first1, last1) compares lexicographically - * relationship than the range [first2, last2).

- * - *

A lexicographical comparison is the kind of comparison generally used to sort words alphabetically in - * dictionaries; It involves comparing sequentially the elements that have the same position in both ranges against - * each other until one element is not equivalent to the other. The result of comparing these first non-matching - * elements is the result of the lexicographical comparison.

- * - *

If both sequences compare equal until one of them ends, the shorter sequence is lexicographically - * relationship than the longer one.

- * - * @param first1 An {@link Iterator} to the initial position of the first sequence. - * @param last1 An {@link Iterator} to the final position in a sequence. The range used is - * [first1, last1), including the element pointed by first1, but not the element - * pointed by last1. - * @param first2 An {@link Iterator} to the initial position of the second sequence. - * @param last2 An {@link Iterator} to the final position of the second sequence. The ranged used is - * [first2, last2). - * @param compare Binary function that accepts two arguments of the types pointed by the iterators, and returns a - * value convertible to bool. The value returned indicates whether the first argument is - * considered to go before the second in the specific strict weak ordering it defines. - * - * @return true if the first range compares lexicographically relationship than than the - * second. false otherwise (including when all the elements of both ranges are equivalent). - */ - function lexicographical_compare, Iterator2 extends Iterator>(first1: Iterator1, last1: Iterator1, first2: Iterator2, last2: Iterator2, compare: (x: T, y: T) => boolean): boolean; - /** - *

Find value in range.

- * - *

Returns an iterator to the first element in the range [first, last) that compares equal to - * val. If no such element is found, the function returns last.

- * - *

The function uses {@link equal_to equal_to} to compare the individual elements to val.

- * - * @param first An {@link Iterator} to the initial position in a sequence. - * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), - * which contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - * @param val Value to search for in the range. - * - * @return An {@link Iterator} to the first element in the range that compares equal to val. If no elements - * match, the function returns last. - */ - function find>(first: InputIterator, last: InputIterator, val: T): InputIterator; - /** - *

Find element in range.

- * - *

Returns an iterator to the first element in the range [first, last) for which pred returns - * true. If no such element is found, the function returns last.

- * - * @param first An {@link Iterator} to the initial position in a sequence. - * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), - * which contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - * @param pred Unary function that accepts an element in the range as argument and returns a value convertible - * to bool. The value returned indicates whether the element is considered a match in - * the context of this function. The function shall not modify its argument. - * - * @return An {@link Iterator} to the first element in the range for which pred does not return - * false. If pred is false for all elements, the function returns - * last. - */ - function find_if>(first: InputIterator, last: InputIterator, pred: (val: T) => boolean): InputIterator; - /** - *

Find element in range.

- * - *

Returns an iterator to the first element in the range [first, last) for which pred returns - * true. If no such element is found, the function returns last.

- * - * @param first An {@link Iterator} to the initial position in a sequence. - * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), - * which contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - * @param pred Unary function that accepts an element in the range as argument and returns a value convertible - * to bool. The value returned indicates whether the element is considered a match in - * the context of this function. The function shall not modify its argument. - * - * @return An {@link Iterator} to the first element in the range for which pred returns false. - * If pred is true for all elements, the function returns last. - */ - function find_if_not>(first: InputIterator, last: InputIterator, pred: (val: T) => boolean): InputIterator; - /** - *

Find last subsequence in range.

- * - *

Searches the range [first1, last1) for the last occurrence of the sequence defined by - * [first2, last2), and returns an {@link Iterator} to its first element, or last1,/i> if no - * occurrences are found.

- * - *

The elements in both ranges are compared sequentially using {@link equal_to}: A subsequence of - * [first1, last1) is considered a match only when this is true for all the elements of - * [first2, last2).

- * - *

This function returns the last of such occurrences. For an algorithm that returns the first instead, see - * {@link search}.

- * - * @param first1 An {@link Iterator} to the initial position of the first sequence. - * @param last1 An {@link Iterator} to the final position in a sequence. The range used is - * [first1, last1), including the element pointed by first1, but not the element - * pointed by last1. - * @param first2 An {@link Iterator} to the initial position of the element values to be searched for. - * @param last2 An {@link Iterator} to the final position of the element values to be searched for. The range used - * is [first2, last2). - * @param pred Binary function that accepts two elements as arguments (one of each of the two sequences, in the - * same order), and returns a value convertible to bool. The value returned indicates - * whether the elements are considered to match in the context of this function. - * - * @return An {@link Iterator} to the first element of the last occurrence of [first2, last2) in - * [first1, last1). If the sequence is not found, the function returns ,i>last1
. Otherwise - * [first2, last2) is an empty range, the function returns last1. - */ - function find_end, Iterator2 extends Iterator>(first1: Iterator1, last1: Iterator1, first2: Iterator2, last2: Iterator2): Iterator1; - /** - *

Find last subsequence in range.

- * - *

Searches the range [first1, last1) for the last occurrence of the sequence defined by - * [first2, last2), and returns an {@link Iterator} to its first element, or last1,/i> if no - * occurrences are found.

- * - *

The elements in both ranges are compared sequentially using pred: A subsequence of - * [first1, last1) is considered a match only when this is true for all the elements of - * [first2, last2).

- * - *

This function returns the last of such occurrences. For an algorithm that returns the first instead, see - * {@link search}.

- * - * @param first1 An {@link Iterator} to the initial position of the first sequence. - * @param last1 An {@link Iterator} to the final position in a sequence. The range used is - * [first1, last1), including the element pointed by first1, but not the element - * pointed by last1. - * @param first2 An {@link Iterator} to the initial position of the element values to be searched for. - * @param last2 An {@link Iterator} to the final position of the element values to be searched for. The range used - * is [first2, last2). - * @param pred Binary function that accepts two elements as arguments (one of each of the two sequences, in the - * same order), and returns a value convertible to bool. The value returned indicates - * whether the elements are considered to match in the context of this function. - * - * @return An {@link Iterator} to the first element of the last occurrence of [first2, last2) in - * [first1, last1). If the sequence is not found, the function returns ,i>last1
. Otherwise - * [first2, last2) is an empty range, the function returns last1. - */ - function find_end, Iterator2 extends Iterator>(first1: Iterator1, last1: Iterator1, first2: Iterator2, last2: Iterator2, pred: (x: T, y: T) => boolean): Iterator1; - /** - *

Find element from set in range.

- * - *

Returns an iterator to the first element in the range [first1, last1) that matches any of the - * elements in [first2, last2). If no such element is found, the function returns last1.

- * - *

The elements in [first1, last1) are sequentially compared to each of the values in - * [first2, last2) using {@link equal_to}, until a pair matches.

- * - * @param first1 An {@link Iterator} to the initial position of the first sequence. - * @param last1 An {@link Iterator} to the final position in a sequence. The range used is - * [first1, last1), including the element pointed by first1, but not the element - * pointed by last1. - * @param first2 An {@link Iterator} to the initial position of the element values to be searched for. - * @param last2 An {@link Iterator} to the final position of the element values to be searched for. The range used - * is [first2, last2). - * - * @return An {@link Iterator} to the first element in [first1, last1) that is part of - * [first2, last2). If no matches are found, the function returns last1. - */ - function find_first_of, Iterator2 extends Iterator>(first1: Iterator1, last1: Iterator1, first2: Iterator2, last2: Iterator2): Iterator1; - /** - *

Find element from set in range.

- * - *

Returns an iterator to the first element in the range [first1, last1) that matches any of the - * elements in [first2, last2). If no such element is found, the function returns last1.

- * - *

The elements in [first1, last1) are sequentially compared to each of the values in - * [first2, last2) using pred, until a pair matches.

- * - * @param first1 An {@link Iterator} to the initial position of the first sequence. - * @param last1 An {@link Iterator} to the final position in a sequence. The range used is - * [first1, last1), including the element pointed by first1, but not the element - * pointed by last1. - * @param first2 An {@link Iterator} to the initial position of the element values to be searched for. - * @param last2 An {@link Iterator} to the final position of the element values to be searched for. The range used - * is [first2, last2). - * @param pred Binary function that accepts two elements as arguments (one of each of the two sequences, in the - * same order), and returns a value convertible to bool. The value returned indicates - * whether the elements are considered to match in the context of this function. - * - * @return An {@link Iterator} to the first element in [first1, last1) that is part of - * [first2, last2). If no matches are found, the function returns last1. - */ - function find_first_of, Iterator2 extends Iterator>(first1: Iterator1, last1: Iterator1, first2: Iterator2, last2: Iterator2, pred: (x: T, y: T) => boolean): Iterator1; - /** - *

Find equal adjacent elements in range.

- * - *

Searches the range [first, last) for the first occurrence of two consecutive elements that match, - * and returns an {@link Iterator} to the first of these two elements, or last if no such pair is found.

- * - *

Two elements match if they compare equal using {@link equal_to}.

- * - * @param first An {@link Iterator} to the initial position in a sequence. - * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), - * which contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - * - * @return An {@link Iterator} to the first element of the first pair of matching consecutive elements in the range - * [first, last). If no such pair is found, the function returns last. - */ - function adjacent_find>(first: InputIterator, last: InputIterator): InputIterator; - /** - *

Find equal adjacent elements in range.

- * - *

Searches the range [first, last) for the first occurrence of two consecutive elements that match, - * and returns an {@link Iterator} to the first of these two elements, or last if no such pair is found.

- * - *

Two elements match if they compare equal using pred.

- * - * @param first An {@link Iterator} to the initial position in a sequence. - * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), - * which contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - * @param pred Unary function that accepts an element in the range as argument and returns a value convertible to - * bool. The value returned indicates whether the element is considered a match in the - * context of this function. The function shall not modify its argument. - * - * @return An {@link Iterator} to the first element of the first pair of matching consecutive elements in the range - * [first, last). If no such pair is found, the function returns last. - */ - function adjacent_find>(first: InputIterator, last: InputIterator, pred: (x: T, y: T) => boolean): InputIterator; - /** - *

Search range for subsequence.

- * - *

Searches the range [first1, last1) for the first occurrence of the sequence defined by - * [first2, last2), and returns an iterator to its first element, or last1 if no occurrences are - * found.

- * - *

The elements in both ranges are compared sequentially using {@link equal_to}: A subsequence of - * [first1, last1) is considered a match only when this is true for all the elements of - * [first2, last2).

- * - *

This function returns the first of such occurrences. For an algorithm that returns the last instead, see - * {@link find_end}.

- * - * @param first1 {@link Iterator Forward iterator} to the initial position of the searched sequence. - * @param last1 {@link Iterator Forward iterator} to the final position of the searched sequence. The range used is - * [first1, last1), which contains all the elements between first1 and last1, - * including the element pointed by first1 but not the element pointed by last1. - * @param first2 {@link Iterator Forward iterator} to the initial position of the sequence to be searched for. - * @param last2 {@link Iterator Forward iterator} to the final position of the sequence to be searched for. The range - * used is [first2, last2). - * - * @return An iterator to the first element of the first occurrence of [first2, last2) in first1 - * and last1. If the sequence is not found, the function returns last1. Otherwise - * [first2, last2) is an empty range, the function returns first1. - */ - function search, ForwardIterator2 extends Iterator>(first1: ForwardIterator1, last1: ForwardIterator1, first2: ForwardIterator2, last2: ForwardIterator2): ForwardIterator1; - /** - *

Search range for subsequence.

- * - *

Searches the range [first1, last1) for the first occurrence of the sequence defined by - * [first2, last2), and returns an iterator to its first element, or last1 if no occurrences are - * found.

- * - *

The elements in both ranges are compared sequentially using pred: A subsequence of - * [first1, last1) is considered a match only when this is true for all the elements of - * [first2, last2).

- * - *

This function returns the first of such occurrences. For an algorithm that returns the last instead, see - * {@link find_end}.

- * - * @param first1 {@link Iterator Forward iterator} to the initial position of the searched sequence. - * @param last1 {@link Iterator Forward iterator} to the final position of the searched sequence. The range used is - * [first1, last1), which contains all the elements between first1 and last1, - * including the element pointed by first1 but not the element pointed by last1. - * @param first2 {@link Iterator Forward iterator} to the initial position of the sequence to be searched for. - * @param last2 {@link Iterator Forward iterator} to the final position of the sequence to be searched for. The range - * used is [first2, last2). - * @param pred Binary function that accepts two elements as arguments (one of each of the two sequences, in the same - * order), and returns a value convertible to bool. The returned value indicates whether the elements are - * considered to match in the context of this function. The function shall not modify any of its - * arguments. - * - * @return An iterator to the first element of the first occurrence of [first2, last2) in - * [first1, last1). If the sequence is not found, the function returns last1. Otherwise - * [first2, last2) is an empty range, the function returns first1. - */ - function search, ForwardIterator2 extends Iterator>(first1: ForwardIterator1, last1: ForwardIterator1, first2: ForwardIterator2, last2: ForwardIterator2, pred: (x: T, y: T) => boolean): ForwardIterator1; - /** - *

Search range for elements.

- * - *

Searches the range [first, last) for a sequence of count elements, each comparing equal to - * val.

- * - *

The function returns an iterator to the first of such elements, or last if no such sequence is found. - *

- * - * @param first {@link Iterator Forward iterator} to the initial position of the searched sequence. - * @param last {@link Iterator Forward iterator} to the final position of the searched sequence. The range used is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * @param count Minimum number of successive elements to match. - * @param val Individual value to be compared, or to be used as argument for {@link equal_to}. - * - * @return An iterator to the first element of the sequence. If no such sequence is found, the function returns - * last. - */ - function search_n>(first: ForwardIterator, last: ForwardIterator, count: number, val: T): ForwardIterator; - /** - *

Search range for elements.

- * - *

Searches the range [first, last) for a sequence of count elements, each comparing equal to - * val.

- * - *

The function returns an iterator to the first of such elements, or last if no such sequence is found. - *

- * - * @param first {@link Iterator Forward iterator} to the initial position of the searched sequence. - * @param last {@link Iterator Forward iterator} to the final position of the searched sequence. The range used is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * @param count Minimum number of successive elements to match. - * @param val Individual value to be compared, or to be used as argument for pred. - * @param pred Binary function that accepts two arguments (one element from the sequence as first, and val as - * second), and returns a value convertible to bool. The value returned indicates whether the - * element is considered a match in the context of this function. The function shall not modify any of its - * arguments. - * - * @return An {@link Iterator} to the first element of the sequence. If no such sequence is found, the function - * returns last. - */ - function search_n>(first: ForwardIterator, last: ForwardIterator, count: number, val: T, pred: (x: T, y: T) => boolean): ForwardIterator; - /** - *

Return first position where two ranges differ.

- * - *

Compares the elements in the range [first1, last1) with those in the range beginning at - * first2, and returns the first element of both sequences that does not match.

- * - *

The function returns a {@link Pair} of {@link iterators Iterator} to the first element in each range that - * does not match.

- * - * @param first1 An {@link Iterator} to the initial position of the first sequence. - * @param last1 An {@link Iterator} to the final position in a sequence. The range used is - * [first1, last1), including the element pointed by first1, but not the element - * pointed by last1. - * @param first2 An {@link Iterator} to the initial position of the second sequence. The comparison includes up to - * as many elements of this sequence as those in the range [first1, last1). - * - * @return A {@link Pair}, where its members {@link Pair.first first} and {@link Pair.second second} point to the - * first element in both sequences that did not compare equal to each other. If the elements compared in - * both sequences have all matched, the function returns a {@link Pair} with {@link Pair.first first} set - * to last1 and {@link Pair.second second} set to the element in that same relative position in the - * second sequence. If none matched, it returns {@link make_pair}(first1, first2). - */ - function mismatch, Iterator2 extends Iterator>(first1: Iterator1, last1: Iterator1, first2: Iterator2): Pair; - /** - *

Return first position where two ranges differ.

- * - *

Compares the elements in the range [first1, last1) with those in the range beginning at - * first2, and returns the first element of both sequences that does not match.

- * - *

The function returns a {@link Pair} of {@link iterators Iterator} to the first element in each range that - * does not match.

- * - * @param first1 An {@link Iterator} to the initial position of the first sequence. - * @param last1 An {@link Iterator} to the final position in a sequence. The range used is - * [first1, last1), including the element pointed by first1, but not the element - * pointed by last1. - * @param first2 An {@link Iterator} to the initial position of the second sequence. The comparison includes up to - * as many elements of this sequence as those in the range [first1, last1). - * @param pred Binary function that accepts two elements as argument (one of each of the two sequences, in the same - * order), and returns a value convertible to bool. The value returned indicates whether - * the elements are considered to match in the context of this function. - * - * @return A {@link Pair}, where its members {@link Pair.first first} and {@link Pair.second second} point to the - * first element in both sequences that did not compare equal to each other. If the elements compared in - * both sequences have all matched, the function returns a {@link Pair} with {@link Pair.first first} set - * to last1 and {@link Pair.second second} set to the element in that same relative position in the - * second sequence. If none matched, it returns {@link make_pair}(first1, first2). - */ - function mismatch, Iterator2 extends Iterator>(first1: Iterator1, last1: Iterator1, first2: Iterator2, compare: (x: T, y: T) => boolean): Pair; - /** - *

Count appearances of value in range.

- * - *

Returns the number of elements in the range [first, last) that compare equal to val.

- * - *

The function uses {@link equal_to} to compare the individual elements to val.

- * - * @param first An {@link Iterator} to the initial position in a sequence. - * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), - * which contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - * @param val Value to match. - * - * @return The number of elements in the range [first, last) that compare equal to val. - */ - function count>(first: InputIterator, last: InputIterator, val: T): number; - /** - *

Return number of elements in range satisfying condition.

- * - *

Returns the number of elements in the range [first, last) for which pred is true. - *

- * - * @param first An {@link Iterator} to the initial position in a sequence. - * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), - * which contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - * @param pred Unary function that accepts an element in the range as argument, and returns a value convertible - * to bool. The value returned indicates whether the element is counted by this function. - * The function shall not modify its argument. This can either be a function pointer or a function - * object. - */ - function count_if>(first: InputIterator, last: InputIterator, pred: (val: T) => boolean): number; -} -declare namespace std { - /** - *

Copy range of elements.

- * - *

Copies the elements in the range [first, last) into the range beginning at result.

- * - *

The function returns an iterator to the end of the destination range (which points to the element following the - * last element copied).

- * - *

The ranges shall not overlap in such a way that result points to an element in the range - * [first, last). For such cases, see {@link copy_backward}.

- * - * @param first {@link Iterator Input iterator} to the initial position in a sequence to be copied. - * @param last {@link Iterator Input iterator} to the initial position in a sequence to be copied. The range used is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * @param result {@link Iterator Output iterator} to the initial position in the destination sequence. This shall not - * point to any element in the range [first, last). - * - * @return An iterator to the end of the destination range where elements have been copied. - */ - function copy, OutputIterator extends base.ILinearIterator>(first: InputIterator, last: InputIterator, result: OutputIterator): OutputIterator; - /** - *

Copy elements.

- * - *

Copies the first n elements from the range beginning at first into the range beginning at - * result.

- * - *

The function returns an iterator to the end of the destination range (which points to one past the last element - * copied).

- * - *

If n is negative, the function does nothing.

- * - *

If the ranges overlap, some of the elements in the range pointed by result may have undefined but valid values. - *

- * - * @param first {@link Iterator Input iterator} to the initial position in a sequence of at least n elements to - * be copied. InputIterator shall point to a type assignable to the elements pointed by - * OutputIterator. - * @param n Number of elements to copy. If this value is negative, the function does nothing. - * @param result {@link Iterator Output iterator} to the initial position in the destination sequence of at least - * n elements. This shall not point to any element in the range [first, last]. - * - * @return An iterator to the end of the destination range where elements have been copied. - */ - function copy_n, OutputIterator extends base.ILinearIterator>(first: InputIterator, n: number, result: OutputIterator): OutputIterator; - /** - *

Copy certain elements of range.

- * - *

Copies the elements in the range [first, last) for which pred returns true to the - * range beginning at result.

- * - * @param first {@link Iterator Input iterator} to the initial position in a sequence to be copied. - * @param last {@link Iterator Input iterator} to the initial position in a sequence to be copied. The range used is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * @param result {@link Iterator Output iterator} to the initial position in the destination sequence. This shall not - * point to any element in the range [first, last). - * @param pred Unary function that accepts an element in the range as argument, and returns a value convertible to - * bool. The value returned indicates whether the element is to be copied (if - * true, it is copied). The function shall not modify any of its arguments. - * - * @return An iterator to the end of the destination range where elements have been copied. - */ - function copy_if, OutputIterator extends base.ILinearIterator>(first: InputIterator, last: InputIterator, result: OutputIterator, pred: (x: T) => boolean): OutputIterator; - /** - *

Copy range of elements backward.

- * - *

Copies the elements in the range [first, last) starting from the end into the range terminating - * at result.

- * - *

The function returns an iterator to the first element in the destination range.

- * - *

The resulting range has the elements in the exact same order as [first, last). To reverse their - * order, see {@link reverse_copy}.

- * - *

The function begins by copying *(last-1) into *(result-1), and then follows backward - * by the elements preceding these, until first is reached (and including it).

- * - *

The ranges shall not overlap in such a way that result (which is the past-the-end element in the - * destination range) points to an element in the range (first,last]. For such cases, see {@link copy}.

- * - * @param first {@link Iterator Bidirectional iterator} to the initial position in a sequence to be copied. - * @param last {@link Iterator Bidirectional iterator} to the initial position in a sequence to be copied. The range - * used is [first, last), which contains all the elements between first and - * last, including the element pointed by first but not the element pointed by last. - * @param result {@link Iterator Bidirectional iterator} to the initial position in the destination sequence. This - * shall not point to any element in the range [first, last). - * - * @return An iterator to the first element of the destination sequence where elements have been copied. - */ - function copy_backward, BidirectionalIterator2 extends base.ILinearIterator>(first: BidirectionalIterator1, last: BidirectionalIterator1, result: BidirectionalIterator2): BidirectionalIterator2; - /** - *

Fill range with value.

- * - *

Assigns val to all the elements in the range [first, last).

- * - * @param first {@link Iterator Forward iterator} to the initial position in a sequence of elements that support being - * assigned a value of type T. - * @param last {@link Iterator Forward iterator} to the final position in a sequence of elements that support being - * assigned a value of type T.. The range filled is [first, last), which contains - * all the elements between first and last, including the element pointed by first - * but not the element pointed by last. - * @param val Value to assign to the elements in the filled range. - */ - function fill>(first: ForwardIterator, last: ForwardIterator, val: T): void; - /** - *

Fill sequence with value.

- * - *

Assigns val to the first n elements of the sequence pointed by first.

- * - * @param first {@link Iterator Output iterator} to the initial position in a sequence of elements that support being - * assigned a value of type T. - * @param n Number of elements to fill. If negative, the function does nothing. - * @param val Value to be used to fill the range. - * - * @return An iterator pointing to the element that follows the last element filled. - */ - function fill_n>(first: OutputIterator, n: number, val: T): OutputIterator; - /** - *

Transform range.

- * - *

Applies op to each of the elements in the range [first, last) and stores the value returned - * by each operation in the range that begins at result.

- * - * @param first {@link Iterator Input iterator} to the initial position in a sequence to be transformed. - * @param last {@link Iterator Input iterator} to the initial position in a sequence to be transformed. The range - * used is [first, last), which contains all the elements between first and - * last, including the element pointed by first but not the element pointed by last. - * @param result {@link Iterator Output} iterator to the initial position of the range where the operation results are - * stored. The range includes as many elements as [first, last). - * @param op Unary function that accepts one element of the type pointed to by InputIterator as argument, and - * returns some result value convertible to the type pointed to by OutputIterator. - * - * @return An iterator pointing to the element that follows the last element written in the result sequence. - */ - function transform, OutputIterator extends base.ILinearIterator>(first: InputIterator, last: InputIterator, result: OutputIterator, op: (val: T) => T): OutputIterator; - /** - *

Transform range.

- * - *

Calls binary_op using each of the elements in the range [first1, last1) as first argument, - * and the respective argument in the range that begins at first2 as second argument. The value returned by - * each call is stored in the range that begins at result.

- * - * @param first1 {@link Iterator Input iterator} to the initial position of the first sequence. - * @param last1 {@link Iterator Input iterator} to the final position of the first sequence. The range used is - * [first1, last1), including the element pointed by first1, but not the element - * pointed by last1. - * @param first2 {@link Iterator Input iterator} to the initial position of the second range. The range includes as - * many elements as [first1, last1). - * @param result {@link Iterator Output} iterator to the initial position of the range where the operation results are - * stored. The range includes as many elements as [first1, last1). - * @param binary_op Binary function that accepts two elements as argument (one of each of the two sequences), and - * returns some result value convertible to the type pointed to by OutputIterator. - * - * @return An iterator pointing to the element that follows the last element written in the result sequence. - */ - function transform, InputIterator2 extends Iterator, OutputIterator extends base.ILinearIterator>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, result: OutputIterator, binary_op: (x: T, y: T) => T): OutputIterator; - /** - *

Generate values for range with function.

- * - *

Assigns the value returned by successive calls to gen to the elements in the range [first, last). - *

- * - * @param first {@link Iterator Forward iterator} to the initial position in a sequence. - * @param last {@link Iterator Forward iterator} to the final position in a sequence. The range affected is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * @param gen Generator function that is called with no arguments and returns some value of a type convertible to - * those pointed by the iterators. - */ - function generate>(first: ForwardIterator, last: ForwardIterator, gen: () => T): void; - /** - *

Generate values for sequence with function.

- * - *

Assigns the value returned by successive calls to gen to the first n elements of the sequence - * pointed by first.

- * - * @param first {@link Iterator Output iterator} to the initial position in a sequence of at least n elements - * that support being assigned a value of the type returned by gen. - * @param n Number of values to generate. If negative, the function does nothing. - * @param gen Generator function that is called with no arguments and returns some value of a type convertible to - * those pointed by the iterators. - * - * @return An iterator pointing to the element that follows the last element whose value has been generated. - */ - function generate_n>(first: ForwardIterator, n: number, gen: () => T): ForwardIterator; - /** - *

Remove consecutive duplicates in range.

- * - *

Removes all but the first element from every consecutive group of equivalent elements in the range - * [first, last).

- * - *

The function cannot alter the properties of the object containing the range of elements (i.e., it cannot - * alter the size of an array or a container): The removal is done by replacing the duplicate elements by the next - * element that is not a duplicate, and signaling the new size of the shortened range by returning an iterator to - * the element that should be considered its new past-the-last element.

- * - *

The relative order of the elements not removed is preserved, while the elements between the returned - * iterator and last are left in a valid but unspecified state.

- * - * @param first An {@link Iterator} to the initial position in a sequence. - * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), - * which contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - * - * @return An iterator to the element that follows the last element not removed. The range between first and - * this iterator includes all the elements in the sequence that were not considered duplicates. - */ - function unique>(first: InputIterator, last: InputIterator): InputIterator; - /** - *

Remove consecutive duplicates in range.

- * - *

Removes all but the first element from every consecutive group of equivalent elements in the range - * [first, last).

- * - *

The function cannot alter the properties of the object containing the range of elements (i.e., it cannot - * alter the size of an array or a container): The removal is done by replacing the duplicate elements by the next - * element that is not a duplicate, and signaling the new size of the shortened range by returning an iterator to - * the element that should be considered its new past-the-last element.

- * - *

The relative order of the elements not removed is preserved, while the elements between the returned - * iterator and last are left in a valid but unspecified state.

- * - * @param first An {@link Iterator} to the initial position in a sequence. - * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), - * which contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - * @param pred Binary function that accepts two elements in the range as argument, and returns a value convertible - * to bool. The value returned indicates whether both arguments are considered equivalent - * (if true, they are equivalent and one of them is removed). The function shall not modify - * any of its arguments. - * - * @return An iterator to the element that follows the last element not removed. The range between first and - * this iterator includes all the elements in the sequence that were not considered duplicates. - */ - function unique>(first: InputIterator, last: InputIterator, pred: (left: t, right: t) => boolean): InputIterator; - /** - *

Copy range removing duplicates.

- * - *

Copies the elements in the range [first, last) to the range beginning at result, except - * consecutive duplicates (elements that compare equal to the element preceding).

- * - *

Only the first element from every consecutive group of equivalent elements in the range - * [first, last) is copied.

- * - *

The comparison between elements is performed by applying {@lnk equal_to}.

- * - * @param first {@link Iterator Forward iterator} to the initial position in a sequence. - * @param last {@link Iterator Forward iterator} to the final position in a sequence. The range used is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * @param result Output iterator to the initial position of the range where the resulting range of values is stored. - * The pointed type shall support being assigned the value of an element in the range - * [first, last). - * - * @return An iterator pointing to the end of the copied range, which contains no consecutive duplicates. - */ - function unique_copy, OutputIterator extends base.ILinearIterator>(first: InputIterator, last: InputIterator, result: OutputIterator): OutputIterator; - /** - *

Copy range removing duplicates.

- * - *

Copies the elements in the range [first, last) to the range beginning at result, except - * consecutive duplicates (elements that compare equal to the element preceding).

- * - *

Only the first element from every consecutive group of equivalent elements in the range - * [first, last) is copied.

- * - *

The comparison between elements is performed by applying pred.

- * - * @param first {@link Iterator Forward iterator} to the initial position in a sequence. - * @param last {@link Iterator Forward iterator} to the final position in a sequence. The range used is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * @param result Output iterator to the initial position of the range where the resulting range of values is stored. - * The pointed type shall support being assigned the value of an element in the range - * [first, last). - * @param pred Binary function that accepts two elements in the range as argument, and returns a value convertible to - * bool. The value returned indicates whether both arguments are considered equivalent (if - * true, they are equivalent and one of them is removed). The function shall not modify any - * of its arguments. - * - * @return An iterator pointing to the end of the copied range, which contains no consecutive duplicates. - */ - function unique_copy, OutputIterator extends base.ILinearIterator>(first: InputIterator, last: InputIterator, result: OutputIterator, pred: (x: T, y: T) => boolean): OutputIterator; - /** - *

Remove value from range.

- * - *

Transforms the range [first, last) into a range with all the elements that compare equal to - * val removed, and returns an iterator to the new last of that range.

- * - *

The function cannot alter the properties of the object containing the range of elements (i.e., it cannot alter - * the size of an array or a container): The removal is done by replacing the elements that compare equal to - * val by the next element that does not, and signaling the new size of the shortened range by returning an - * iterator to the element that should be considered its new past-the-last element.

- * - *

The relative order of the elements not removed is preserved, while the elements between the returned iterator - * and last are left in a valid but unspecified state.

- * - * @param first An {@link Iterator} to the initial position in a sequence. - * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), - * which contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - * @param val Value to be removed. - */ - function remove>(first: InputIterator, last: InputIterator, val: T): InputIterator; - /** - *

Remove elements from range.

- * - *

Transforms the range [first, last) into a range with all the elements for which pred returns - * true removed, and returns an iterator to the new last of that range.

- * - *

The function cannot alter the properties of the object containing the range of elements (i.e., it cannot - * alter the size of an array or a container): The removal is done by replacing the elements for which pred returns - * true by the next element for which it does not, and signaling the new size of the shortened range - * by returning an iterator to the element that should be considered its new past-the-last element.

- * - *

The relative order of the elements not removed is preserved, while the elements between the returned - * iterator and last are left in a valid but unspecified state.

- * - * @param first An {@link Iterator} to the initial position in a sequence. - * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), - * which contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - * @param pred Unary function that accepts an element in the range as argument, and returns a value convertible to - * bool. The value returned indicates whether the element is to be removed (if - * true, it is removed). The function shall not modify its argument. - */ - function remove_if>(first: InputIterator, last: InputIterator, pred: (left: T) => boolean): InputIterator; - /** - *

Copy range removing value.

- * - *

Copies the elements in the range [first, last) to the range beginning at result, except - * those elements that compare equal to val.

- * - *

The resulting range is shorter than [first, last) by as many elements as matches in the sequence, - * which are "removed".

- * - *

The function uses {@link equal_to} to compare the individual elements to val.

- * - * @param first {@link Iterator InputIterator} to the initial position in a sequence. - * @param last {@link Iterator InputIterator} to the final position in a sequence. The range used is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting sequence is - * stored. The pointed type shall support being assigned the value of an element in the range - * [first, last). - * @param val Value to be removed. - * - * @return An iterator pointing to the end of the copied range, which includes all the elements in - * [first, last) except those that compare equal to val. - */ - function remove_copy, OutputIterator extends base.ILinearIterator>(first: InputIterator, last: InputIterator, result: OutputIterator, val: T): OutputIterator; - /** - *

Copy range removing values.

- * - *

Copies the elements in the range [first, last) to the range beginning at result, except - * those elements for which pred returns true.

- * - *

The resulting range is shorter than [first, last) by as many elements as matches, which are - * "removed".

- * - * @param first {@link Iterator InputIterator} to the initial position in a sequence. - * @param last {@link Iterator InputIterator} to the final position in a sequence. The range used is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting sequence is - * stored. The pointed type shall support being assigned the value of an element in the range - * [first, last). - * @param pred Unary function that accepts an element in the range as argument, and returns a value convertible to - * bool. The value returned indicates whether the element is to be removed from the copy (if - * true, it is not copied). The function shall not modify its argument. - * - * @return An iterator pointing to the end of the copied range, which includes all the elements in - * [first, last) except those for which pred returns true. - */ - function remove_copy_if, OutputIterator extends base.ILinearIterator>(first: InputIterator, last: InputIterator, result: OutputIterator, pred: (val: T) => boolean): OutputIterator; - /** - *

Replace value in range.

- * - *

Assigns new_val to all the elements in the range [first, last) that compare equal to - * old_val.

- * - *

The function uses {@link equal_to} to compare the individual elements to old_val.

- * - * @param first An {@link Iterator} to the initial position in a sequence. - * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), - * which contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - * @param old_val Value to be replaced. - * @param new_val Replacement value. - */ - function replace>(first: InputIterator, last: InputIterator, old_val: T, new_val: T): void; - /** - *

Replace value in range.

- * - *

Assigns new_val to all the elements in the range [first, last) for which pred returns - * true.

- * - * @param first An {@link Iterator} to the initial position in a sequence. - * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), - * which contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - * @param pred Unary function that accepts an element in the range as argument, and returns a value convertible to - * bool. The value returned indicates whether the element is to be replaced (if - * true, it is replaced). The function shall not modify its argument. - * @param new_val Value to assign to replaced elements. - */ - function replace_if>(first: InputIterator, last: InputIterator, pred: (val: T) => boolean, new_val: T): void; - /** - *

Copy range replacing value.

- * - *

Copies the elements in the range [first, last) to the range beginning at result, replacing - * the appearances of old_value by new_value.

- * - *

The function uses {@link std.equal_to} to compare the individual elements to old_value.

- * - *

The ranges shall not overlap in such a way that result points to an element in the range - * [first, last).

- * - * @param first {@link Iterator InputIterator} to the initial position in a sequence. - * @param last {@link Iterator InputIterator} to the final position in a sequence. The range used is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting sequence is - * stored. The pointed type shall support being assigned the value of an element in the range - * [first, last). - * @param old_val Value to be replaced. - * @param new_val Replacement value. - * - * @return An iterator pointing to the element that follows the last element written in the result sequence. - */ - function replace_copy, OutputIterator extends base.ILinearIterator>(first: InputIterator, last: InputIterator, result: OutputIterator, old_val: T, new_val: T): OutputIterator; - /** - *

Copy range replacing value.

- * - *

Copies the elements in the range [first, last) to the range beginning at result, replacing - * those for which pred returns true by new_value.

- * - * @param first {@link Iterator InputIterator} to the initial position in a sequence. - * @param last {@link Iterator InputIterator} to the final position in a sequence. The range used is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting sequence is - * stored. The pointed type shall support being assigned the value of an element in the range - * [first, last). - * @param pred Unary function that accepts an element in the range as argument, and returns a value convertible to - * bool. The value returned indicates whether the element is to be removed from the copy (if - * true, it is not copied). The function shall not modify its argument. - * @param new_val Value to assign to replaced values. - * - * @return An iterator pointing to the element that follows the last element written in the result sequence. - */ - function replace_copy_if, OutputIterator extends base.ILinearIterator>(first: InputIterator, last: InputIterator, result: OutputIterator, pred: (val: T) => boolean, new_val: T): OutputIterator; - /** - *

Exchange values of objects pointed to by two iterators.

- * - *

Swaps the elements pointed to by x and y.

- * - *

The function calls {@link Iterator.swap} to exchange the elements.

- * - * @param x {@link Iterator Forward iterator} to the objects to swap. - * @param y {@link Iterator Forward iterator} to the objects to swap. - */ - function iter_swap(x: Iterator, y: Iterator): void; - /** - *

Exchange values of two ranges.

- * - *

Exchanges the values of each of the elements in the range [first1, last1) with those of their - * respective elements in the range beginning at first2.

- * - *

The function calls {@link Iterator.swap} to exchange the elements.

- * - * @param first1 {@link Iterator Forward iterator} to the initial position of the first sequence. - * @param last1 {@link Iterator Forward iterator} to the final position of the first sequence. The range used is - * [first1, last1), including the element pointed by first1, but not the element - * pointed by last1. - * @param first2 {@link Iterator Forward iterator} to the initial position of the second range. The range includes as - * many elements as [first1, last1). The two ranges shall not overlap. - * - * @return An iterator to the last element swapped in the second sequence. - */ - function swap_ranges, ForwardIterator2 extends Iterator>(first1: ForwardIterator1, last1: ForwardIterator1, first2: ForwardIterator2): ForwardIterator2; - /** - *

Reverse range.

- * - *

Reverses the order of the elements in the range [first, last).

- * - *

The function calls {@link iter_swap} to swap the elements to their new locations.

- * - * @param first An {@link Iterator} to the initial position in a sequence. - * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), - * which contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - */ - function reverse>(first: InputIterator, last: InputIterator): void; - /** - *

Copy range reversed.

- * - *

Copies the elements in the range [first, last) to the range beginning at result, but in - * reverse order.

- * - * @param first {@link Iterator Bidirectional iterator} to the initial position in a sequence to be copied. - * @param last {@link Iterator Bidirectional iterator} to the initial position in a sequence to be copied. The range - * used is [first, last), which contains all the elements between first and - * last, including the element pointed by first but not the element pointed by last. - * @param result {@link Iterator Output iterator} to the initial position of the range where the reserved range is - * stored. The pointed type shall support being assigned the value of an element in the range - * [first, last). - * - * @return An output iterator pointing to the end of the copied range, which contains the same elements in reverse - * order. - */ - function reverse_copy, OutputIterator extends base.ILinearIterator>(first: BidirectionalIterator, last: BidirectionalIterator, result: OutputIterator): OutputIterator; - /** - *

Rotate left the elements in range.

- * - *

Rotates the order of the elements in the range [first, last), in such a way that the element - * pointed by middle becomes the new first element.

- * - * @param first An {@link Iterator} to the initial position in a sequence. - * @param middle An {@link Iterator} pointing to the element within the range [first, last) that is - * moved to the first position in the range. - * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), - * which contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - * - * @return An iterator pointing to the element that now contains the value previously pointed by first. - */ - function rotate>(first: InputIterator, middle: InputIterator, last: InputIterator): InputIterator; - /** - *

Copy range rotated left.

- * - *

Copies the elements in the range [first, last) to the range beginning at result, but - * rotating the order of the elements in such a way that the element pointed by middle becomes the first - * element in the resulting range.

- * - * @param first {@link Iterator Forward iterator} to the initial position of the range to be copy-rotated. - * @param middle Forward iterator pointing to the element within the range [first, last) that is copied as the first element in the resulting range. - * @param last {@link Iterator Forward iterator} to the final positions of the range to be copy-rotated. The range - * used is [first, last), which contains all the elements between first and - * last, including the element pointed by first but not the element pointed by last. - * Notice that in this function, these are not consecutive parameters, but the first and third ones. - * @param result {@link Iterator Output iterator} to the initial position of the range where the reserved range is - * stored. The pointed type shall support being assigned the value of an element in the range - * [first, last). - * - * @return An output iterator pointing to the end of the copied range. - */ - function rotate_copy, OutputIterator extends base.ILinearIterator>(first: ForwardIterator, middle: ForwardIterator, last: ForwardIterator, result: OutputIterator): OutputIterator; - /** - *

Randomly rearrange elements in range.

- * - *

Rearranges the elements in the range [first, last) randomly.

- * - *

The function swaps the value of each element with that of some other randomly picked element. When provided, - * the function gen determines which element is picked in every case. Otherwise, the function uses some unspecified - * source of randomness.

- * - *

To specify a uniform random generator, see {@link shuffle}.

- * - * @param first An {@link Iterator} to the initial position in a sequence. - * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), - * which contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - */ - function random_shuffle>(first: RandomAccessIterator, last: RandomAccessIterator): void; - /** - *

Randomly rearrange elements in range using generator.

- * - *

Rearranges the elements in the range [first, last) randomly, using g as uniform random - * number generator.

- * - *

The function swaps the value of each element with that of some other randomly picked element. The function - * determines the element picked by calling g().

- * - *

To shuffle the elements of the range without such a generator, see {@link random_shuffle} instead.

- * - *
Note
- *

Using random generator engine is not implemented yet.

- * - * @param first An {@link Iterator} to the initial position in a sequence. - * @param last An {@link Iterator} to the final position in a sequence. The range used is [first, last), - * which contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - */ - function shuffle>(first: RandomAccessIterator, last: RandomAccessIterator): void; -} -declare namespace std { - /** - *

Sort elements in range.

- * - *

Sorts the elements in the range [first, last) into ascending order. The elements are compared - * using {@link less}.

- * - * @param first {@link IArrayIterator Random-access iterator} to the initial position of the sequence to be sorted. - * @param last {@link IArrayIterator Random-access iterator} to the final position of the sequence to be sorted. - * The range used is [first, last), which contains all the elements between first - * and last, including the element pointed by first but not the element pointed by - * last. {@link IArrayIterator RandomAccessIterator} shall point to a type for which - * {@link Iterator.swap swap} is properly defined. - */ - function sort>(first: RandomAccessIterator, last: RandomAccessIterator): void; - /** - *

Sort elements in range.

- * - *

Sorts the elements in the range [first, last) into specific order. The elements are compared - * using compare.

- * - * @param first {@link IArrayIterator Random-access iterator} to the initial position of the sequence to be sorted. - * @param last {@link IArrayIterator Random-access iterator} to the final position of the sequence to be sorted. - * The range used is [first, last), which contains all the elements between first - * and last, including the element pointed by first but not the element pointed by - * last. {@link IArrayIterator RandomAccessIterator} shall point to a type for which - * {@link Iterator.swap swap} is properly defined. - * @param compare Binary function that accepts two elements in the range as arguments, and returns a value - * convertible to boolean. The value returned indicates whether the element passed as first - * argument is considered to go before the second in the specific strict weak ordering it defines. The - * function shall not modify any of its arguments. This can either be a function pointer or a function - * object. - */ - function sort>(first: RandomAccessIterator, last: RandomAccessIterator, compare: (left: T, right: T) => boolean): void; - /** - *

Partially sort elements in range.

- * - *

Rearranges the elements in the range [first, last), in such a way that the elements before - * middle are the smallest elements in the entire range and are sorted in ascending order, while the remaining - * elements are left without any specific order.

- * - *

The elements are compared using {@link less}.

- * - * @param last {@link IArrayIterator Random-access iterator} to the first position of the sequence to be sorted. - * @param middle {@link IArrayIterator Random-access iterator} pointing to the element within the range [first, last) that is used as the upper boundary of the elements that are fully sorted. - * @param last {@link IArrayIterator Random-access iterator} to the final position of the sequence to be sorted. - * The range used is [first, last), which contains all the elements between first - * and last, including the element pointed by first but not the element pointed by - * last. - */ - function partial_sort>(first: RandomAccessIterator, middle: RandomAccessIterator, last: RandomAccessIterator): void; - /** - *

Partially sort elements in range.

- * - *

Rearranges the elements in the range [first, last), in such a way that the elements before - * middle are the smallest elements in the entire range and are sorted in ascending order, while the remaining - * elements are left without any specific order.

- * - *

The elements are compared using comp.

- * - * @param last {@link IArrayIterator Random-access iterator} to the first position of the sequence to be sorted. - * @param middle {@link IArrayIterator Random-access iterator} pointing to the element within the range [first, last) that is used as the upper boundary of the elements that are fully sorted. - * @param last {@link IArrayIterator Random-access iterator} to the final position of the sequence to be sorted. - * The range used is [first, last), which contains all the elements between first - * and last, including the element pointed by first but not the element pointed by - * last. - * @param compare Binary function that accepts two elements in the range as arguments, and returns a value - * convertible to boolean. The value returned indicates whether the element passed as - * first argument is considered to go before the second in the specific strict weak ordering it - * defines. The function shall not modify any of its arguments. - */ - function partial_sort>(first: RandomAccessIterator, middle: RandomAccessIterator, last: RandomAccessIterator, compare: (x: T, y: T) => boolean): void; - /** - *

Copy and partially sort range.

- * - *

Copies the smallest elements in the range [first, last) to - * [result_first, result_last), sorting the elements copied. The number of elements copied is the same - * as the {@link distance} between result_first and result_last (unless this is more than the amount of - * elements in [first, last)).

- * - *

The range [first, last) is not modified.

- * - *

The elements are compared using {@link less}.

- * - * @param first {@link Iterator Input iterator} to the initial position of the sequence to copy from. - * @param last {@link Iterator Input iterator} to the final position of the sequence to copy from. The range used is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * InputIterator shall point to a type assignable to the elements pointed by - * RandomAccessIterator. - * @param result_first {@link Iterator Random-access iterator} to the initial position of the destination sequence. - * @param result_last {@link Iterator Random-access iterator} to the final position of the destination sequence. - * The range used is [result_first, result_last). - * @param compare Binary function that accepts two elements in the result range as arguments, and returns a value - * convertible to bool. The value returned indicates whether the element passed as first - * argument is considered to go before the second in the specific strict weak ordering it - * defines. The function shall not modify any of its arguments. - * - * @return An iterator pointing to the element that follows the last element written in the result sequence. - */ - function partial_sort_copy, RandomAccessIterator extends Iterator>(first: InputIterator, last: InputIterator, result_first: RandomAccessIterator, result_last: RandomAccessIterator): RandomAccessIterator; - /** - *

Copy and partially sort range.

- * - *

Copies the smallest (or largest) elements in the range [first, last) to - * [result_first, result_last), sorting the elements copied. The number of elements copied is the same - * as the {@link distance} between result_first and result_last (unless this is more than the amount of - * elements in [first, last)).

- * - *

The range [first, last) is not modified.

- * - *

The elements are compared using compare.

- * - * @param first {@link Iterator Input iterator} to the initial position of the sequence to copy from. - * @param last {@link Iterator Input iterator} to the final position of the sequence to copy from. The range used is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * InputIterator shall point to a type assignable to the elements pointed by - * RandomAccessIterator. - * @param result_first {@link Iterator Random-access iterator} to the initial position of the destination sequence. - * @param result_last {@link Iterator Random-access iterator} to the final position of the destination sequence. - * The range used is [result_first, result_last). - * @param compare Binary function that accepts two elements in the result range as arguments, and returns a value - * convertible to bool. The value returned indicates whether the element passed as first - * argument is considered to go before the second in the specific strict weak ordering it - * defines. The function shall not modify any of its arguments. - * - * @return An iterator pointing to the element that follows the last element written in the result sequence. - */ - function partial_sort_copy, RandomAccessIterator extends Iterator>(first: InputIterator, last: InputIterator, result_first: RandomAccessIterator, result_last: RandomAccessIterator, compare: (x: T, y: T) => boolean): RandomAccessIterator; - /** - *

Check whether range is sorted.

- * - *

Returns true if the range [first, last) is sorted into ascending order.

- * - *

The elements are compared using {@link less}.

- * - * @param first {@link Iterator Forward iterator} to the initial position of the sequence. - * @param last {@link Iterator Forward iterator} to the final position of the sequence. The range checked is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * - * @return true if the range [first, last) is sorted into ascending order, - * false otherwise. If the range [first, last) contains less than two elements, - * the function always returns true. - */ - function is_sorted>(first: ForwardIterator, last: ForwardIterator): boolean; - /** - *

Check whether range is sorted.

- * - *

Returns true if the range [first, last) is sorted into ascending order.

- * - *

The elements are compared using compare.

- * - * @param first {@link Iterator Forward iterator} to the initial position of the sequence. - * @param last {@link Iterator Forward iterator} to the final position of the sequence. The range checked is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * @param compare Binary function that accepts two elements in the range as arguments, and returns a value convertible - * to bool. The value returned indicates whether the element passed as first argument is - * considered to go before the second in the specific strict weak ordering it defines. The function - * shall not modify any of its arguments. - * - * @return true if the range [first, last) is sorted into ascending order, - * false otherwise. If the range [first, last) contains less than two elements, - * the function always returns true. - */ - function is_sorted>(first: ForwardIterator, last: ForwardIterator, compare: (x: T, y: T) => boolean): boolean; - /** - *

Find first unsorted element in range.

- * - *

Returns an iterator to the first element in the range [first, last) which does not follow an - * ascending order.

- * - *

The range between first and the iterator returned {@link is_sorted is sorted}.

- * - *

If the entire range is sorted, the function returns last.

- * - *

The elements are compared using {@link equal_to}.

- * - * @param first {@link Iterator Forward iterator} to the initial position of the sequence. - * @param last {@link Iterator Forward iterator} to the final position of the sequence. The range checked is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * @param compare Binary function that accepts two elements in the range as arguments, and returns a value convertible - * to bool. The value returned indicates whether the element passed as first argument is - * considered to go before the second in the specific strict weak ordering it defines. The function - * shall not modify any of its arguments. - * - * @return An iterator to the first element in the range which does not follow an ascending order, or last if - * all elements are sorted or if the range contains less than two elements. - */ - function is_sorted_until>(first: ForwardIterator, last: ForwardIterator): ForwardIterator; - /** - *

Find first unsorted element in range.

- * - *

Returns an iterator to the first element in the range [first, last) which does not follow an - * ascending order.

- * - *

The range between first and the iterator returned {@link is_sorted is sorted}.

- * - *

If the entire range is sorted, the function returns last.

- * - *

The elements are compared using compare.

- * - * @param first {@link Iterator Forward iterator} to the initial position of the sequence. - * @param last {@link Iterator Forward iterator} to the final position of the sequence. The range checked is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * @param compare Binary function that accepts two elements in the range as arguments, and returns a value convertible - * to bool. The value returned indicates whether the element passed as first argument is - * considered to go before the second in the specific strict weak ordering it defines. The function - * shall not modify any of its arguments. - * - * @return An iterator to the first element in the range which does not follow an ascending order, or last if - * all elements are sorted or if the range contains less than two elements. - */ - function is_sorted_until>(first: ForwardIterator, last: ForwardIterator, compare: (x: T, y: T) => boolean): ForwardIterator; -} -declare namespace std { - /** - *

Make heap from range.

- * - *

Rearranges the elements in the range [first, last) in such a way that they form a heap.

- * - *

A heap is a way to organize the elements of a range that allows for fast retrieval of the element with the - * highest value at any moment (with {@link pop_heap}), even repeatedly, while allowing for fast insertion of new - * elements (with {@link push_heap}).

- * - *

The element with the highest value is always pointed by first. The order of the other elements depends on the - * particular implementation, but it is consistent throughout all heap-related functions of this header.

- * - *

The elements are compared using {@link less}: The element with the highest value is an element for which this - * would return false when compared to every other element in the range.

- * - *

The standard container adaptor {@link PriorityQueue} calls {@link make_heap}, {@link push_heap} and - * {@link pop_heap} automatically to maintain heap properties for a container.

- * - * @param first {@link IArrayIterator Random-access iterator} to the initial position of the sequence to be - * transformed into a heap. - * @param last {@link IArrayIterator Random-access iterator} to the final position of the sequence to be transformed - * into a heap. The range used is [first, last), which contains all the elements between - * first and last, including the element pointed by first but not the element pointed - * by last. {@link IArrayIterator RandomAccessIterator} shall point to a type for which - * {@link Iterator.swap swap} is properly defined. - */ - function make_heap>(first: RandomAccessIterator, last: RandomAccessIterator): void; - /** - *

Make heap from range.

- * - *

Rearranges the elements in the range [first, last) in such a way that they form a heap.

- * - *

A heap is a way to organize the elements of a range that allows for fast retrieval of the element with the - * highest value at any moment (with {@link pop_heap}), even repeatedly, while allowing for fast insertion of new - * elements (with {@link push_heap}).

- * - *

The element with the highest value is always pointed by first. The order of the other elements depends on the - * particular implementation, but it is consistent throughout all heap-related functions of this header.

- * - *

The elements are compared using compare: The element with the highest value is an element for which this - * would return false when compared to every other element in the range.

- * - *

The standard container adaptor {@link PriorityQueue} calls {@link make_heap}, {@link push_heap} and - * {@link pop_heap} automatically to maintain heap properties for a container.

- * - * @param first {@link IArrayIterator Random-access iterator} to the initial position of the sequence to be - * transformed into a heap. - * @param last {@link IArrayIterator Random-access iterator} to the final position of the sequence to be transformed - * into a heap. The range used is [first, last), which contains all the elements between - * first and last, including the element pointed by first but not the element pointed - * by last. {@link IArrayIterator RandomAccessIterator} shall point to a type for which - * {@link Iterator.swap swap} is properly defined. - * @param compare Binary function that accepts two elements in the range as arguments, and returns a value - * convertible to boolean. The value returned indicates whether the element passed as - * first argument is considered to go before the second in the specific strict weak ordering it defines. - * The function shall not modify any of its arguments. This can either be a function pointer or a - * function object. - */ - function make_heap>(first: RandomAccessIterator, last: RandomAccessIterator, compare: (x: T, y: T) => boolean): void; - /** - *

Push element into heap range.

- * - *

Given a heap in the range [first, last - 1), this function extends the range considered a heap to - * [first, last) by placing the value in (last - 1) into its corresponding location within it. - *

- * - *

A range can be organized into a heap by calling {@link make_heap}. After that, its heap properties are - * preserved if elements are added and removed from it using {@link push_heap} and {@link pop_heap}, respectively. - *

- * - * @param first {@link IArrayIterator Random-access iterator} to the initial position of the new heap range, including - * the pushed element. - * @param last {@link IArrayIterator Random-access iterator} to the final position of the new heap range, including - * the pushed element. The range used is [first, last), which contains all the elements - * between first and last, including the element pointed by first but not the element - * pointed by last. {@link IArrayIterator RandomAccessIterator} shall point to a type for which - * {@link Iterator.swap swap} is properly defined. - */ - function push_heap>(first: RandomAccessIterator, last: RandomAccessIterator): void; - /** - *

Push element into heap range.

- * - *

Given a heap in the range [first, last - 1), this function extends the range considered a heap to - * [first, last) by placing the value in (last - 1) into its corresponding location within it. - *

- * - *

A range can be organized into a heap by calling {@link make_heap}. After that, its heap properties are - * preserved if elements are added and removed from it using {@link push_heap} and {@link pop_heap}, respectively. - *

- * - * @param first {@link IArrayIterator Random-access iterator} to the initial position of the new heap range, including - * the pushed element. - * @param last {@link IArrayIterator Random-access iterator} to the final position of the new heap range, including - * the pushed element. The range used is [first, last), which contains all the elements - * between first and last, including the element pointed by first but not the element - * pointed by last. {@link IArrayIterator RandomAccessIterator} shall point to a type for which - * {@link Iterator.swap swap} is properly defined. - * @param compare Binary function that accepts two elements in the range as arguments, and returns a value - * convertible to boolean. The value returned indicates whether the element passed as - * first argument is considered to go before the second in the specific strict weak ordering it defines. - * The function shall not modify any of its arguments. This can either be a function pointer or a - * function object. - */ - function push_heap>(first: RandomAccessIterator, last: RandomAccessIterator, compare: (x: T, y: T) => boolean): void; - /** - *

Pop element from heap range.

- * - *

Rearranges the elements in the heap range [first, last) in such a way that the part considered a - * heap is shortened by one: The element with the highest value is moved to (last - 1).

- * - *

While the element with the highest value is moved from first to (last - 1) (which now is out of the - * heap), the other elements are reorganized in such a way that the range [first, last - 1) preserves - * the properties of a heap.

- * - *

A range can be organized into a heap by calling {@link make_heap}. After that, its heap properties are - * preserved if elements are added and removed from it using {@link push_heap} and {@link pop_heap}, respectively. - *

- * - * @param first {@link IArrayIterator Random-access iterator} to the initial position of the heap to be shrank by one. - * @param last {@link IArrayIterator Random-access iterator} to the final position of the heap to be shrank by one. - * The range used is [first, last), which contains all the elements between first and - * last, including the element pointed by first but not the element pointed by last. - * {@link IArrayIterator RandomAccessIterator} shall point to a type for which {@link Iterator.swap swap} - * is properly defined. - */ - function pop_heap>(first: RandomAccessIterator, last: RandomAccessIterator): void; - /** - *

Pop element from heap range.

- * - *

Rearranges the elements in the heap range [first, last) in such a way that the part considered a - * heap is shortened by one: The element with the highest value is moved to (last - 1).

- * - *

While the element with the highest value is moved from first to (last - 1) (which now is out of the - * heap), the other elements are reorganized in such a way that the range [first, last - 1) preserves - * the properties of a heap.

- * - *

A range can be organized into a heap by calling {@link make_heap}. After that, its heap properties are - * preserved if elements are added and removed from it using {@link push_heap} and {@link pop_heap}, respectively. - *

- * - * @param first {@link IArrayIterator Random-access iterator} to the initial position of the heap to be shrank by one. - * @param last {@link IArrayIterator Random-access iterator} to the final position of the heap to be shrank by one. - * The range used is [first, last), which contains all the elements between first and - * last, including the element pointed by first but not the element pointed by last. - * {@link IArrayIterator RandomAccessIterator} shall point to a type for which {@link Iterator.swap swap} - * is properly defined. - * @param compare Binary function that accepts two elements in the range as arguments, and returns a value - * convertible to boolean. The value returned indicates whether the element passed as - * first argument is considered to go before the second in the specific strict weak ordering it defines. - * The function shall not modify any of its arguments. This can either be a function pointer or a - * function object. - */ - function pop_heap>(first: RandomAccessIterator, last: RandomAccessIterator, compare: (x: T, y: T) => boolean): void; - /** - *

Test if range is heap.

- * - *

Returns true if the range [first, last) forms a heap, as if constructed with {@link make_heap}. - *

- * - *

The elements are compared using {@link less}.

- * - * @param first {@link IArrayIterator Random-access iterator} to the initial position of the sequence. - * @param last {@link IArrayIterator Random-access iterator} to the final position of the sequence. The range used is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * {@link IArrayIterator RandomAccessIterator} shall point to a type for which {@link Iterator.swap swap} - * is properly defined. - * - * @return true if the range [first, last) is a heap (as if constructed with - * {@link make_heap}), false otherwise. If the range [first, last) contains less - * than two elements, the function always returns true. - */ - function is_heap>(first: RandomAccessIterator, last: RandomAccessIterator): boolean; - /** - *

Test if range is heap.

- * - *

Returns true if the range [first, last) forms a heap, as if constructed with {@link make_heap}. - *

- * - *

The elements are compared using compare.

- * - * @param first {@link IArrayIterator Random-access iterator} to the initial position of the sequence. - * @param last {@link IArrayIterator Random-access iterator} to the final position of the sequence. The range used is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * {@link IArrayIterator RandomAccessIterator} shall point to a type for which {@link Iterator.swap swap} - * is properly defined. - * @param compare Binary function that accepts two elements in the range as arguments, and returns a value - * convertible to boolean. The value returned indicates whether the element passed as - * first argument is considered to go before the second in the specific strict weak ordering it defines. - * The function shall not modify any of its arguments. This can either be a function pointer or a - * function object. - * - * @return true if the range [first, last) is a heap (as if constructed with - * {@link make_heap}), false otherwise. If the range [first, last) contains less - * than two elements, the function always returns true. - */ - function is_heap>(first: RandomAccessIterator, last: RandomAccessIterator, compare: (x: T, y: T) => boolean): boolean; - /** - *

Find first element not in heap order.

- * - *

Returns an iterator to the first element in the range [first, last) which is not in a valid - * position if the range is considered a heap (as if constructed with {@link make_heap}).

- * - *

The range between first and the iterator returned is a heap.

- * - *

If the entire range is a valid heap, the function returns last.

- * - *

The elements are compared using {@link less}.

- * - * @param first {@link IArrayIterator Random-access iterator} to the initial position of the sequence. - * @param last {@link IArrayIterator Random-access iterator} to the final position of the sequence. The range used is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * {@link IArrayIterator RandomAccessIterator} shall point to a type for which {@link Iterator.swap swap} - * is properly defined. - */ - function is_heap_until>(first: RandomAccessIterator, last: RandomAccessIterator): RandomAccessIterator; - /** - *

Find first element not in heap order.

- * - *

Returns an iterator to the first element in the range [first, last) which is not in a valid - * position if the range is considered a heap (as if constructed with {@link make_heap}).

- * - *

The range between first and the iterator returned is a heap.

- * - *

If the entire range is a valid heap, the function returns last.

- * - *

The elements are compared using {@link less}.

- * - * @param first {@link IArrayIterator Random-access iterator} to the initial position of the sequence. - * @param last {@link IArrayIterator Random-access iterator} to the final position of the sequence. The range used is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * {@link IArrayIterator RandomAccessIterator} shall point to a type for which {@link Iterator.swap swap} - * is properly defined. - * @param compare Binary function that accepts two elements in the range as arguments, and returns a value - * convertible to boolean. The value returned indicates whether the element passed as - * first argument is considered to go before the second in the specific strict weak ordering it defines. - * The function shall not modify any of its arguments. This can either be a function pointer or a - * function object. - */ - function is_heap_until>(first: RandomAccessIterator, last: RandomAccessIterator, compare: (x: T, y: T) => boolean): RandomAccessIterator; - /** - *

Sort elements of heap.

- * - *

Sorts the elements in the heap range [first, last) into ascending order.

- * - *

The elements are compared using {@link less}, which shall be the same as used to construct the heap.

- * - *

The range loses its properties as a heap.

- * - * @param first {@link IArrayIterator Random-access iterator} to the initial position of the sequence to be sorted. - * @param last {@link IArrayIterator Random-access iterator} to the final position of the sequence to be sorted. - * The range used is [first, last), which contains all the elements between first and - * last, including the element pointed by first but not the element pointed by last. - * {@link IArrayIterator RandomAccessIterator} shall point to a type for which {@link Iterator.swap swap} - * is properly defined. - */ - function sort_heap>(first: RandomAccessIterator, last: RandomAccessIterator): void; - /** - *

Sort elements of heap.

- * - *

Sorts the elements in the heap range [first, last) into ascending order.

- * - *

The elements are compared using compare, which shall be the same as used to construct the heap.

- * - *

The range loses its properties as a heap.

- * - * @param first {@link IArrayIterator Random-access iterator} to the initial position of the sequence to be sorted. - * @param last {@link IArrayIterator Random-access iterator} to the final position of the sequence to be sorted. - * The range used is [first, last), which contains all the elements between first and - * last, including the element pointed by first but not the element pointed by last. - * {@link IArrayIterator RandomAccessIterator} shall point to a type for which {@link Iterator.swap swap} - * is properly defined. - * @param compare Binary function that accepts two elements in the range as arguments, and returns a value - * convertible to boolean. The value returned indicates whether the element passed as - * first argument is considered to go before the second in the specific strict weak ordering it defines. - * The function shall not modify any of its arguments. This can either be a function pointer or a - * function object. - */ - function sort_heap>(first: RandomAccessIterator, last: RandomAccessIterator, compare: (x: T, y: T) => boolean): void; -} -declare namespace std { - /** - *

Return iterator to lower bound.

- * - *

Returns an iterator pointing to the first element in the range [first, last) which does not - * compare less than val.

- * - *

The elements are compared using {@link less}. The elements in the range shall already be {@link is_sorted sorted} - * according to this same criterion ({@link less}), or at least {@link is_partitioned partitioned} with respect to - * val.

- * - *

The function optimizes the number of comparisons performed by comparing non-consecutive elements of the sorted - * range, which is specially efficient for {@link IArrayIterator random-access iterators}.

- * - *

Unlike {@link upper_bound}, the value pointed by the iterator returned by this function may also be equivalent - * to val, and not only greater.

- * - * @param first {@link Iterator Forward iterator} to the initial position of a {@link is_sorted sorted} (or properly - * {@link is_partitioned partitioned}) sequence. - * @param last {@link Iterator Forward iterator} to the final position of a {@link is_sorted sorted} (or properly - * {@link is_partitioned partitioned}) sequence. The range used is [first, last), which - * contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - * @param val Value of the lower bound to search for in the range. T shall be a type supporting being compared - * with elements of the range [first, last) as the left-hand side operand of {@link less}. - * - * @return An iterator to the lower bound of val in the range. If all the element in the range compare less than - * val, the function returns last. - */ - function lower_bound>(first: ForwardIterator, last: ForwardIterator, val: T): ForwardIterator; - /** - *

Return iterator to lower bound.

- * - *

Returns an iterator pointing to the first element in the range [first, last) which does not - * compare less than val.

- * - *

The elements are compared using compare. The elements in the range shall already be - * {@link is_sorted sorted} according to this same criterion (compare), or at least - * {@link is_partitioned partitioned} with respect to val.

- * - *

The function optimizes the number of comparisons performed by comparing non-consecutive elements of the sorted - * range, which is specially efficient for {@link IArrayIterator random-access iterators}.

- * - *

Unlike {@link upper_bound}, the value pointed by the iterator returned by this function may also be equivalent - * to val, and not only greater.

- * - * @param first {@link Iterator Forward iterator} to the initial position of a {@link is_sorted sorted} (or properly - * {@link is_partitioned partitioned}) sequence. - * @param last {@link Iterator Forward iterator} to the final position of a {@link is_sorted sorted} (or properly - * {@link is_partitioned partitioned}) sequence. The range used is [first, last), which - * contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - * @param val Value of the lower bound to search for in the range. - * @param compare Binary function that accepts two arguments (the first of the type pointed by ForwardIterator, - * and the second, always val), and returns a value convertible to bool. The value - * returned indicates whether the first argument is considered to go before the second. The function - * shall not modify any of its arguments. - * - * @return An iterator to the lower bound of val in the range. If all the element in the range compare less than - * val, the function returns last. - */ - function lower_bound>(first: ForwardIterator, last: ForwardIterator, val: T, compare: (x: T, y: T) => boolean): ForwardIterator; - /** - *

Return iterator to upper bound.

- * - *

Returns an iterator pointing to the first element in the range [first, last) which compares - * greater than val.

- * - *

The elements are compared using {@link less}. The elements in the range shall already be {@link is_sorted sorted} - * according to this same criterion ({@link less}), or at least {@link is_partitioned partitioned} with respect to - * val.

- * - *

The function optimizes the number of comparisons performed by comparing non-consecutive elements of the sorted - * range, which is specially efficient for {@link IArrayIterator random-access iterators}.

- * - *

Unlike {@link lower_bound}, the value pointed by the iterator returned by this function cannot be equivalent to - * val, only greater.

- * - * @param first {@link Iterator Forward iterator} to the initial position of a {@link is_sorted sorted} (or properly - * {@link is_partitioned partitioned}) sequence. - * @param last {@link Iterator Forward iterator} to the final position of a {@link is_sorted sorted} (or properly - * {@link is_partitioned partitioned}) sequence. The range used is [first, last), which - * contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - * @param val Value of the lower bound to search for in the range. T shall be a type supporting being compared - * with elements of the range [first, last) as the left-hand side operand of {@link less}. - * - * @return An iterator to the upper bound of val in the range. If no element in the range comparse greater than - * val, the function returns last. - */ - function upper_bound>(first: ForwardIterator, last: ForwardIterator, val: T): ForwardIterator; - /** - *

Return iterator to upper bound.

- * - *

Returns an iterator pointing to the first element in the range [first, last) which compares - * greater than val.

- * - *

The elements are compared using compare. The elements in the range shall already be - * {@link is_sorted sorted} according to this same criterion (compare), or at least - * {@link is_partitioned partitioned} with respect to val.

- * - *

The function optimizes the number of comparisons performed by comparing non-consecutive elements of the sorted - * range, which is specially efficient for {@link IArrayIterator random-access iterators}.

- * - *

Unlike {@link lower_bound}, the value pointed by the iterator returned by this function cannot be equivalent to - * val, only greater.

- * - * @param first {@link Iterator Forward iterator} to the initial position of a {@link is_sorted sorted} (or properly - * {@link is_partitioned partitioned}) sequence. - * @param last {@link Iterator Forward iterator} to the final position of a {@link is_sorted sorted} (or properly - * {@link is_partitioned partitioned}) sequence. The range used is [first, last), which - * contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - * @param val Value of the lower bound to search for in the range. - * @param compare Binary function that accepts two arguments (the first of the type pointed by ForwardIterator, - * and the second, always val), and returns a value convertible to bool. The value - * returned indicates whether the first argument is considered to go before the second. The function - * shall not modify any of its arguments. - * - * @return An iterator to the upper bound of val in the range. If no element in the range comparse greater than - * val, the function returns last. - */ - function upper_bound>(first: ForwardIterator, last: ForwardIterator, val: T, compare: (x: T, y: T) => boolean): ForwardIterator; - /** - *

Get subrange of equal elements.

- * - *

Returns the bounds of the subrange that includes all the elements of the range [first, last) with - * values equivalent to val.

- * - *

The elements are compared using {@link less}. Two elements, ax/i> and y are considered equivalent - * if (!std.less(x, y) && !std.less(y, x)).

- * - *

The elements in the range shall already be {@link is_sorted sorted} according to this same criterion - * ({@link less}), or at least {@link is_partitioned partitioned} with respect to val.

- * - *

If val is not equivalent to any value in the range, the subrange returned has a length of zero, with both - * iterators pointing to the nearest value greater than val, if any, or to last, if val compares - * greater than all the elements in the range.

- * - * @param first {@link Iterator Forward iterator} to the initial position of a {@link is_sorted sorted} (or properly - * {@link is_partitioned partitioned}) sequence. - * @param last {@link Iterator Forward iterator} to the final position of a {@link is_sorted sorted} (or properly - * {@link is_partitioned partitioned}) sequence. The range used is [first, last), which - * contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - * @param val Value of the lower bound to search for in the range. T shall be a type supporting being compared - * with elements of the range [first, last) as the left-hand side operand of {@link less}. - * - * @return A {@link Pair} object, whose member {@link Pair.first} is an iterator to the lower bound of the subrange of - * equivalent values, and {@link Pair.second} its upper bound. The values are the same as those that would be - * returned by functions {@link lower_bound} and {@link upper_bound} respectively. - */ - function equal_range>(first: ForwardIterator, last: ForwardIterator, val: T): Pair; - /** - *

Get subrange of equal elements.

- * - *

Returns the bounds of the subrange that includes all the elements of the range [first, last) with - * values equivalent to val.

- * - *

The elements are compared using compare. Two elements, ax/i> and y are considered equivalent - * if (!compare(x, y) && !compare(y, x)).

- * - *

The elements in the range shall already be {@link is_sorted sorted} according to this same criterion - * (compare), or at least {@link is_partitioned partitioned} with respect to val.

- * - *

If val is not equivalent to any value in the range, the subrange returned has a length of zero, with both - * iterators pointing to the nearest value greater than val, if any, or to last, if val compares - * greater than all the elements in the range.

- * - * @param first {@link Iterator Forward iterator} to the initial position of a {@link is_sorted sorted} (or properly - * {@link is_partitioned partitioned}) sequence. - * @param last {@link Iterator Forward iterator} to the final position of a {@link is_sorted sorted} (or properly - * {@link is_partitioned partitioned}) sequence. The range used is [first, last), which - * contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - * @param val Value of the lower bound to search for in the range. - * @param compare Binary function that accepts two arguments of the type pointed by ForwardIterator (and of type - * T), and returns a value convertible to bool. The value returned indicates whether - * the first argument is considered to go before the second. The function shall not modify any of its - * arguments. - * - * @return A {@link Pair} object, whose member {@link Pair.first} is an iterator to the lower bound of the subrange of - * equivalent values, and {@link Pair.second} its upper bound. The values are the same as those that would be - * returned by functions {@link lower_bound} and {@link upper_bound} respectively. - */ - function equal_range>(first: ForwardIterator, last: ForwardIterator, val: T, compare: (x: T, y: T) => boolean): Pair; - /** - *

Get subrange of equal elements.

- * - *

Returns the bounds of the subrange that includes all the elements of the range [first, last) with - * values equivalent to val.

- * - *

The elements are compared using {@link less}. Two elements, x and y are considered equivalent - * if (!std.less(x, y) && !std.less(y, x)).

- * - *

The elements in the range shall already be {@link is_sorted sorted} according to this same criterion - * ({@link less}), or at least {@link is_partitioned partitioned} with respect to val.

- * - *

If val is not equivalent to any value in the range, the subrange returned has a length of zero, with both - * iterators pointing to the nearest value greater than val, if any, or to last, if val compares - * greater than all the elements in the range.

- * - * @param first {@link Iterator Forward iterator} to the initial position of a {@link is_sorted sorted} (or properly - * {@link is_partitioned partitioned}) sequence. - * @param last {@link Iterator Forward iterator} to the final position of a {@link is_sorted sorted} (or properly - * {@link is_partitioned partitioned}) sequence. The range used is [first, last), which - * contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - * @param val Value of the lower bound to search for in the range. T shall be a type supporting being compared - * with elements of the range [first, last) as the left-hand side operand of {@link less}. - * - * @return true if an element equivalent to val is found, and false otherwise. - */ - function binary_search>(first: ForwardIterator, last: ForwardIterator, val: T): boolean; - /** - *

Get subrange of equal elements.

- * - *

Returns the bounds of the subrange that includes all the elements of the range [first, last) with - * values equivalent to val.

- * - *

The elements are compared using {compare}. Two elements, x and y are considered equivalent - * if (!compare(x, y) && !compare(y, x)).

- * - *

The elements in the range shall already be {@link is_sorted sorted} according to this same criterion - * (compare), or at least {@link is_partitioned partitioned} with respect to val.

- * - *

If val is not equivalent to any value in the range, the subrange returned has a length of zero, with both - * iterators pointing to the nearest value greater than val, if any, or to last, if val compares - * greater than all the elements in the range.

- * - * @param first {@link Iterator Forward iterator} to the initial position of a {@link is_sorted sorted} (or properly - * {@link is_partitioned partitioned}) sequence. - * @param last {@link Iterator Forward iterator} to the final position of a {@link is_sorted sorted} (or properly - * {@link is_partitioned partitioned}) sequence. The range used is [first, last), which - * contains all the elements between first and last, including the element pointed by - * first but not the element pointed by last. - * @param val Value of the lower bound to search for in the range. - * @param compare Binary function that accepts two arguments of the type pointed by ForwardIterator (and of type - * T), and returns a value convertible to bool. The value returned indicates whether - * the first argument is considered to go before the second. The function shall not modify any of its - * arguments. - * - * @return true if an element equivalent to val is found, and false otherwise. - */ - function binary_search>(first: ForwardIterator, last: ForwardIterator, val: T, compare: (x: T, y: T) => boolean): boolean; -} -declare namespace std { - /** - *

Test whether range is partitioned.

- * - *

Returns true if all the elements in the range [first, last) for which pred - * returns true precede those for which it returns false.

- * - *

If the range is {@link IContainer.empty empty}, the function returns true.

- * - * @param first {@link Iterator Input iterator} to the initial position of the sequence. - * @param last {@link Iterator Input iterator} to the final position of the sequence. The range used is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * @param pred Unary function that accepts an element in the range as argument, and returns a value convertible to - * bool. The value returned indicates whether the element belongs to the first group (if - * true, the element is expected before all the elements for which it returns - * false). The function shall not modify its argument. - * - * @return true if all the elements in the range [first, last) for which pred returns - * true precede those for which it returns false. Otherwise it returns - * false. If the range is {@link IContainer.empty empty}, the function returns true. - */ - function is_partitioned>(first: InputIterator, last: InputIterator, pred: (x: T) => boolean): boolean; - /** - *

Partition range in two.

- * - *

Rearranges the elements from the range [first, last), in such a way that all the elements for - * which pred returns true precede all those for which it returns false. The iterator - * returned points to the first element of the second group.

- * - *

The relative ordering within each group is not necessarily the same as before the call. See - * {@link stable_partition} for a function with a similar behavior but with stable ordering within each group.

- * - * @param first {@link Iterator Forward iterator} to the initial position of the sequence to partition. - * @param last {@link Iterator Forward iterator} to the final position of the sequence to partition. The range used is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * @param pred Unary function that accepts an element in the range as argument, and returns a value convertible to - * bool. The value returned indicates whether the element belongs to the first group (if - * true, the element is expected before all the elements for which it returns - * false). The function shall not modify its argument. - * - * @return An iterator that points to the first element of the second group of elements (those for which pred - * returns false), or last if this group is {@link IContainer.empty empty}. - */ - function partition>(first: BidirectionalIterator, last: BidirectionalIterator, pred: (x: T) => boolean): BidirectionalIterator; - /** - *

Partition range in two - stable ordering.

- * - *

Rearranges the elements in the range [first, last), in such a way that all the elements for which - * pred returns true precede all those for which it returns false, and, unlike - * function {@link partition}, the relative order of elements within each group is preserved.

- * - *

This is generally implemented using an internal temporary buffer.

- * - * @param first {@link Iterator Bidirectional iterator} to the initial position of the sequence to partition. - * @param last {@link Iterator Bidirectional iterator} to the final position of the sequence to partition. The range - * used is [first, last), which contains all the elements between first and - * last, including the element pointed by first but not the element pointed by last. - * @param pred Unary function that accepts an element in the range as argument, and returns a value convertible to - * bool. The value returned indicates whether the element belongs to the first group (if - * true, the element is expected before all the elements for which it returns - * false). The function shall not modify its argument. - * - * @return An iterator that points to the first element of the second group of elements (those for which pred - * returns false), or last if this group is {@link IContainer.empty empty}. - */ - function stable_partition>(first: BidirectionalIterator, last: BidirectionalIterator, pred: (x: T) => boolean): BidirectionalIterator; - /** - *

Partition range into two.

- * - *

Copies the elements in the range [first, last) for which pred returns true - * into the range pointed by result_true, and those for which it does not into the range pointed by - * result_false.

- * - * @param first {@link Iterator Input iterator} to the initial position of the range to be copy-partitioned. - * @param last {@link Iterator Input iterator} to the final position of the range to be copy-partitioned. The range - * used is [first, last), which contains all the elements between first and - * last, including the element pointed by first but not the element pointed by last. - * @param result_true {@link Iterator Output iterator} to the initial position of the range where the elements for - * which pred returns true are stored. - * @param result_false {@link Iterator Output iterator} to the initial position of the range where the elements for - * which pred returns false are stored. - * @param pred Unary function that accepts an element pointed by InputIterator as argument, and returns a value - * convertible to bool. The value returned indicates on which result range the element is - * copied. The function shall not modify its argument. - * - * @return A {@link Pair} of iterators with the end of the generated sequences pointed by result_true and - * result_false, respectivelly. Its member {@link Pair.first first} points to the element that follows - * the last element copied to the sequence of elements for which pred returned true. Its - * member {@link Pair.second second} points to the element that follows the last element copied to the sequence - * of elements for which pred returned false. - */ - function partition_copy, OutputIterator1 extends base.ILinearIterator, OutputIterator2 extends base.ILinearIterator>(first: InputIterator, last: InputIterator, result_true: OutputIterator1, result_false: OutputIterator2, pred: (val: T) => T): Pair; - /** - *

Get partition point.

- * - *

Returns an iterator to the first element in the partitioned range [first, last) for which - * pred is not true, indicating its partition point.

- * - *

The elements in the range shall already {@link is_partitioned be partitioned}, as if {@link partition} had been - * called with the same arguments.

- * - *

The function optimizes the number of comparisons performed by comparing non-consecutive elements of the sorted - * range, which is specially efficient for {@link Iteartor random-access iterators}.

- * - * @param first {@link Iterator Forward iterator} to the initial position of the partitioned sequence. - * @param last {@link Iterator Forward iterator} to the final position of the partitioned sequence. The range checked - * is [first, last), which contains all the elements between first an last, - * including the element pointed by first but not the element pointed by last. - * @param pred Unary function that accepts an element in the range as argument, and returns a value convertible to - * bool. The value returned indicates whether the element goes before the partition point (if - * true, it goes before; if false goes at or after it). The function shall not - * modify its argument. - * - * @return An iterator to the first element in the partitioned range [first, last) for which pred - * is not true, or last if it is not true for any element. - */ - function partition_point>(first: ForwardIterator, last: ForwardIterator, pred: (x: T) => boolean): ForwardIterator; -} -declare namespace std { - /** - *

Merge sorted ranges.

- * - *

Combines the elements in the sorted ranges [first1, last1) and [first2, last2), into - * a new range beginning at result with all its elements sorted.

- * - *

The elements are compared using {@link less}. The elements in both ranges shall already be ordered according to - * this same criterion ({@link less}). The resulting range is also sorted according to this.

- * - * @param first1 {@link Iterator Input iterator} to the initial position of the first sorted sequence. - * @param last1 {@link Iterator Input iterator} to the final position of the first sorted sequence. The range used is - * [first1, last1), which contains all the elements between first1 and last1, - * including the element pointed by first1 but not the element pointed by last1. - * @param first2 {@link Iterator Input iterator} to the initial position of the second sorted sequence. - * @param last2 {@link Iterator Input iterator} to the final position of the second sorted sequence. The range used is - * [first2, last2). - * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting combined - * range is stored. Its size is equal to the sum of both ranges above. - * - * @return An iterator pointing to the past-the-end element in the resulting sequence. - */ - function merge, InputIterator2 extends Iterator, OutputIterator extends base.ILinearIterator>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, result: OutputIterator): OutputIterator; - /** - *

Merge sorted ranges.

- * - *

Combines the elements in the sorted ranges [first1, last1) and [first2, last2), into - * a new range beginning at result with all its elements sorted.

- * - *

The elements are compared using {@link less}. The elements in both ranges shall already be ordered according to - * this same criterion (compare). The resulting range is also sorted according to this.

- * - * @param first1 {@link Iterator Input iterator} to the initial position of the first sorted sequence. - * @param last1 {@link Iterator Input iterator} to the final position of the first sorted sequence. The range used is - * [first1, last1), which contains all the elements between first1 and last1, - * including the element pointed by first1 but not the element pointed by last1. - * @param first2 {@link Iterator Input iterator} to the initial position of the second sorted sequence. - * @param last2 {@link Iterator Input iterator} to the final position of the second sorted sequence. The range used is - * [first2, last2). - * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting combined - * range is stored. Its size is equal to the sum of both ranges above. - * @param compare Binary function that accepts two arguments of the types pointed by the iterators, and returns a value - * convertible to bool. The value returned indicates whether the first argument is - * considered to go before the second in the specific strict weak ordering it defines. The - * function shall not modify any of its arguments. - * - * @return An iterator pointing to the past-the-end element in the resulting sequence. - */ - function merge, InputIterator2 extends Iterator, OutputIterator extends base.ILinearIterator>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, result: OutputIterator, compare: (x: T, y: T) => boolean): OutputIterator; - /** - *

Merge consecutive sorted ranges.

- * - *

Merges two consecutive sorted ranges: [first, middle) and [middle, last), putting - * the result into the combined sorted range [first, last).

- * - *

The elements are compared using {@link less}. The elements in both ranges shall already be ordered according to - * this same criterion ({@link less}). The resulting range is also sorted according to this.

- * - *

The function preserves the relative order of elements with equivalent values, with the elements in the first - * range preceding those equivalent in the second.

- * - * @param first {@link Iterator Bidirectional iterator} to the initial position in the first sorted sequence to merge. - * This is also the initial position where the resulting merged range is stored. - * @param middle {@link Iterator Bidirectional iterator} to the initial position of the second sorted sequence, which - * because both sequences must be consecutive, matches the past-the-end position of the first - * sequence. - * @param last {@link Iterator Bidirectional iterator} to the past-the-end position of the second sorted - * sequence. This is also the past-the-end position of the range where the resulting merged range is - * stored. - */ - function inplace_merge>(first: BidirectionalIterator, middle: BidirectionalIterator, last: BidirectionalIterator): void; - /** - *

Merge consecutive sorted ranges.

- * - *

Merges two consecutive sorted ranges: [first, middle) and [middle, last), putting - * the result into the combined sorted range [first, last).

- * - *

The elements are compared using compare. The elements in both ranges shall already be ordered according - * to this same criterion (compare). The resulting range is also sorted according to this.

- * - *

The function preserves the relative order of elements with equivalent values, with the elements in the first - * range preceding those equivalent in the second.

- * - * @param first {@link Iterator Bidirectional iterator} to the initial position in the first sorted sequence to merge. - * This is also the initial position where the resulting merged range is stored. - * @param middle {@link Iterator Bidirectional iterator} to the initial position of the second sorted sequence, which - * because both sequences must be consecutive, matches the past-the-end position of the first - * sequence. - * @param last {@link Iterator Bidirectional iterator} to the past-the-end position of the second sorted - * sequence. This is also the past-the-end position of the range where the resulting merged range is - * stored. - * @param compare Binary function that accepts two arguments of the types pointed by the iterators, and returns a value - * convertible to bool. The value returned indicates whether the first argument is - * considered to go before the second in the specific strict weak ordering it defines. The - * function shall not modify any of its arguments. - */ - function inplace_merge>(first: BidirectionalIterator, middle: BidirectionalIterator, last: BidirectionalIterator, compare: (x: T, y: T) => boolean): void; - /** - *

Test whether sorted range includes another sorted range.

- * - *

Returns true if the sorted range [first1, last1) contains all the elements in the - * sorted range [first2, last2).

- * - *

The elements are compared using {@link less}. Two elements, x and y are considered equivalent - * if (!std.less(x, y) && !std.less(y, x)).

- * - *

The elements in the range shall already be ordered according to this same criterion ({@link less}).

- * - * @param first1 {@link Iterator Input iterator} to the initial position of the first sorted sequence. - * @param last1 {@link Iterator Input iterator} to the final position of the first sorted sequence (which is tested on - * whether it contains the second sequence). The range used is [first1, last1), which - * contains all the elements between first1 and last1, including the element pointed by - * first1 but not the element pointed by last1. - * @param first2 {@link Iterator Input iterator} to the initial position of the second sorted sequence. - * @param last2 {@link Iterator Input iterator} to the final position of the second sorted sequence. (which is tested - * on whether it is contained in the first sequence). The range used is [first2, last2). - * - * @return true if every element in the range [first2, last2) is contained in the range - * [first1, last1), false otherwise. If [first2, last2) is an empty - * range, the function returns true. - */ - function includes, InputIterator2 extends Iterator>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2): boolean; - /** - *

Test whether sorted range includes another sorted range.

- * - *

Returns true if the sorted range [first1, last1) contains all the elements in the - * sorted range [first2, last2).

- * - *

The elements are compared using compare. Two elements, x and y are considered equivalent - * if (!compare(x, y) && !compare(y, x)).

- * - *

The elements in the range shall already be ordered according to this same criterion (compare).

- * - * @param first1 {@link Iterator Input iterator} to the initial position of the first sorted sequence. - * @param last1 {@link Iterator Input iterator} to the final position of the first sorted sequence (which is tested on - * whether it contains the second sequence). The range used is [first1, last1), which - * contains all the elements between first1 and last1, including the element pointed by - * first1 but not the element pointed by last1. - * @param first2 {@link Iterator Input iterator} to the initial position of the second sorted sequence. - * @param last2 {@link Iterator Input iterator} to the final position of the second sorted sequence. (which is tested - * on whether it is contained in the first sequence). The range used is [first2, last2). - * @param compare Binary function that accepts two elements as arguments (one from each of the two sequences, in the - * same order), and returns a value convertible to bool. The value returned indicates - * whether the element passed as first argument is considered to go before the second in the specific - * strict weak ordering it defines. The function shall not modify any of its arguments. - * - * @return true if every element in the range [first2, last2) is contained in the range - * [first1, last1), false otherwise. If [first2, last2) is an empty - * range, the function returns true. - */ - function includes, InputIterator2 extends Iterator>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, compare: (x: T, y: T) => boolean): boolean; - /** - *

Union of two sorted ranges.

- * - *

Constructs a sorted range beginning in the location pointed by result with the set union of the - * two sorted ranges [first1, last1) and [first2, last2).

- * - *

The union of two sets is formed by the elements that are present in either one of the sets, or in both. - * Elements from the second range that have an equivalent element in the first range are not copied to the resulting - * range.

- * - *

The elements are compared using {@link less}. Two elements, x and y are considered equivalent - * if (!std.less(x, y) && !std.less(y, x)).

- * - *

The elements in the ranges shall already be ordered according to this same criterion ({@link less}). The - * resulting range is also sorted according to this.

- * - * @param first1 {@link Iterator Input iterator} to the initial position of the first sorted sequence. - * @param last1 {@link Iterator Input iterator} to the final position of the first sorted sequence. The range used is - * [first1, last1), which contains all the elements between first1 and last1, - * including the element pointed by first1 but not the element pointed by last1. - * @param first2 {@link Iterator Input iterator} to the initial position of the second sorted sequence. - * @param last2 {@link Iterator Input iterator} to the final position of the second sorted sequence. The range used is - * [first2, last2). - * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting sequence is - * stored. The pointed type shall support being assigned the value of an element from the other ranges. - * - * @return An iterator to the end of the constructed range. - */ - function set_union, InputIterator2 extends Iterator, OutputIterator extends base.ILinearIterator>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, result: OutputIterator): OutputIterator; - /** - *

Union of two sorted ranges.

- * - *

Constructs a sorted range beginning in the location pointed by result with the set union of the - * two sorted ranges [first1, last1) and [first2, last2).

- * - *

The union of two sets is formed by the elements that are present in either one of the sets, or in both. - * Elements from the second range that have an equivalent element in the first range are not copied to the resulting - * range.

- * - *

The elements are compared using compare. Two elements, x and y are considered equivalent - * if (!compare(x, y) && !compare(y, x)).

- * - *

The elements in the ranges shall already be ordered according to this same criterion (compare). The - * resulting range is also sorted according to this.

- * - * @param first1 {@link Iterator Input iterator} to the initial position of the first sorted sequence. - * @param last1 {@link Iterator Input iterator} to the final position of the first sorted sequence. The range used is - * [first1, last1), which contains all the elements between first1 and last1, - * including the element pointed by first1 but not the element pointed by last1. - * @param first2 {@link Iterator Input iterator} to the initial position of the second sorted sequence. - * @param last2 {@link Iterator Input iterator} to the final position of the second sorted sequence. The range used is - * [first2, last2). - * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting sequence is - * stored. The pointed type shall support being assigned the value of an element from the other ranges. - * @param compare Binary function that accepts two arguments of the types pointed by the input iterators, and returns a - * value convertible to bool. The value returned indicates whether the first argument is - * considered to go before the second in the specific strict weak ordering it defines. The - * function shall not modify any of its arguments. - * - * @return An iterator to the end of the constructed range. - */ - function set_union, InputIterator2 extends Iterator, OutputIterator extends base.ILinearIterator>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, result: OutputIterator, compare: (x: T, y: T) => boolean): OutputIterator; - /** - *

Intersection of two sorted ranges.

- * - *

Constructs a sorted range beginning in the location pointed by result with the set intersection of - * the two sorted ranges [first1, last1) and [first2, last2).

- * - *

The intersection of two sets is formed only by the elements that are present in both sets. The elements - * copied by the function come always from the first range, in the same order.

- * - *

The elements are compared using {@link less}. Two elements, x and y are considered equivalent - * if (!std.less(x, y) && !std.less(y, x)).

- * - *

The elements in the ranges shall already be ordered according to this same criterion ({@link less}). The - * resulting range is also sorted according to this.

- * - * @param first1 {@link Iterator Input iterator} to the initial position of the first sorted sequence. - * @param last1 {@link Iterator Input iterator} to the final position of the first sorted sequence. The range used is - * [first1, last1), which contains all the elements between first1 and last1, - * including the element pointed by first1 but not the element pointed by last1. - * @param first2 {@link Iterator Input iterator} to the initial position of the second sorted sequence. - * @param last2 {@link Iterator Input iterator} to the final position of the second sorted sequence. The range used is - * [first2, last2). - * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting sequence is - * stored. The pointed type shall support being assigned the value of an element from the first range. - * - * @return An iterator to the end of the constructed range. - */ - function set_intersection, InputIterator2 extends Iterator, OutputIterator extends base.ILinearIterator>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, result: OutputIterator): OutputIterator; - /** - *

Intersection of two sorted ranges.

- * - *

Constructs a sorted range beginning in the location pointed by result with the set intersection of - * the two sorted ranges [first1, last1) and [first2, last2).

- * - *

The intersection of two sets is formed only by the elements that are present in both sets. The elements - * copied by the function come always from the first range, in the same order.

- * - *

The elements are compared using compare. Two elements, x and y are considered equivalent - * if (!compare(x, y) && !compare(y, x)).

- * - *

The elements in the ranges shall already be ordered according to this same criterion (compare). The - * resulting range is also sorted according to this.

- * - * @param first1 {@link Iterator Input iterator} to the initial position of the first sorted sequence. - * @param last1 {@link Iterator Input iterator} to the final position of the first sorted sequence. The range used is - * [first1, last1), which contains all the elements between first1 and last1, - * including the element pointed by first1 but not the element pointed by last1. - * @param first2 {@link Iterator Input iterator} to the initial position of the second sorted sequence. - * @param last2 {@link Iterator Input iterator} to the final position of the second sorted sequence. The range used is - * [first2, last2). - * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting sequence is - * stored. The pointed type shall support being assigned the value of an element from the first range. - * @param compare Binary function that accepts two arguments of the types pointed by the input iterators, and returns a - * value convertible to bool. The value returned indicates whether the first argument is - * considered to go before the second in the specific strict weak ordering it defines. The - * function shall not modify any of its arguments. - * - * @return An iterator to the end of the constructed range. - */ - function set_intersection, InputIterator2 extends Iterator, OutputIterator extends base.ILinearIterator>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, result: OutputIterator, compare: (x: T, y: T) => boolean): OutputIterator; - /** - *

Difference of two sorted ranges.

- * - *

Constructs a sorted range beginning in the location pointed by result with the set difference of - * the sorted range [first1, last1) with respect to the sorted range [first2, last2).

- * - *

The difference of two sets is formed by the elements that are present in the first set, but not in the - * second one. The elements copied by the function come always from the first range, in the same order.

- * - *

For containers supporting multiple occurrences of a value, the difference includes as many occurrences of - * a given value as in the first range, minus the amount of matching elements in the second, preserving order.

- * - *

Notice that this is a directional operation - for a symmetrical equivalent, see {@link set_symmetric_difference}. - *

- * - *

The elements are compared using {@link less}. Two elements, x and y are considered equivalent - * if (!std.less(x, y) && !std.less(y, x)).

- * - *

The elements in the ranges shall already be ordered according to this same criterion ({@link less}). The - * resulting range is also sorted according to this.

- * - * @param first1 {@link Iterator Input iterator} to the initial position of the first sorted sequence. - * @param last1 {@link Iterator Input iterator} to the final position of the first sorted sequence. The range used is - * [first1, last1), which contains all the elements between first1 and last1, - * including the element pointed by first1 but not the element pointed by last1. - * @param first2 {@link Iterator Input iterator} to the initial position of the second sorted sequence. - * @param last2 {@link Iterator Input iterator} to the final position of the second sorted sequence. The range used is - * [first2, last2). - * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting sequence is - * stored. The pointed type shall support being assigned the value of an element from the first range. - * - * @return An iterator to the end of the constructed range. - */ - function set_difference, InputIterator2 extends Iterator, OutputIterator extends base.ILinearIterator>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, result: OutputIterator): OutputIterator; - /** - *

Difference of two sorted ranges.

- * - *

Constructs a sorted range beginning in the location pointed by result with the set difference of - * the sorted range [first1, last1) with respect to the sorted range [first2, last2).

- * - *

The difference of two sets is formed by the elements that are present in the first set, but not in the - * second one. The elements copied by the function come always from the first range, in the same order.

- * - *

For containers supporting multiple occurrences of a value, the difference includes as many occurrences of - * a given value as in the first range, minus the amount of matching elements in the second, preserving order.

- * - *

Notice that this is a directional operation - for a symmetrical equivalent, see {@link set_symmetric_difference}. - *

- * - *

The elements are compared using compare. Two elements, x and y are considered equivalent - * if (!compare(x, y) && !compare(y, x)).

- * - *

The elements in the ranges shall already be ordered according to this same criterion (compare). The - * resulting range is also sorted according to this.

- * - * @param first1 {@link Iterator Input iterator} to the initial position of the first sorted sequence. - * @param last1 {@link Iterator Input iterator} to the final position of the first sorted sequence. The range used is - * [first1, last1), which contains all the elements between first1 and last1, - * including the element pointed by first1 but not the element pointed by last1. - * @param first2 {@link Iterator Input iterator} to the initial position of the second sorted sequence. - * @param last2 {@link Iterator Input iterator} to the final position of the second sorted sequence. The range used is - * [first2, last2). - * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting sequence is - * stored. The pointed type shall support being assigned the value of an element from the first range. - * @param compare Binary function that accepts two arguments of the types pointed by the input iterators, and returns a - * value convertible to bool. The value returned indicates whether the first argument is - * considered to go before the second in the specific strict weak ordering it defines. The - * function shall not modify any of its arguments. - * - * @return An iterator to the end of the constructed range. - */ - function set_difference, InputIterator2 extends Iterator, OutputIterator extends base.ILinearIterator>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, result: OutputIterator, compare: (x: T, y: T) => boolean): OutputIterator; - /** - *

Symmetric difference of two sorted ranges.

- * - *

Constructs a sorted range beginning in the location pointed by0 result with the set - * symmetric difference of the two sorted ranges [first1, last1) and [first2, last2). - *

- * - *

The symmetric difference of two sets is formed by the elements that are present in one of the sets, but - * not in the other. Among the equivalent elements in each range, those discarded are those that appear before in the - * existent order before the call. The existing order is also preserved for the copied elements.

- * - *

The elements are compared using {@link less}. Two elements, x and y are considered equivalent - * if (!std.less(x, y) && !std.less(y, x)).

- * - *

The elements in the ranges shall already be ordered according to this same criterion ({@link std.less}). The - * resulting range is also sorted according to this.

- * - * @param first1 {@link Iterator Input iterator} to the initial position of the first sorted sequence. - * @param last1 {@link Iterator Input iterator} to the final position of the first sorted sequence. The range used is - * [first1, last1), which contains all the elements between first1 and last1, - * including the element pointed by first1 but not the element pointed by last1. - * @param first2 {@link Iterator Input iterator} to the initial position of the second sorted sequence. - * @param last2 {@link Iterator Input iterator} to the final position of the second sorted sequence. The range used is - * [first2, last2). - * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting sequence is - * stored. The pointed type shall support being assigned the value of an element from the other ranges. - * @param compare Binary function that accepts two arguments of the types pointed by the input iterators, and returns a - * value convertible to bool. The value returned indicates whether the first argument is - * considered to go before the second in the specific strict weak ordering it defines. The - * function shall not modify any of its arguments. - * - * @return An iterator to the end of the constructed range. - */ - function set_symmetric_difference, InputIterator2 extends Iterator, OutputIterator extends base.ILinearIterator>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, result: OutputIterator): OutputIterator; - /** - *

Symmetric difference of two sorted ranges.

- * - *

Constructs a sorted range beginning in the location pointed by0 result with the set - * symmetric difference of the two sorted ranges [first1, last1) and [first2, last2). - *

- * - *

The symmetric difference of two sets is formed by the elements that are present in one of the sets, but - * not in the other. Among the equivalent elements in each range, those discarded are those that appear before in the - * existent order before the call. The existing order is also preserved for the copied elements.

- * - *

The elements are compared using compare. Two elements, x and y are considered equivalent - * if (!compare(x, y) && !compare(y, x)).

- * - *

The elements in the ranges shall already be ordered according to this same criterion (compare). The - * resulting range is also sorted according to this.

- * - * @param first1 {@link Iterator Input iterator} to the initial position of the first sorted sequence. - * @param last1 {@link Iterator Input iterator} to the final position of the first sorted sequence. The range used is - * [first1, last1), which contains all the elements between first1 and last1, - * including the element pointed by first1 but not the element pointed by last1. - * @param first2 {@link Iterator Input iterator} to the initial position of the second sorted sequence. - * @param last2 {@link Iterator Input iterator} to the final position of the second sorted sequence. The range used is - * [first2, last2). - * @param result {@link Iterator Output iterator} to the initial position of the range where the resulting sequence is - * stored. The pointed type shall support being assigned the value of an element from the other ranges. - * @param compare Binary function that accepts two arguments of the types pointed by the input iterators, and returns a - * value convertible to bool. The value returned indicates whether the first argument is - * considered to go before the second in the specific strict weak ordering it defines. The - * function shall not modify any of its arguments. - * - * @return An iterator to the end of the constructed range. - */ - function set_symmetric_difference, InputIterator2 extends Iterator, OutputIterator extends base.ILinearIterator>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, result: OutputIterator, compare: (x: T, y: T) => boolean): OutputIterator; -} -declare namespace std { - /** - *

Return the smallest.

- * - *

Returns the smallest of all the elements in the args.

- * - * @param args Values to compare. - * - * @return The lesser of the values passed as arguments. - */ - function min(...args: T[]): T; - /** - *

Return the largest.

- * - *

Returns the largest of all the elements in the args.

- * - * @param args Values to compare. - * - * @return The largest of the values passed as arguments. - */ - function max(...args: T[]): T; - /** - *

Return smallest and largest elements.

- * - *

Returns a {@link Pair} with the smallest of all the elements in the args as first element (the first of - * them, if there are more than one), and the largest as second (the last of them, if there are more than one).

- * - * @param args Values to compare. - * - * @return The lesser and greatest of the values passed as arguments. - */ - function minmax(...args: T[]): Pair; - /** - *

Return smallest element in range.

- * - *

Returns an iterator pointing to the element with the smallest value in the range [first, last). - *

- * - *

The comparisons are performed using either {@link less}; An element is the smallest if no other element - * compares less than it. If more than one element fulfills this condition, the iterator returned points to the first - * of such elements.

- * - * @param first {@link Iteartor Input iterator} to the initial final position of the sequence to compare. - * @param last {@link Iteartor Input iterator} to the final final position of the sequence to compare. The range used - * is [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * - * @return An iterator to smallest value in the range, or last if the range is empty. - */ - function min_element>(first: ForwardIterator, last: ForwardIterator): ForwardIterator; - /** - *

Return smallest element in range.

- * - *

Returns an iterator pointing to the element with the smallest value in the range [first, last). - *

- * - *

The comparisons are performed using either compare; An element is the smallest if no other element - * compares less than it. If more than one element fulfills this condition, the iterator returned points to the first - * of such elements.

- * - * @param first {@link Iteartor Input iterator} to the initial final position of the sequence to compare. - * @param last {@link Iteartor Input iterator} to the final final position of the sequence to compare. The range used - * is [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * @param compare Binary function that accepts two elements in the range as arguments, and returns a value convertible - * to bool. The value returned indicates whether the element passed as first argument is - * considered less than the second. The function shall not modify any of its arguments. - * - * @return An iterator to smallest value in the range, or last if the range is empty. - */ - function min_element>(first: ForwardIterator, last: ForwardIterator, compare: (x: T, y: T) => boolean): ForwardIterator; - /** - *

Return largest element in range.

- * - *

Returns an iterator pointing to the element with the largest value in the range [first, last). - *

- * - *

The comparisons are performed using either {@link greater}; An element is the largest if no other element - * compares less than it. If more than one element fulfills this condition, the iterator returned points to the first - * of such elements.

- * - * @param first {@link Iteartor Input iterator} to the initial final position of the sequence to compare. - * @param last {@link Iteartor Input iterator} to the final final position of the sequence to compare. The range used - * is [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * - * @return An iterator to largest value in the range, or last if the range is empty. - */ - function max_element>(first: ForwardIterator, last: ForwardIterator): ForwardIterator; - /** - *

Return largest element in range.

- * - *

Returns an iterator pointing to the element with the largest value in the range [first, last). - *

- * - *

The comparisons are performed using either compare; An element is the largest if no other element - * compares less than it. If more than one element fulfills this condition, the iterator returned points to the first - * of such elements.

- * - * @param first {@link Iteartor Input iterator} to the initial final position of the sequence to compare. - * @param last {@link Iteartor Input iterator} to the final final position of the sequence to compare. The range used - * is [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * @param compare Binary function that accepts two elements in the range as arguments, and returns a value convertible - * to bool. The value returned indicates whether the element passed as first argument is - * considered less than the second. The function shall not modify any of its arguments. - * - * @return An iterator to largest value in the range, or last if the range is empty. - */ - function max_element>(first: ForwardIterator, last: ForwardIterator, compare: (x: T, y: T) => boolean): ForwardIterator; - /** - *

Return smallest and largest elements in range.

- * - *

Returns a {@link Pair} with an iterator pointing to the element with the smallest value in the range - * [first, last) as first element, and the largest as second.

- * - *

The comparisons are performed using either {@link less} and {@link greater}.

- * - *

If more than one equivalent element has the smallest value, the first iterator points to the first of such - * elements.

- * - *

If more than one equivalent element has the largest value, the second iterator points to the last of such - * elements.

- * - * @param first {@link Iteartor Input iterator} to the initial final position of the sequence to compare. - * @param last {@link Iteartor Input iterator} to the final final position of the sequence to compare. The range used - * is [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * @param compare Binary function that accepts two elements in the range as arguments, and returns a value convertible - * to bool. The value returned indicates whether the element passed as first argument is - * considered less than the second. The function shall not modify any of its arguments. - * - * @return A {@link Pair} with an iterator pointing to the element with the smallest value in the range - * [first, last) as first element, and the largest as second. - */ - function minmax_element>(first: ForwardIterator, last: ForwardIterator): Pair; - /** - *

Return smallest and largest elements in range.

- * - *

Returns a {@link Pair} with an iterator pointing to the element with the smallest value in the range - * [first, last) as first element, and the largest as second.

- * - *

The comparisons are performed using either compare.

- * - *

If more than one equivalent element has the smallest value, the first iterator points to the first of such - * elements.

- * - *

If more than one equivalent element has the largest value, the second iterator points to the last of such - * elements.

- * - * @param first {@link Iteartor Input iterator} to the initial final position of the sequence to compare. - * @param last {@link Iteartor Input iterator} to the final final position of the sequence to compare. The range used - * is [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - * @param compare Binary function that accepts two elements in the range as arguments, and returns a value convertible - * to bool. The value returned indicates whether the element passed as first argument is - * considered less than the second. The function shall not modify any of its arguments. - * - * @return A {@link Pair} with an iterator pointing to the element with the smallest value in the range - * [first, last) as first element, and the largest as second. - */ - function minmax_element>(first: ForwardIterator, last: ForwardIterator, compare: (x: T, y: T) => boolean): Pair; - /** - *

Test whether range is permutation of another.

- * - *

Compares the elements in the range [first1, last1) with those in the range beginning at - * first2, and returns true if all of the elements in both ranges match, even in a different - * order.

- * - * @param first1 An {@link Iterator} to the initial position of the first sequence. - * @param last1 An {@link Iterator} to the final position in a sequence. The range used is - * [first1, last1), including the element pointed by first1, but not the element - * pointed by last1. - * @param first2 An {@link Iterator} to the initial position of the second sequence. The comparison includes up to - * as many elements of this sequence as those in the range [first1, last1). - * - * @return true if all the elements in the range [first1, last1) compare equal to those - * of the range starting at first2 in any order, and false otherwise. - */ - function is_permutation, Iterator2 extends Iterator>(first1: Iterator1, last1: Iterator1, first2: Iterator2): boolean; - /** - *

Test whether range is permutation of another.

- * - *

Compares the elements in the range [first1, last1) with those in the range beginning at - * first2, and returns true if all of the elements in both ranges match, even in a different - * order.

- * - * @param first1 An {@link Iterator} to the initial position of the first sequence. - * @param last1 An {@link Iterator} to the final position in a sequence. The range used is - * [first1, last1), including the element pointed by first1, but not the element - * pointed by last1. - * @param first2 An {@link Iterator} to the initial position of the second sequence. The comparison includes up to - * as many elements of this sequence as those in the range [first1, last1). - * @param pred Binary function that accepts two elements as argument (one of each of the two sequences, in the same - * order), and returns a value convertible to bool. The value returned indicates whether - * the elements are considered to match in the context of this function. - * - * @return true if all the elements in the range [first1, last1) compare equal to those - * of the range starting at first2 in any order, and false otherwise. - */ - function is_permutation, Iterator2 extends Iterator>(first1: Iterator1, last1: Iterator1, first2: Iterator2, pred: (x: T, y: T) => boolean): boolean; - /** - * Transform range to previous permutation. - * - * Rearranges the elements in the range [*first*, *last*) into the previous *lexicographically-ordered* permutation. - * - * A *permutation* is each one of the N! possible arrangements the elements can take (where *N* is the number of - * elements in the range). Different permutations can be ordered according to how they compare - * {@link lexicographicaly lexicographical_compare} to each other; The first such-sorted possible permutation (the one - * that would compare *lexicographically smaller* to all other permutations) is the one which has all its elements - * sorted in ascending order, and the largest has all its elements sorted in descending order. - * - * The comparisons of individual elements are performed using the {@link std.less std.less()} function. - * - * If the function can determine the previous permutation, it rearranges the elements as such and returns true. If - * that was not possible (because it is already at the lowest possible permutation), it rearranges the elements - * according to the last permutation (sorted in descending order) and returns false. - * - * @param first Bidirectional iterators to the initial positions of the sequence - * @param last Bidirectional iterators to the final positions of the sequence. The range used is [*first*, *last*), - * which contains all the elements between *first* and *last*, including the element pointed by *first* - * but not the element pointed by *last*. - * - * @return true if the function could rearrange the object as a lexicographicaly smaller permutation. Otherwise, the - * function returns false to indicate that the arrangement is not less than the previous, but the largest - * possible (sorted in descending order). - */ - function prev_permutation>(first: BidirectionalIterator, last: BidirectionalIterator): boolean; - /** - * Transform range to previous permutation. - * - * Rearranges the elements in the range [*first*, *last*) into the previous *lexicographically-ordered* permutation. - * - * A *permutation* is each one of the N! possible arrangements the elements can take (where *N* is the number of - * elements in the range). Different permutations can be ordered according to how they compare - * {@link lexicographicaly lexicographical_compare} to each other; The first such-sorted possible permutation (the one - * that would compare *lexicographically smaller* to all other permutations) is the one which has all its elements - * sorted in ascending order, and the largest has all its elements sorted in descending order. - * - * The comparisons of individual elements are performed using the *compare*. - * - * If the function can determine the previous permutation, it rearranges the elements as such and returns true. If - * that was not possible (because it is already at the lowest possible permutation), it rearranges the elements - * according to the last permutation (sorted in descending order) and returns false. - * - * @param first Bidirectional iterators to the initial positions of the sequence - * @param last Bidirectional iterators to the final positions of the sequence. The range used is [*first*, *last*), - * which contains all the elements between *first* and *last*, including the element pointed by *first* - * but not the element pointed by *last*. - * @param compare Binary function that accepts two arguments of the type pointed by BidirectionalIterator, and returns - * a value convertible to bool. The value returned indicates whether the first argument is considered - * to go before the second in the specific strict weak ordering it defines. - * - * @return true if the function could rearrange the object as a lexicographicaly smaller permutation. Otherwise, the - * function returns false to indicate that the arrangement is not less than the previous, but the largest - * possible (sorted in descending order). - */ - function prev_permutation>(first: BidirectionalIterator, last: BidirectionalIterator, compare: (x: T, y: T) => boolean): boolean; - /** - * Transform range to next permutation. - * - * Rearranges the elements in the range [*first*, *last*) into the next *lexicographically greater* permutation. - * - * A permutation is each one of the *N!* possible arrangements the elements can take (where *N* is the number of - * elements in the range). Different permutations can be ordered according to how they compare - * {@link lexicographicaly lexicographical_compare} to each other; The first such-sorted possible permutation (the one - * that would compare *lexicographically smaller* to all other permutations) is the one which has all its elements - * sorted in ascending order, and the largest has all its elements sorted in descending order. - * - * The comparisons of individual elements are performed using the {@link std.less} function. - * - * If the function can determine the next higher permutation, it rearranges the elements as such and returns true. If - * that was not possible (because it is already at the largest possible permutation), it rearranges the elements - * according to the first permutation (sorted in ascending order) and returns false. - * - * @param first Bidirectional iterators to the initial positions of the sequence - * @param last Bidirectional iterators to the final positions of the sequence. The range used is [*first*, *last*), - * which contains all the elements between *first* and *last*, including the element pointed by *first* - * but not the element pointed by *last*. - * - * @return true if the function could rearrange the object as a lexicographicaly greater permutation. Otherwise, the - * function returns false to indicate that the arrangement is not greater than the previous, but the lowest - * possible (sorted in ascending order). - */ - function next_permutation>(first: BidirectionalIterator, last: BidirectionalIterator): boolean; - /** - * Transform range to next permutation. - * - * Rearranges the elements in the range [*first*, *last*) into the next *lexicographically greater* permutation. - * - * A permutation is each one of the *N!* possible arrangements the elements can take (where *N* is the number of - * elements in the range). Different permutations can be ordered according to how they compare - * {@link lexicographicaly lexicographical_compare} to each other; The first such-sorted possible permutation (the one - * that would compare *lexicographically smaller* to all other permutations) is the one which has all its elements - * sorted in ascending order, and the largest has all its elements sorted in descending order. - * - * The comparisons of individual elements are performed using the *compare*. - * - * If the function can determine the next higher permutation, it rearranges the elements as such and returns true. If - * that was not possible (because it is already at the largest possible permutation), it rearranges the elements - * according to the first permutation (sorted in ascending order) and returns false. - * - * @param first Bidirectional iterators to the initial positions of the sequence - * @param last Bidirectional iterators to the final positions of the sequence. The range used is [*first*, *last*), - * which contains all the elements between *first* and *last*, including the element pointed by *first* - * but not the element pointed by *last*. - * @param compare Binary function that accepts two arguments of the type pointed by BidirectionalIterator, and returns - * a value convertible to bool. The value returned indicates whether the first argument is considered - * to go before the second in the specific strict weak ordering it defines. - * - * @return true if the function could rearrange the object as a lexicographicaly greater permutation. Otherwise, the - * function returns false to indicate that the arrangement is not greater than the previous, but the lowest - * possible (sorted in ascending order). - */ - function next_permutation>(first: BidirectionalIterator, last: BidirectionalIterator, compare: (x: T, y: T) => boolean): boolean; -} -declare namespace std.base { - /** - *

Static class holding enumeration codes of color of Red-black tree.

- * - *

Color codes imposed to nodes of RB-Tree are following those rules:

- * - *
    - *
  1. A node is either red or black.
  2. - *
  3. The root is black. This rule is sometimes omitted. Since the root can - * always be changed from red to black, but not - * necessarily vice versa, this rule has little effect on analysis.
  4. - *
  5. All leaves (NIL; null) are black.
  6. - *
  7. If a node is red, then both its children are - * black.
  8. - *
  9. Every path from a given node to any of its descendant NIL nodes contains the same number of - * black nodes. Some definitions: the number of - * black nodes from the root to a node is the node's - * black depth; the uniform number of black - * nodes in all paths from root to the leaves is called the black-height of - * the red-black tree.
  10. - *
- * - * @author Migrated by Jeongho Nam - */ - enum Color { - /** - *

Code of color black.

- * - *
    - *
  • Those are clearly black: root, leaf nodes or children nodes of red.
  • - *
  • Every path from a given nodes containes the same number of black nodes exclude NIL(s).
  • - *
- */ - BLACK = 0, - /** - *

Code of color red.

- */ - RED = 1, - } -} -declare namespace std.base { - /** - *

An abstract container.

- * - *

- * - *

- * - *

Container properties

- *
- *
Sequence
- *
Elements in sequence containers are ordered in a strict linear sequence. Individual elements are - * accessed by their position in this sequence.
- * - *
Doubly-linked list
- *
Each element keeps information on how to locate the next and the previous elements, allowing - * constant time insert and erase operations before or after a specific element (even of entire ranges), - * but no direct random access.
- *
- * - * @param Type of elements. - * - * @author Jeongho Nam - */ - abstract class Container implements IContainer { - /** - * Default Constructor. - */ - protected constructor(); - /** - * @inheritdoc - */ - abstract assign>(begin: InputIterator, end: InputIterator): void; - /** - * @inheritdoc - */ - clear(): void; - /** - * @inheritdoc - */ - abstract begin(): Iterator; - /** - * @inheritdoc - */ - abstract end(): Iterator; - /** - * @inheritdoc - */ - abstract rbegin(): base.IReverseIterator; - /** - * @inheritdoc - */ - abstract rend(): base.IReverseIterator; - /** - * @inheritdoc - */ - abstract size(): number; - /** - * @inheritdoc - */ - empty(): boolean; - /** - * @inheritdoc - */ - abstract push(...items: T[]): number; - /** - * @inheritdoc - */ - abstract insert(position: Iterator, val: T): Iterator; - /** - * @inheritdoc - */ - abstract erase(position: Iterator): Iterator; - /** - * @inheritdoc - */ - abstract erase(begin: Iterator, end: Iterator): Iterator; - /** - * @inheritdoc - */ - swap(obj: IContainer): void; - } -} -declare namespace std.base { - /** - *

An abstract error instance.

- * - *

{@link ErrorInstance} is an abstract class of {@link ErrorCode} and {@link ErrorCondition} - * holding an error instance's identifier {@link value}, associated with a {@link category}.

- * - *

The operating system and other low-level applications and libraries generate numerical error codes to - * represent possible results. These numerical values may carry essential information for a specific platform, - * but be non-portable from one platform to another.

- * - *

Objects of this class associate such numerical codes to {@link ErrorCategory error categories}, - * so that they can be interpreted when needed as more abstract (and portable) - * {@link ErrorCondition error conditions}.

- * - *

- *

- * - * @author Jeongho Nam - */ - abstract class ErrorInstance { - /** - * @hidden - */ - protected category_: ErrorCategory; - /** - * @hidden - */ - protected value_: number; - /** - * Default Constructor. - */ - constructor(); - /** - * Construct from a numeric value and error category. - * - * @param val A numerical value identifying an error instance. - * @param category A reference to an {@link ErrorCategory} object. - */ - constructor(val: number, category: ErrorCategory); - /** - *

Assign error instance.

- * - *

Assigns the {@link ErrorCode} object a value of val associated with the {@link ErrorCategory}.

- * - * @param val A numerical value identifying an error instance. - * @param category A reference to an {@link ErrorCategory} object. - */ - assign(val: number, category: ErrorCategory): void; - /** - *

Clear error instance.

- * - *

Clears the value in the {@link ErrorCode} object so that it is set to a value of 0 of the - * {@link ErrorCategory.systemCategory ErrorCategory.systemCategory()} (indicating no error).

- */ - clear(): void; - /** - *

Get category.

- * - *

Returns a reference to the {@link ErrorCategory} associated with the {@link ErrorCode} object.

- * - * @return A reference to a non-copyable object of a type derived from {@link ErrorCategory}. - */ - category(): ErrorCategory; - /** - *

Error value.

- * - *

Returns the error value associated with the {@link ErrorCode} object.

- * - * @return The error value. - */ - value(): number; - /** - *

Get message.

- * - *

Returns the message associated with the error instance.

- * - *

Error messages are defined by the {@link category} the error instance belongs to.

- * - *

This function returns the same as if the following member was called:

- * - *

category().message(value())

- * - * @return A string object with the message associated with the {@link ErrorCode}. - */ - message(): string; - /** - *

Default error condition.

- * - *

Returns the default {@link ErrorCondition}object associated with the {@link ErrorCode} object.

- * - *

This function returns the same as if the following member was called:

- * - *

category().default_error_condition(value())

- * - *

{@link ErrorCategory.default_error_condition ErrorCategory.default_error_condition()} - * is a virtual member function, that can operate differently for each category.

- * - * @return An {@link ErrorCondition}object that corresponds to the {@link ErrorCode} object. - */ - default_error_condition(): ErrorCondition; - /** - *

Convert to bool.

- * - *

Returns whether the error instance has a numerical {@link value} other than 0.

- * - *

If it is zero (which is generally used to represent no error), the function returns false, otherwise it returns true.

- * - * @return true if the error's numerical value is not zero. - * false otherwise. - */ - to_bool(): boolean; - } -} -declare namespace std.base { - enum Hash { - MIN_SIZE = 10, - RATIO = 1, - MAX_RATIO = 2, - } - /** - *

Hask buckets.

- * - * @author Jeongho Nam - */ - abstract class HashBuckets { - /** - * @hidden - */ - private buckets_; - /** - * @hidden - */ - private item_size_; - /** - * Default Constructor. - */ - protected constructor(); - /** - *

Reconstruction of hash table.

- * - *

All the elements in the hash buckets are rearranged according to their hash value into the new set of - * buckets. This may alter the order of iteration of elements within the container.

- * - *

Notice that {@link rehash rehashes} are automatically performed whenever its number of elements is going - * to greater than its own {@link capacity}.

- * - * @param size Number of bucket size to rehash. - */ - rehash(size: number): void; - clear(): void; - size(): number; - item_size(): number; - capacity(): number; - at(index: number): Vector; - hash_index(val: T): number; - insert(val: T): void; - erase(val: T): void; - } -} -declare namespace std.base { - /** - *

Common interface for hash map.

- * - *

{@link IHashMap}s are associative containers that store elements formed by the combination of - * a key value and a mapped value.

- * - *

In an {@link IHashMap}, the key value is generally used to uniquely identify the - * element, while the mapped value is an object with the content associated to this key. - * Types of key and mapped value may differ.

- * - *

Internally, the elements in the {@link IHashMap} are not sorted in any particular order with - * respect to either their key or mapped values, but organized into buckets depending on - * their hash values to allow for fast access to individual elements directly by their key values - * (with a constant average time complexity on average).

- * - *

Elements with equivalent keys are grouped together in the same bucket and in such a way that - * an iterator can iterate through all of them. Iterators in the container are doubly linked iterators.

- * - *

- * - *

- * - *

Container properties

- *
- *
Associative
- *
Elements in associative containers are referenced by their key and not by their absolute - * position in the container.
- * - *
Hashed
- *
Hashed containers organize their elements using hash tables that allow for fast access to elements - * by their key.
- * - *
Map
- *
Each element associates a key to a mapped value: - * Keys are meant to identify the elements whose main content is the mapped value.
- *
- * - * @param Type of the key values. - * Each element in an {@link IHashMap} is identified by a key value. - * @param Type of the mapped value. - * Each element in an {@link IHashMap} is used to store some data as its mapped value. - * - * @reference http://www.cplusplus.com/reference/unordered_map - * @author Jeongho Nam - */ - interface IHashMap { - /** - *

Return iterator to beginning.

- * - *

Returns an iterator pointing to the first element in the {@link IHashMap}.

- * - *

Notice that an {@link IHashMap} object makes no guarantees on which specific element is considered its - * first element. But, in any case, the range that goes from its begin to its end covers all the elements in the - * container, until invalidated.

- * - * @return An iterator to the first element in the container. - */ - begin(): MapIterator; - /** - *

Return iterator to beginning.

- * - *

Returns an iterator pointing to the first element in one of buckets in the {@link IHashMap}.

- * - *

Notice that an {@link IHashMap} object makes no guarantees on which specific element is considered its - * first element. But, in any case, the range that goes from its begin to its end covers all the elements in the - * bucket, until invalidated.

- * - * @param index Bucket number. This shall be lower than {@link bucket_count}. - * - * @return An iterator to the first element in the bucket. - */ - begin(index: number): MapIterator; - /** - *

Return iterator to end.

- * - *

Returns an iterator pointing to the past-the-end element in the {@link HaspMap} container.

- * - *

The iterator returned by end does not point to any element, but to the position that follows the last - * element in the {@link HaspMap} container (its past-the-end position). Thus, the value returned shall - * not be dereferenced - it is generally used to describe the open-end of a range, such as - * [begin, end).

- * - *

Notice that an {@link IHashMap} object makes no guarantees on which order its elements follow. But, in any - * case, the range that goes from its begin to its end covers all the elements in the container (or the bucket), - * until invalidated.

- * - * @return An iterator to the element past the end of the container. - */ - end(): MapIterator; - /** - *

Return iterator to end.

- * - *

Returns an iterator pointing to the past-the-end element in the {@link HaspMap} container.

- * - *

The iterator returned by end does not point to any element, but to the position that follows the last - * element in the {@link HaspMap} container (its past-the-end position). Thus, the value returned shall - * not be dereferenced - it is generally used to describe the open-end of a range, such as - * [begin, end).

- * - *

Notice that an {@link IHashMap} object makes no guarantees on which order its elements follow. But, in any - * case, the range that goes from its begin to its end covers all the elements in the container (or the bucket), - * until invalidated.

- * - * @param index Bucket number. This shall be lower than {@link bucket_count}. - * - * @return An iterator to the element past the end of the bucket. - */ - end(index: number): MapIterator; - /** - *

Return {@link MapReverseIterator reverse iterator} to reverse beginning.

- * - *

Returns a {@link MapReverseIterator reverse iterator} pointing to the last element in the {@link IHashMap} - * (i.e., its reverse beginning).

- * - * {@link MapReverseIterator Reverse iterators} iterate backwards: increasing them moves them towards the - * beginning of the container.

- * - *

{@link rbegin} points to the element preceding the one that would be pointed to by member {@link end}.

- * - *

Notice that an {@link IHashMap} object makes no guarantees on which specific element is considered its - * first element. But, in any case, the range that goes from its begin to its end covers all the elements in the - * bucket, until invalidated.

- * - * @return A {@link MapReverseIterator reverse iterator} to the reverse beginning of the sequence - */ - rbegin(): MapReverseIterator; - /** - *

Return {@link MapReverseIterator reverse iterator} to reverse beginning.

- * - *

Returns a {@link MapReverseIterator reverse iterator} pointing to the last element in one of buckets in the - * {@link IHashMap} (i.e., its reverse beginning).

- * - * {@link MapReverseIterator Reverse iterators} iterate backwards: increasing them moves them towards the - * beginning of the container.

- * - *

{@link rbegin} points to the element preceding the one that would be pointed to by member {@link end}.

- * - *

Notice that an {@link IHashMap} object makes no guarantees on which specific element is considered its - * first element. But, in any case, the range that goes from its begin to its end covers all the elements in the - * bucket, until invalidated.

- * - * @param index Bucket number. This shall be lower than {@link bucket_count}. - * - * @return A {@link MapReverseIterator reverse iterator} to the reverse beginning of the sequence - */ - rbegin(index: number): MapReverseIterator; - /** - *

Return {@link MapReverseIterator reverse iterator} to reverse end.

- * - *

Returns a {@link MapReverseIterator reverse iterator} pointing to the theoretical element right before - * the first element in the {@link IHashMap hash map container} (which is considered its reverse end).

- * - *

The range between {@link IHashMap}.{@link rbegin} and {@link IHashMap}.{@link rend} contains all the - * elements of the container (in reverse order).

- * - *

Notice that an {@link IHashMap} object makes no guarantees on which order its elements follow. But, in any - * case, the range that goes from its begin to its end covers all the elements in the container (or the bucket), - * until invalidated.

- * - * @return A {@link MapReverseIterator reverse iterator} to the reverse end of the sequence. - */ - rend(): MapReverseIterator; - /** - *

Return {@link MapReverseIterator reverse iterator} to reverse end.

- * - *

Returns a {@link MapReverseIterator reverse iterator} pointing to the theoretical element right before - * the first element in one of buckets in the {@link IHashMap hash map container} (which is considered its - * reverse end).

- * - *

The range between {@link IHashMap}.{@link rbegin} and {@link IHashMap}.{@link rend} contains all the - * elements of the container (in reverse order).

- * - *

Notice that an {@link IHashMap} object makes no guarantees on which order its elements follow. But, in any - * case, the range that goes from its begin to its end covers all the elements in the container (or the bucket), - * until invalidated.

- * - * @param index Bucket number. This shall be lower than {@link bucket_count}. - * - * @return A {@link MapReverseIterator reverse iterator} to the reverse end of the sequence. - */ - rend(index: number): MapReverseIterator; - /** - *

Return number of buckets.

- * - *

Returns the number of buckets in the {@link IHashMap} container.

- * - *

A bucket is a slot in the container's internal hash table to which elements are assigned based on the - * hash value of their key.

- * - *

The number of buckets influences directly the {@link load_factor load factor} of the container's hash - * table (and thus the probability of collision). The container automatically increases the number of buckets to - * keep the load factor below a specific threshold (its {@link max_load_factor}), causing a {@link rehash} each - * time the number of buckets needs to be increased.

- * - * @return The current amount of buckets. - */ - bucket_count(): number; - /** - *

Return bucket size.

- * - *

Returns the number of elements in bucket n.

- * - *

A bucket is a slot in the container's internal hash table to which elements are assigned based on the hash - * value of their key.

- * - *

The number of elements in a bucket influences the time it takes to access a particular element in the - * bucket. The container automatically increases the number of buckets to keep the {@link load_cator load factor} - * (which is the average bucket size) below its {@link max_load_factor}.

- * - * @param n Bucket number. This shall be lower than {@link bucket_count}. - * - * @return The number of elements in bucket n. - */ - bucket_size(n: number): number; - /** - *

Get maximum load factor.

- * - *

Returns the current maximum load factor for the {@link HashMultiMap} container.

- * - *

The load factor is the ratio between the number of elements in the container (its {@link size}) and the - * number of buckets ({@link bucket_count}).

- * - *

By default, {@link HashMultiMap} containers have a {@link max_load_factor} of 1.0.

- * - *

The load factor influences the probability of collision in the hash table (i.e., the probability of two - * elements being located in the same bucket). The container uses the value of max_load_factor as the threshold - * that forces an increase in the number of buckets (and thus causing a {@link rehash}).

- * - *

Note though, that implementations may impose an upper limit on the number of buckets (see - * {@link max_bucket_count}), which may force the container to ignore the {@link max_load_factor}.

- * - * @return The current load factor. - */ - max_load_factor(): number; - /** - *

Set maximum load factor.

- * - *

Sets z as the cnew maximum load factor for the {@link HashMultiMap} container.

- * - *

The load factor is the ratio between the number of elements in the container (its {@link size}) and the - * number of buckets ({@link bucket_count}).

- * - *

By default, {@link HashMultiMap} containers have a {@link max_load_factor} of 1.0.

- * - *

The load factor influences the probability of collision in the hash table (i.e., the probability of two - * elements being located in the same bucket). The container uses the value of max_load_factor as the threshold - * that forces an increase in the number of buckets (and thus causing a {@link rehash}).

- * - *

Note though, that implementations may impose an upper limit on the number of buckets (see - * {@link max_bucket_count}), which may force the container to ignore the {@link max_load_factor}.

- * - * @param z The new maximum load factor. - */ - max_load_factor(z: number): void; - /** - *

Locate element's bucket.

- * - *

Returns the bucket number where the element with key is located.

- * - *

A bucket is a slot in the container's internal hash table to which elements are assigned based on the - * hash value of their key. Buckets are numbered from 0 to ({@link bucket_count} - 1).

- * - *

Individual elements in a bucket can be accessed by means of the range iterators returned by - * {@link begin} and {@link end}.

- * - * @param key Key whose bucket is to be located. - */ - bucket(key: Key): number; - /** - *

Request a capacity change.

- * - *

Sets the number of buckets in the container ({@link bucket_count}) to the most appropriate to contain at - * least n elements.

- * - *

If n is greater than the current {@link bucket_count} multiplied by the {@link max_load_factor}, - * the container's {@link bucket_count} is increased and a {@link rehash} is forced.

- * - *

If n is lower than that, the function may have no effect.

- * - * @param n The number of elements requested as minimum capacity. - */ - reserve(n: number): void; - /** - *

Set number of buckets.

- * - *

Sets the number of buckets in the container to n or more.

- * - *

If n is greater than the current number of buckets in the container ({@link bucket_count}), a - * {@link HashBuckets.rehash rehash} is forced. The new {@link bucket_count bucket count} can either be equal or - * greater than n.

- * - *

If n is lower than the current number of buckets in the container ({@link bucket_count}), the - * function may have no effect on the {@link bucket_count bucket count} and may not force a - * {@link HashBuckets.rehash rehash}.

- * - *

A {@link HashBuckets.rehash rehash} is the reconstruction of the hash table: All the elements in the - * container are rearranged according to their hash value into the new set of buckets. This may alter the order - * of iteration of elements within the container.

- * - *

{@link HashBuckets.rehash Rehashes} are automatically performed by the container whenever its - * {@link load_factor load factor} is going to surpass its {@link max_load_factor} in an operation.

- * - *

Notice that this function expects the number of buckets as argument. A similar function exists, - * {@link reserve}, that expects the number of elements in the container as argument.

- * - * @param n The minimum number of buckets for the container hash table. - */ - rehash(n: number): void; - } -} -declare namespace std.base { - /** - *

Hash buckets storing {@link MapIterator MapIterators}.

- * - *

- * - *

- * - * @author Jeongho Nam - */ - class MapHashBuckets extends HashBuckets> { - private map; - constructor(map: MapContainer); - find(key: K): MapIterator; - } -} -declare namespace std.base { - /** - *

A common interface for hash set.

- * - *

{@link IHashSet}s are containers that store unique elements in no particular order, and which - * allow for fast retrieval of individual elements based on their value.

- * - *

In an {@link IHashSet}, the value of an element is at the same time its key, that - * identifies it uniquely. Keys are immutable, therefore, the elements in an {@link IHashSet} cannot be - * modified once in the container - they can be inserted and removed, though.

- * - *

Internally, the elements in the {@link IHashSet} are not sorted in any particular order, but - * organized into buckets depending on their hash values to allow for fast access to individual elements - * directly by their values (with a constant average time complexity on average).

- * - *

{@link IHashSet} containers are faster than {@link TreeSet} containers to access individual - * elements by their key, although they are generally less efficient for range iteration through a - * subset of their elements.

- * - *

- * - *

- * - *

Container properties

- *
- *
Associative
- *
Elements in associative containers are referenced by their key and not by their absolute - * position in the container.
- * - *
Hashed
- *
Hashed containers organize their elements using hash tables that allow for fast access to elements - * by their key.
- * - *
Set
- *
The value of an element is also the key used to identify it.
- *
- * - * @param Type of the elements. - * Each element in an {@link IHashSet} is also uniquely identified by this value. - * - * @reference http://www.cplusplus.com/reference/unordered_set/unordered_set - * @author Jeongho Nam - */ - interface IHashSet { - /** - *

Return iterator to beginning.

- * - *

Returns an iterator pointing to the first element in the {@link IHashSet}.

- * - *

Notice that an {@link IHashSet} object makes no guarantees on which specific element is considered its - * first element. But, in any case, the range that goes from its begin to its end covers all the elements in the - * container, until invalidated.

- * - * @return An iterator to the first element in the container. - */ - begin(): SetIterator; - /** - *

Return iterator to beginning.

- * - *

Returns an iterator pointing to the first element in one of buckets in the {@link IHashSet}.

- * - *

Notice that an {@link IHashSet} object makes no guarantees on which specific element is considered its - * first element. But, in any case, the range that goes from its begin to its end covers all the elements in the - * bucket, until invalidated.

- * - * @param index Bucket number. This shall be lower than {@link bucket_count}. - * - * @return An iterator to the first element in the bucket. - */ - begin(index: number): SetIterator; - /** - *

Return iterator to end.

- * - *

Returns an iterator pointing to the past-the-end element in the {@link HaspMap} container.

- * - *

The iterator returned by end does not point to any element, but to the position that follows the last - * element in the {@link HaspMap} container (its past-the-end position). Thus, the value returned shall - * not be dereferenced - it is generally used to describe the open-end of a range, such as - * [begin, end).

- * - *

Notice that an {@link IHashSet} object makes no guarantees on which order its elements follow. But, in any - * case, the range that goes from its begin to its end covers all the elements in the container (or the bucket), - * until invalidated.

- * - * @return An iterator to the element past the end of the container. - */ - end(): SetIterator; - /** - *

Return iterator to end.

- * - *

Returns an iterator pointing to the past-the-end element in the {@link HaspMap} container.

- * - *

The iterator returned by end does not point to any element, but to the position that follows the last - * element in the {@link HaspMap} container (its past-the-end position). Thus, the value returned shall - * not be dereferenced - it is generally used to describe the open-end of a range, such as - * [begin, end).

- * - *

Notice that an {@link IHashSet} object makes no guarantees on which order its elements follow. But, in any - * case, the range that goes from its begin to its end covers all the elements in the container (or the bucket), - * until invalidated.

- * - * @param index Bucket number. This shall be lower than {@link bucket_count}. - * - * @return An iterator to the element past the end of the bucket. - */ - end(index: number): SetIterator; - rbegin(): SetReverseIterator; - rbegin(index: number): SetReverseIterator; - rend(): SetReverseIterator; - rend(index: number): SetReverseIterator; - /** - *

Return number of buckets.

- * - *

Returns the number of buckets in the {@link IHashSet} container.

- * - *

A bucket is a slot in the container's internal hash table to which elements are assigned based on the - * hash value of their key.

- * - *

The number of buckets influences directly the {@link load_factor load factor} of the container's hash - * table (and thus the probability of collision). The container automatically increases the number of buckets to - * keep the load factor below a specific threshold (its {@link max_load_factor}), causing a {@link rehash} each - * time the number of buckets needs to be increased.

- * - * @return The current amount of buckets. - */ - bucket_count(): number; - /** - *

Return bucket size.

- * - *

Returns the number of elements in bucket n.

- * - *

A bucket is a slot in the container's internal hash table to which elements are assigned based on the hash - * value of their key.

- * - *

The number of elements in a bucket influences the time it takes to access a particular element in the - * bucket. The container automatically increases the number of buckets to keep the {@link load_cator load factor} - * (which is the average bucket size) below its {@link max_load_factor}.

- * - * @param n Bucket number. This shall be lower than {@link bucket_count}. - * - * @return The number of elements in bucket n. - */ - bucket_size(n: number): number; - /** - *

Get maximum load factor.

- * - *

Returns the current maximum load factor for the {@link HashMultiMap} container.

- * - *

The load factor is the ratio between the number of elements in the container (its {@link size}) and the - * number of buckets ({@link bucket_count}).

- * - *

By default, {@link HashMultiMap} containers have a {@link max_load_factor} of 1.0.

- * - *

The load factor influences the probability of collision in the hash table (i.e., the probability of two - * elements being located in the same bucket). The container uses the value of max_load_factor as the threshold - * that forces an increase in the number of buckets (and thus causing a {@link rehash}).

- * - *

Note though, that implementations may impose an upper limit on the number of buckets (see - * {@link max_bucket_count}), which may force the container to ignore the {@link max_load_factor}.

- * - * @return The current load factor. - */ - max_load_factor(): number; - /** - *

Set maximum load factor.

- * - *

Sets z as the cnew maximum load factor for the {@link HashMultiMap} container.

- * - *

The load factor is the ratio between the number of elements in the container (its {@link size}) and the - * number of buckets ({@link bucket_count}).

- * - *

By default, {@link HashMultiMap} containers have a {@link max_load_factor} of 1.0.

- * - *

The load factor influences the probability of collision in the hash table (i.e., the probability of two - * elements being located in the same bucket). The container uses the value of max_load_factor as the threshold - * that forces an increase in the number of buckets (and thus causing a {@link rehash}).

- * - *

Note though, that implementations may impose an upper limit on the number of buckets (see - * {@link max_bucket_count}), which may force the container to ignore the {@link max_load_factor}.

- * - * @param z The new maximum load factor. - */ - max_load_factor(z: number): void; - /** - *

Locate element's bucket.

- * - *

Returns the bucket number where the element with key is located.

- * - *

A bucket is a slot in the container's internal hash table to which elements are assigned based on the - * hash value of their key. Buckets are numbered from 0 to ({@link bucket_count} - 1).

- * - *

Individual elements in a bucket can be accessed by means of the range iterators returned by - * {@link begin} and {@link end}.

- * - * @param key Key whose bucket is to be located. - */ - bucket(key: T): number; - /** - *

Request a capacity change.

- * - *

Sets the number of buckets in the container ({@link bucket_count}) to the most appropriate to contain at - * least n elements.

- * - *

If n is greater than the current {@link bucket_count} multiplied by the {@link max_load_factor}, - * the container's {@link bucket_count} is increased and a {@link rehash} is forced.

- * - *

If n is lower than that, the function may have no effect.

- * - * @param n The number of elements requested as minimum capacity. - */ - reserve(n: number): void; - /** - *

Set number of buckets.

- * - *

Sets the number of buckets in the container to n or more.

- * - *

If n is greater than the current number of buckets in the container ({@link bucket_count}), a - * {@link HashBuckets.rehash rehash} is forced. The new {@link bucket_count bucket count} can either be equal or - * greater than n.

- * - *

If n is lower than the current number of buckets in the container ({@link bucket_count}), the - * function may have no effect on the {@link bucket_count bucket count} and may not force a - * {@link HashBuckets.rehash rehash}.

- * - *

A {@link HashBuckets.rehash rehash} is the reconstruction of the hash table: All the elements in the - * container are rearranged according to their hash value into the new set of buckets. This may alter the order - * of iteration of elements within the container.

- * - *

{@link HashBuckets.rehash Rehashes} are automatically performed by the container whenever its - * {@link load_factor load factor} is going to surpass its {@link max_load_factor} in an operation.

- * - *

Notice that this function expects the number of buckets as argument. A similar function exists, - * {@link reserve}, that expects the number of elements in the container as argument.

- * - * @param n The minimum number of buckets for the container hash table. - */ - rehash(n: number): void; - } -} -declare namespace std.base { - /** - *

Hash buckets storing {@link SetIterator SetIterators}.

- * - *

- * - *

- * - * @author Jeongho Nam - */ - class SetHashBuckets extends HashBuckets> { - private set; - constructor(set: SetContainer); - find(val: T): SetIterator; - } -} -declare namespace std.base { - /** - *

Array

- * - *

{@link IArray} is an interface for sequence containers representing arrays that can change in - * {@link size}. However, compared to arrays, {@link IArray} objectss consume more memory in exchange for - * the ability to manage storage and grow dynamically in an efficient way.

- * - *

Both {@link Vector Vectors} and {@link Deque Deques} who implemented {@link IArray} provide a very - * similar interface and can be used for similar purposes, but internally both work in quite different ways: - * While {@link Vector Vectors} use a single array that needs to be occasionally reallocated for growth, the - * elements of a {@link Deque} can be scattered in different chunks of storage, with the container keeping the - * necessary information internally to provide direct access to any of its elements in constant time and with a - * uniform sequential interface (through iterators). Therefore, {@link Deque Deques} are a little more complex - * internally than {@link Vector Vectors}, but this allows them to grow more efficiently under certain - * circumstances, especially with very long sequences, where reallocations become more expensive.

- * - *

Both {@link Vector Vectors} and {@link Deque Deques} provide a very similar interface and can be used for - * similar purposes, but internally both work in quite different ways: While {@link Vector Vectors} use a single - * array that needs to be occasionally reallocated for growth, the elements of a {@link Deque} can be scattered - * in different chunks of storage, with the container keeping the necessary information internally to provide - * direct access to any of its elements in constant time and with a uniform sequential interface (through - * iterators). Therefore, {@link Deque Deques} are a little more complex internally than {@link Vector Vectors}, - * but this allows them to grow more efficiently under certain circumstances, especially with very long - * sequences, where reallocations become more expensive.

- * - *

For operations that involve frequent insertion or removals of elements at positions other than the - * beginning or the end, {@link IArray} objects perform worse and have less consistent iterators and references - * than {@link List Lists}

. - * - *

- * - *

- * - *

Container properties

- *
- *
Sequence
- *
- * Elements in sequence containers are ordered in a strict linear sequence. Individual elements are - * accessed by their position in this sequence. - *
- * - *
Dynamic array
- *
- * Allows direct access to any element in the sequence, even through pointer arithmetics, and provides - * relatively fast addition/removal of elements at the end of the sequence. - *
- *
- * - * @param Type of the elements. - * - * @author Jeongho Nam - */ - interface IArrayContainer extends ILinearContainer { - /** - *

Request a change in capacity.

- * - *

Requests that the {@link IArray container} {@link capacity} be at least enough to contain - * n elements.

- * - *

If n is greater than the current {@link IArray container} {@link capacity}, the - * function causes the {@link IArray container} to reallocate its storage increasing its - * {@link capacity} to n (or greater).

- * - *

In all other cases, the function call does not cause a reallocation and the - * {@link IArray container} {@link capacity} is not affected.

- * - *

This function has no effect on the {@link IArray container} {@link size} and cannot alter - * its elements.

- * - * @param n Minimum {@link capacity} for the {@link IArray container}. - * Note that the resulting {@link capacity} may be equal or greater than n. - */ - reserve(n: number): void; - /** - *

Return size of allocated storage capacity.

- * - *

Returns the size of the storage space currently allocated for the {@link IArray container}, - * expressed in terms of elements.

- * - *

This {@link capacity} is not necessarily equal to the {@link IArray container} {@link size}. - * It can be equal or greater, with the extra space allowing to accommodate for growth without the - * need to reallocate on each insertion.

- * - *

Notice that this {@link capacity} does not suppose a limit on the {@link size} of the - * {@link IArray container}. When this {@link capacity} is exhausted and more is needed, it is - * automatically expanded by the {@link IArray container} (reallocating it storage space). - * The theoretical limit on the {@link size} of a {@link IArray container} is given by member - * {@link max_size}.

- * - *

The {@link capacity} of a {@link IArray container} can be explicitly altered by calling member - * {@link IArray.reserve}.

- * - * @return The size of the currently allocated storage capacity in the {@link IArray container}, - * measured in terms of the number elements it can hold. - */ - capacity(): number; - /** - *

Access element.

- *

Returns a value to the element at position index in the {@link IArray container}.

- * - *

The function automatically checks whether index is within the bounds of valid elements - * in the {@link IArray container}, throwing an {@link OutOfRange} exception if it is not (i.e., - * if index is greater or equal than its {@link size}).

- * - * @param index Position of an element in the - * If this is greater than or equal to the {@link IArray container} {@link size}, an - * exception of type {@link OutOfRange} is thrown. Notice that the first - * element has a position of 0 (not 1). - * - * @return The element at the specified position in the - */ - at(index: number): T; - /** - *

Modify element.

- *

Replaces an element at the specified position (index) in this {@link IArray container} - * with the specified element (val).

- * - *

The function automatically checks whether index is within the bounds of valid elements - * in the {@link IArray container}, throwing an {@link OutOfRange} exception if it is not (i.e., if - * index is greater or equal than its {@link size}).

- * - * @.param index A specified position of the value to replace. - * @param val A value to be stored at the specified position. - * - * @return The previous element had stored at the specified position. - */ - set(index: number, val: T): void; - } - /** - *

Random-access iterator.

- * - *

{@link IArrayIterator Random-access iterators} are iterators that can be used to access elements at an - * arbitrary offset position relative to the element they point to, offering the same functionality as pointers. - *

- * - *

{@link IArrayIterator Random-access iterators} are the most complete iterators in terms of functionality. - * All pointer types are also valid {@link IArrayIterator random-access iterators}.

- * - *

There is not a single type of {@link IArrayIterator random-access iterator}: Each container may define its - * own specific iterator type able to iterate through it and access its elements.

- * - *

- * - *

- * - * @reference http://www.cplusplus.com/reference/iterator/RandomAccessIterator - * @author Jeongho Nam - */ - interface IArrayIterator extends ILinearIterator { - /** - * Get index, sequence number of the iterator in the source {@link IArray array}. - * - * @return Sequence number of the iterator in the source {@link IArray array}. - */ - index: number; - /** - * @inheritdoc - */ - prev(): IArrayIterator; - /** - * @inheritdoc - */ - next(): IArrayIterator; - } -} -declare namespace std.base { - /** - *

An interface of containers.

- * - *

{@link IContainer} is an interface designed for sequence containers. Sequence containers of STL - * (Standard Template Library) are based on the {@link IContainer}.

- * - *

- * - *

- * - *

Container properties

- *
- *
Sequence
- *
Elements in sequence containers are ordered in a strict linear sequence. Individual elements are - * accessed by their position in this sequence.
- * - *
Doubly-linked list
- *
Each element keeps information on how to locate the next and the previous elements, allowing - * constant time insert and erase operations before or after a specific element (even of entire ranges), - * but no direct random access.
- *
- * - * @param Type of elements. - * - * @author Jeongho Nam - */ - interface IContainer { - /** - *

Assign new content to content.

- * - *

Assigns new contents to the container, replacing its current contents, and modifying its - * {@link size} accordingly.

- * - * @param begin Input interator of the initial position in a sequence. - * @param end Input interator of the final position in a sequence. - */ - assign>(begin: InputIterator, end: InputIterator): void; - /** - *

Clear content.

- * - *

Removes all elements from the Container, leaving the container with a size of 0.

- */ - clear(): void; - /** - *

Return iterator to beginning.

- * - *

Returns an iterator referring the first element in the

- * - *

Note

- *

If the container is {@link empty}, the returned iterator is same with {@link end end()}.

- * - * @return An iterator to the first element in the The iterator containes the first element's value. - */ - begin(): Iterator; - /** - *

Return iterator to end.

- *

Returns an iterator referring to the past-the-end element in the

- * - *

The past-the-end element is the theoretical element that would follow the last element in the - * It does not point to any element, and thus shall not be dereferenced.

- * - *

Because the ranges used by functions of the Container do not include the element reference by their - * closing iterator, this function is often used in combination with {@link IContainer}.{@link begin} to - * specify a range including all the elements in the container.

- * - *

Note

- *

Returned iterator from {@link IContainer}.{@link end} does not refer any element. Trying to accessing - * element by the iterator will cause throwing exception ({@link OutOfRange}).

- * - *

If the container is {@link empty}, this function returns the same as {@link Container}.{@link begin}. - *

- * - * @return An iterator to the end element in the - */ - end(): Iterator; - /** - *

Return {@link ReverseIterator reverse iterator} to reverse beginning.

- * - *

Returns a {@link ReverseIterator reverse iterator} pointing to the last element in the container (i.e., - * its reverse beginning).

- * - *

{@link ReverseIterator reverse iterators} iterate backwards: increasing them moves them towards the - * beginning of the

- * - *

{@link rbegin} points to the element right before the one that would be pointed to by member {@link end}. - *

- * - * @return A {@link ReverseIterator reverse iterator} to the reverse beginning of the sequence - */ - rbegin(): base.IReverseIterator; - /** - *

Return {@link ReverseIterator reverse iterator} to reverse end.

- * - *

Returns a {@link ReverseIterator reverse iterator} pointing to the theoretical element preceding the - * first element in the container (which is considered its reverse end).

- * - *

The range between {@link IContainer}.{@link rbegin} and {@link IContainer}.{@link rend} contains all - * the elements of the container (in reverse order). - * - * @return A {@link ReverseIterator reverse iterator} to the reverse end of the sequence - */ - rend(): base.IReverseIterator; - /** - * Return the number of elements in the Container. - * - * @return The number of elements in the - */ - size(): number; - /** - *

Test whether the container is empty.

- *

Returns whether the container is empty (i.e. whether its size is 0).

- * - *

This function does not modify the container in any way. To clear the content of the container, - * see {@link clear clear()}.

- * - * @return true if the container size is 0, false otherwise. - */ - empty(): boolean; - /** - *

Insert elements.

- * - *

Appends new elements to the container, and returns the new size of the

- * - * @param items New elements to insert. - * - * @return New size of the Container. - */ - push(...items: T[]): number; - /** - *

Insert an element.

- * - *

The container is extended by inserting a new element before the element at the specified - * position. This effectively increases the {@link IContainer.size container size} by the amount of - * elements inserted.

- * - * @param position Position in the {@link IContainer} where the new element is inserted. - * {@link iterator} is a member type, defined as a {@link Iterator random access iterator} - * type that points to elements. - * @param val Value to be copied to the inserted element. - * - * @return An iterator that points to the newly inserted element. - */ - insert(position: Iterator, val: T): Iterator; - /** - *

Erase an element.

- * - *

Removes from the container a single element.

- * - *

This effectively reduces the container size by the number of element removed.

- * - * @param position Iterator pointing to a single element to be removed from the Container. - * - * @return An iterator pointing to the element that followed the last element erased by the function - * call. This is the {@link end Container.end} if the operation erased the last element in the - * sequence. - */ - erase(position: Iterator): Iterator; - /** - *

Erase elements.

- * - *

Removes from the container a range of elements.

- * - *

This effectively reduces the container size by the number of elements removed.

- * - * @param begin An iterator specifying a range of beginning to erase. - * @param end An iterator specifying a range of end to erase. - * - * @return An iterator pointing to the element that followed the last element erased by the function - * call. This is the {@link end Container.end} if the operation erased the last element in - * the sequence. - */ - erase(begin: Iterator, end: Iterator): Iterator; - /** - *

Swap content.

- * - *

Exchanges the content of the container by the content of obj, which is another - * {@link IContainer container} object with same type of elements. Sizes and container type may differ.

- * - *

After the call to this member function, the elements in this container are those which were in obj - * before the call, and the elements of obj are those which were in this. All iterators, references and - * pointers remain valid for the swapped objects.

- * - *

Notice that a non-member function exists with the same name, {@link std.swap swap}, overloading that - * algorithm with an optimization that behaves like this member function.

- * - * @param obj Another {@link IContainer container} of the same type of elements (i.e., instantiated - * with the same template parameter, T) whose content is swapped with that of this - * {@link container IContainer}. - */ - swap(obj: IContainer): void; - } - interface IReverseIterator extends ReverseIterator, IReverseIterator> { - } -} -declare namespace std.base { - /** - *

An interface for deque

- * - *

- * - *

- * - * @author Jeongho Nam - */ - interface IDequeContainer extends ILinearContainer { - /** - *

Insert element at beginning.

- * - *

Inserts a new element at the beginning of the {@link IDeque container}, right before its - * current first element. This effectively increases the {@link IDeque container} {@link size} by - * one.

- * - * @param val Value to be inserted as an element. - */ - push_front(val: T): void; - /** - *

Delete first element.

- * - *

Removes the first element in the {@link IDeque container}, effectively reducing its - * {@link size} by one.

- */ - pop_front(): void; - } -} -declare namespace std.base { - /** - *

An interface for linear containers.

- * - *

- * - *

- * - * @author Jeonngho Nam - */ - interface ILinearContainer extends IContainer { - /** - * @inheritdoc - */ - assign>(begin: InputIterator, end: InputIterator): void; - /** - *

Assign container content.

- * - *

Assigns new contents to the {@link IList container}, replacing its current contents, - * and modifying its {@link size} accordingly.

- * - * @param n New size for the - * @param val Value to fill the container with. Each of the n elements in the container will - * be initialized to a copy of this value. - */ - assign(n: number, val: T): void; - /** - *

Access first element.

- *

Returns a value of the first element in the {@link IList container}.

- * - *

Unlike member {@link end end()}, which returns an iterator just past this element, - * this function returns a direct value.

- * - *

Calling this function on an {@link empty} {@link IList container} causes undefined behavior.

- * - * @return A value of the first element of the {@link IList container}. - */ - front(): T; - /** - *

Access last element.

- *

Returns a value of the last element in the {@link IList container}.

- * - *

Unlike member {@link end end()}, which returns an iterator just past this element, - * this function returns a direct value.

- * - *

Calling this function on an {@link empty} {@link IList container} causes undefined behavior.

- * - * @return A value of the last element of the {@link IList container}. - */ - back(): T; - /** - *

Add element at the end.

- * - *

Adds a new element at the end of the {@link IList container}, after its current last element. - * This effectively increases the {@link IList container} {@link size} by one.

- * - * @param val Value to be copied to the new element. - */ - push_back(val: T): void; - /** - *

Delete last element.

- * - *

Removes the last element in the {@link IList container}, effectively reducing the - * {@link IList container} {@link size} by one.

- */ - pop_back(): void; - /** - *

Insert an element.

- * - *

The {@link IList conatiner} is extended by inserting new element before the element at the - * specified position, effectively increasing the {@link IList container} {@link size} by - * one.

- * - * @param position Position in the {@link IList container} where the new elements are inserted. - * {@link iterator} is a member type, defined as a {@link iterator random access iterator} - * type that points to elements. - * @param val Value to be copied to the inserted element. - * - * @return An iterator that points to the newly inserted element. - */ - insert(position: Iterator, val: T): Iterator; - /** - *

Insert elements by range iterators.

- * - *

The {@link IList container} is extended by inserting new elements before the element at the - * specified position, effectively increasing the {@link IList container} {@link size} by - * the number of repeating elements n.

- * - * @param position Position in the {@link IList container} where the new elements are inserted. - * {@link iterator} is a member type, defined as a {@link iterator random access iterator} - * type that points to elements. - * @param n Number of elements to insert. Each element is initialized to a copy of val. - * @param val Value to be copied (or moved) to the inserted elements. - * - * @return An iterator that points to the first of the newly inserted elements. - */ - insert(position: Iterator, n: number, val: T): Iterator; - /** - *

Insert elements by range iterators.

- * - *

The {@link IList container} is extended by inserting new elements before the element at the - * specified position, effectively increasing the {@link IList container} {@link size} by - * the number of elements inserted by range iterators.

- * - * @param position Position in the {@link IList container} where the new elements are inserted. - * {@link iterator} is a member type, defined as a {@link iterator random access iterator} - * type that points to elements. - * @param begin Input interator of the initial position in a sequence. - * @param end Input interator of the final position in a sequence. - * - * @return An iterator that points to the first of the newly inserted elements. - */ - insert>(position: Iterator, begin: InputIterator, end: InputIterator): Iterator; - } - /** - * An interface for iterators from linear containers. - * - * {@link ILieanerIterator} is an bi-directional iterator which is created from the related - * {@link ILinearContainer linear containers}. Not only accessing to {@link value} of the pointed element from - * this {@link ILieanerIterator}, but also modifying the {@link value} is possible. - * - * @author Jeongho Nam - */ - interface ILinearIterator extends Iterator { - /** - * @inheritdoc - */ - value: T; - /** - * @inheritdoc - */ - prev(): ILinearIterator; - /** - * @inheritdoc - */ - next(): ILinearIterator; - } -} -declare namespace std { - /** - *

Bi-directional iterator.

- * - *

{@link Iterator Bidirectional iterators} are iterators that can be used to access the sequence of elements - * in a range in both directions (towards the end and towards the beginning).

- * - *

All {@link IArrayIterator random-access iterators} are also valid {@link Iterrator bidirectional iterators}. - *

- * - *

There is not a single type of {@link Iterator bidirectional iterator}: {@link IContainer Each container} - * may define its own specific iterator type able to iterate through it and access its elements.

- * - *

- * - *

- * - * @reference http://www.cplusplus.com/reference/iterator/BidirectionalIterator - * @author Jeongho Nam - */ - abstract class Iterator { - /** - * Source container of the iterator is directing for. - */ - protected source_: base.IContainer; - /** - * Construct from the source {@link IContainer container}. - * - * @param source The source container. - */ - protected constructor(source: base.IContainer); - /** - *

Get iterator to previous element.

- *

If current iterator is the first item(equal with {@link IContainer.begin IContainer.begin()}), - * returns {@link IContainer.end IContainer.end()}.

- * - * @return An iterator of the previous item. - */ - abstract prev(): Iterator; - /** - *

Get iterator to next element.

- *

If current iterator is the last item, returns {@link IContainer.end IContainer.end()}.

- * - * @return An iterator of the next item. - */ - abstract next(): Iterator; - /** - * Advances the {@link Iterator} by n element positions. - * - * @param n Number of element positions to advance. - * @return An advanced iterator. - */ - advance(n: number): Iterator; - /** - * Get source - */ - get_source(): base.IContainer; - /** - *

Whether an iterator is equal with the iterator.

- * - *

Compare two iterators and returns whether they are equal or not.

- * - *

Note

- *

Iterator's {@link equals equals()} only compare souce container and index number.

- * - *

Although elements in a pair, key and value are {@link std.equal_to equal_to}, if the source map or - * index number is different, then the {@link equals equals()} will return false. If you want to - * compare the elements of a pair, compare them directly by yourself.

- * - * @param obj An iterator to compare - * @return Indicates whether equal or not. - */ - equals(obj: Iterator): boolean; - /** - *

Get value of the iterator is pointing.

- * - * @return A value of the iterator. - */ - readonly abstract value: T; - abstract swap(obj: Iterator): void; - } -} -declare namespace std { - /** - *

This class reverses the direction in which a bidirectional or random-access iterator iterates through a range. - *

- * - *

A copy of the original iterator (the {@link Iterator base iterator}) is kept internally and used to reflect - * the operations performed on the {@link ReverseIterator}: whenever the {@link ReverseIterator} is incremented, its - * {@link Iterator base iterator} is decreased, and vice versa. A copy of the {@link Iterator base iterator} with the - * current state can be obtained at any time by calling member {@link base}.

- * - *

Notice however that when an iterator is reversed, the reversed version does not point to the same element in - * the range, but to the one preceding it. This is so, in order to arrange for the past-the-end element of a - * range: An iterator pointing to a past-the-end element in a range, when reversed, is pointing to the last element - * (not past it) of the range (this would be the first element of the reversed range). And if an iterator to the - * first element in a range is reversed, the reversed iterator points to the element before the first element (this - * would be the past-the-end element of the reversed range).

- * - *

- * - *

- * - * @reference http://www.cplusplus.com/reference/iterator/reverse_iterator - * @author Jeongho Nam - */ - abstract class ReverseIterator, This extends ReverseIterator> extends Iterator { - /** - * @hidden - */ - protected base_: Base; - /** - * Construct from base iterator. - * - * @param base A reference of the base iterator, which iterates in the opposite direction. - */ - protected constructor(base: Base); - /** - *

Return base iterator.

- * - *

Return a reference of the base iteraotr.

- * - *

The base iterator is an iterator of the same type as the one used to construct the {@link ReverseIterator}, - * but pointing to the element next to the one the {@link ReverseIterator} is currently pointing to - * (a {@link ReverseIterator} has always an offset of -1 with respect to its base iterator). - * - * @return A reference of the base iterator, which iterates in the opposite direction. - */ - base(): Base; - /** - * @hidden - */ - protected abstract _Create_neighbor(base: Base): This; - /** - *

Get value of the iterator is pointing.

- * - * @return A value of the reverse iterator. - */ - readonly value: T; - /** - * @inheritdoc - */ - prev(): This; - /** - * @inheritdoc - */ - next(): This; - /** - * @inheritdoc - */ - advance(n: number): This; - /** - * @inheritdoc - */ - equals(obj: This): boolean; - /** - * @inheritdoc - */ - swap(obj: This): void; - } - /** - *

Return distance between {@link Iterator iterators}.

- * - *

Calculates the number of elements between first and last.

- * - *

If it is a {@link IArrayIterator random-access iterator}, the function uses operator- to calculate this. - * Otherwise, the function uses the increase operator {@link Iterator.next next()} repeatedly.

- * - * @param first Iterator pointing to the initial element. - * @param last Iterator pointing to the final element. This must be reachable from first. - * - * @return The number of elements between first and last. - */ - function distance>(first: InputIterator, last: InputIterator): number; - /** - *

Advance iterator.

- * - *

Advances the iterator it by n elements positions.

- * - * @param it Iterator to be advanced. - * @param n Number of element positions to advance. - * - * @return An iterator to the element n positions before it. - */ - function advance>(it: InputIterator, n: number): InputIterator; - /** - *

Get iterator to previous element.

- * - *

Returns an iterator pointing to the element that it would be pointing to if advanced -n positions.

- * - * @param it Iterator to base position. - * @param n Number of element positions offset (1 by default). - * - * @return An iterator to the element n positions before it. - */ - function prev>(it: BidirectionalIterator, n?: number): BidirectionalIterator; - /** - *

Get iterator to next element.

- * - *

Returns an iterator pointing to the element that it would be pointing to if advanced n positions.

- * - * @param it Iterator to base position. - * @param n Number of element positions offset (1 by default). - * - * @return An iterator to the element n positions away from it. - */ - function next>(it: ForwardIterator, n?: number): ForwardIterator; - /** - *

Iterator to beginning.

- * - *

Returns an iterator pointing to the first element in the sequence.

- * - *

If the sequence is empty, the returned value shall not be dereferenced.

- * - * @param container A container object of a class type for which member {@link IContainer.begin begin} is defined. - * - * @return The same as returned by {@link IContainer.begin container.begin()}. - */ - function begin(container: Vector): VectorIterator; - /** - *

Iterator to beginning.

- * - *

Returns an iterator pointing to the first element in the sequence.

- * - *

If the sequence is empty, the returned value shall not be dereferenced.

- * - * @param container A container object of a class type for which member {@link IContainer.begin begin} is defined. - * - * @return The same as returned by {@link IContainer.begin container.begin()}. - */ - function begin(container: List): ListIterator; - /** - *

Iterator to beginning.

- * - *

Returns an iterator pointing to the first element in the sequence.

- * - *

If the sequence is empty, the returned value shall not be dereferenced.

- * - * @param container A container object of a class type for which member {@link IContainer.begin begin} is defined. - * - * @return The same as returned by {@link IContainer.begin container.begin()}. - */ - function begin(container: Deque): DequeIterator; - /** - *

Iterator to beginning.

- * - *

Returns an iterator pointing to the first element in the sequence.

- * - *

If the sequence is empty, the returned value shall not be dereferenced.

- * - * @param container A container object of a class type for which member {@link IContainer.begin begin} is defined. - * - * @return The same as returned by {@link IContainer.begin container.begin()}. - */ - function begin(container: base.SetContainer): SetIterator; - /** - *

Iterator to beginning.

- * - *

Returns an iterator pointing to the first element in the sequence.

- * - *

If the sequence is empty, the returned value shall not be dereferenced.

- * - * @param container A container object of a class type for which member {@link IContainer.begin begin} is defined. - * - * @return The same as returned by {@link IContainer.begin container.begin()}. - */ - function begin(container: base.MapContainer): MapIterator; - /** - *

Iterator to end.

- * - *

Returns an iterator pointing to the past-the-end element in the sequence.

- * - *

If the sequence is {@link IContainer.empty empty}, the returned value compares equal to the one returned by {@link begin} with the same argument.

- * - * @param container A container of a class type for which member {@link IContainer.end end} is defined. - * - * @return The same as returned by {@link IContainer.end container.end()}. - */ - function end(container: Vector): VectorIterator; - /** - *

Iterator to end.

- * - *

Returns an iterator pointing to the past-the-end element in the sequence.

- * - *

If the sequence is {@link IContainer.empty empty}, the returned value compares equal to the one returned by {@link begin} with the same argument.

- * - * @param container A container of a class type for which member {@link IContainer.end end} is defined. - * - * @return The same as returned by {@link IContainer.end container.end()}. - */ - function end(container: List): ListIterator; - /** - *

Iterator to end.

- * - *

Returns an iterator pointing to the past-the-end element in the sequence.

- * - *

If the sequence is {@link IContainer.empty empty}, the returned value compares equal to the one returned by {@link begin} with the same argument.

- * - * @param container A container of a class type for which member {@link IContainer.end end} is defined. - * - * @return The same as returned by {@link IContainer.end container.end()}. - */ - function end(container: Deque): DequeIterator; - /** - *

Iterator to end.

- * - *

Returns an iterator pointing to the past-the-end element in the sequence.

- * - *

If the sequence is {@link IContainer.empty empty}, the returned value compares equal to the one returned by {@link begin} with the same argument.

- * - * @param container A container of a class type for which member {@link IContainer.end end} is defined. - * - * @return The same as returned by {@link IContainer.end container.end()}. - */ - function end(container: base.SetContainer): SetIterator; - /** - *

Iterator to end.

- * - *

Returns an iterator pointing to the past-the-end element in the sequence.

- * - *

If the sequence is {@link IContainer.empty empty}, the returned value compares equal to the one returned by {@link begin} with the same argument.

- * - * @param container A container of a class type for which member {@link IContainer.end end} is defined. - * - * @return The same as returned by {@link IContainer.end container.end()}. - */ - function end(container: base.MapContainer): MapIterator; -} -declare namespace std.base { - /** - * An abstract list. - * - *

{@link ListContainer}s are sequence containers that allow constant time insert and erase operations anywhere - * within the sequence, and iteration in both directions.

- * - *

List containers are implemented as doubly-linked lists; Doubly linked lists can store each of the elements they - * contain in different and unrelated storage locations. The ordering is kept internally by the association to each - * element of a link to the element preceding it and a link to the element following it.

- * - *

Compared to other base standard sequence containers (array, vector and deque), lists perform generally better - * in inserting, extracting and moving elements in any position within the container for which an iterator has already - * been obtained, and therefore also in algorithms that make intensive use of these, like sorting algorithms.

- * - *

The main drawback of lists and forward_lists compared to these other sequence containers is that they lack - * direct access to the elements by their position; For example, to access the sixth element in a list, one has to - * iterate from a known position (like the beginning or the end) to that position, which takes linear time in the - * distance between these. They also consume some extra memory to keep the linking information associated to each - * element (which may be an important factor for large lists of small-sized elements).

- * - *

Container properties

- *
- *
Sequence
- *
Elements in sequence containers are ordered in a strict linear sequence. Individual elements are accessed by - * their position in this sequence.
- * - *
Doubly-linked list
- *
Each element keeps information on how to locate the next and the previous elements, allowing constant time - * insert and erase operations before or after a specific element (even of entire ranges), but no direct random - * access.
- *
- * - * @param Type of the elements. - * - * @reference http://www.cplusplus.com/reference/list/list/ - * - * @author Jeongho Nam - */ - abstract class ListContainer> extends Container implements IDequeContainer { - /** - * @hidden - */ - private begin_; - /** - * @hidden - */ - private end_; - /** - * @hidden - */ - private size_; - /** - * Default Constructor. - */ - protected constructor(); - /** - * @hidden - */ - protected abstract _Create_iterator(prev: BidirectionalIterator, next: BidirectionalIterator, val: T): BidirectionalIterator; - /** - * @hidden - */ - protected _Set_begin(it: BidirectionalIterator): void; - /** - * @inheritdoc - */ - assign>(first: InputIterator, last: InputIterator): void; - /** - * @inheritdoc - */ - clear(): void; - /** - * @inheritdoc - */ - begin(): BidirectionalIterator; - /** - * @inheritdoc - */ - end(): BidirectionalIterator; - /** - * @inheritdoc - */ - size(): number; - /** - * @inheritdoc - */ - front(): T; - /** - * @inheritdoc - */ - back(): T; - /** - * @inheritdoc - */ - push_front(val: T): void; - /** - * @inheritdoc - */ - push_back(val: T): void; - /** - * @inheritdoc - */ - pop_front(): void; - /** - * @inheritdoc - */ - pop_back(): void; - /** - * @inheritdoc - */ - push(...items: T[]): number; - /** - *

Insert an element.

- * - *

The container is extended by inserting a new element before the element at the specified - * position. This effectively increases the {@link List.size List size} by the amount of elements - * inserted.

- * - *

Unlike other standard sequence containers, {@link List} is specifically designed to be efficient - * inserting and removing elements in any position, even in the middle of the sequence.

- * - * @param position Position in the container where the new element is inserted. - * {@link iterator}> is a member type, defined as a - * {@link ListIterator bidirectional iterator} type that points to elements. - * @param val Value to be inserted as an element. - * - * @return An iterator that points to the newly inserted element; val. - */ - insert(position: BidirectionalIterator, val: T): BidirectionalIterator; - /** - *

Insert elements by repeated filling.

- * - *

The container is extended by inserting a new element before the element at the specified - * position. This effectively increases the {@link List.size List size} by the amount of elements - * inserted.

- * - *

Unlike other standard sequence containers, {@link List} is specifically designed to be efficient - * inserting and removing elements in any position, even in the middle of the sequence.

- * - * @param position Position in the container where the new elements are inserted. The {@link iterator} is a - * member type, defined as a {@link ListIterator bidirectional iterator} type that points to - * elements. - * @param size Number of elements to insert. - * @param val Value to be inserted as an element. - * - * @return An iterator that points to the first of the newly inserted elements. - */ - insert(position: BidirectionalIterator, size: number, val: T): BidirectionalIterator; - /** - *

Insert elements by range iterators.

- * - *

The container is extended by inserting a new element before the element at the specified - * position. This effectively increases the {@link List.size List size} by the amount of elements - * inserted.

- * - *

Unlike other standard sequence containers, {@link List} is specifically designed to be efficient - * inserting and removing elements in any position, even in the middle of the sequence.

- * - * @param position Position in the container where the new elements are inserted. The {@link iterator} is a - * member type, defined as a {@link ListIterator bidirectional iterator} type that points to - * elements. - * @param begin An iterator specifying range of the begining element. - * @param end An iterator specifying range of the ending element. - * - * @return An iterator that points to the first of the newly inserted elements. - */ - insert>(position: BidirectionalIterator, begin: InputIterator, end: InputIterator): BidirectionalIterator; - /** - * @hidden - */ - private insert_by_val(position, val); - /** - * @hidden - */ - protected _Insert_by_repeating_val(position: BidirectionalIterator, size: number, val: T): BidirectionalIterator; - /** - * @hidden - */ - protected _Insert_by_range>(position: BidirectionalIterator, begin: InputIterator, end: InputIterator): BidirectionalIterator; - /** - *

Erase an element.

- * - *

Removes from the {@link List} either a single element; position.

- * - *

This effectively reduces the container size by the number of element removed.

- * - *

Unlike other standard sequence containers, {@link List} objects are specifically designed to be - * efficient inserting and removing elements in any position, even in the middle of the sequence.

- * - * @param position Iterator pointing to a single element to be removed from the {@link List}. - * - * @return An iterator pointing to the element that followed the last element erased by the function call. - * This is the {@link end end()} if the operation erased the last element in the sequence. - */ - erase(position: BidirectionalIterator): BidirectionalIterator; - /** - *

Erase elements.

- * - *

Removes from the {@link List} container a range of elements.

- * - *

This effectively reduces the container {@link size} by the number of elements removed.

- * - *

Unlike other standard sequence containers, {@link List} objects are specifically designed to be - * efficient inserting and removing elements in any position, even in the middle of the sequence.

- * - * @param begin An iterator specifying a range of beginning to erase. - * @param end An iterator specifying a range of end to erase. - * - * @return An iterator pointing to the element that followed the last element erased by the function call. - * This is the {@link end end()} if the operation erased the last element in the sequence. - */ - erase(begin: BidirectionalIterator, end: BidirectionalIterator): BidirectionalIterator; - /** - * @hidden - */ - protected _Erase_by_range(first: BidirectionalIterator, last: BidirectionalIterator): BidirectionalIterator; - /** - *

Swap content.

- * - *

Exchanges the content of the container by the content of obj, which is another - * {@link List container} object with same type of elements. Sizes and container type may differ.

- * - *

After the call to this member function, the elements in this container are those which were in obj - * before the call, and the elements of obj are those which were in this. All iterators, references and - * pointers remain valid for the swapped objects.

- * - *

Notice that a non-member function exists with the same name, {@link std.swap swap}, overloading that - * algorithm with an optimization that behaves like this member function.

- * - * @param obj Another {@link List container} of the same type of elements (i.e., instantiated - * with the same template parameter, T) whose content is swapped with that of this - * {@link container List}. - */ - swap(obj: ListContainer): void; - /** - * @inheritdoc - */ - swap(obj: base.IContainer): void; - } -} -declare namespace std.base { - /** - * An iterator, node of a List-based container. - * - * - * - * - * - * @author Jeongho Nam - */ - abstract class ListIteratorBase extends Iterator { - /** - * @hidden - */ - private prev_; - /** - * @hidden - */ - private next_; - /** - * @hidden - */ - protected value_: T; - /** - * Initializer Constructor. - * - * @param source The source {@link Container} to reference. - * @param prev A refenrece of previous node ({@link ListIterator iterator}). - * @param next A refenrece of next node ({@link ListIterator iterator}). - * @param value Value to be stored in the node (iterator). - */ - protected constructor(source: Container, prev: ListIteratorBase, next: ListIteratorBase, value: T); - /** - * @inheritdoc - */ - prev(): ListIteratorBase; - /** - * @inheritdoc - */ - next(): ListIteratorBase; - /** - * @inheritdoc - */ - advance(step: number): ListIteratorBase; - /** - * @inheritdoc - */ - readonly value: T; - /** - * @inheritdoc - */ - equals(obj: ListIteratorBase): boolean; - /** - * @inheritdoc - */ - swap(obj: ListIteratorBase): void; - } -} -declare namespace std.base { - /** - *

An abstract map.

- * - *

{@link MapContainer MapContainers} are associative containers that store elements formed by a combination - * of a key value (Key) and a mapped value (T), and which allows for fast retrieval - * of individual elements based on their keys.

- * - *

In a {@link MapContainer}, the key values are generally used to identify the elements, while the - * mapped values store the content associated to this key. The types of key and - * mapped value may differ, and are grouped together in member type value_type, which is a - * {@link Pair} type combining both:

- * - *

typedef pair value_type;

- * - *

{@link MapContainer} stores elements, keeps sequence and enables indexing by inserting elements into a - * {@link List} and registering {@link ListIterator iterators} of the {@link data_ list container} to an index - * table like {@link RBTree tree} or {@link HashBuckets hash-table}.

- * - *

- *

- * - *

Container properties

- *
- *
Associative
- *
- * Elements in associative containers are referenced by their key and not by their absolute position - * in the container. - *
- * - *
Map
- *
- * Each element associates a key to a mapped value: - * Keys are meant to identify the elements whose main content is the mapped value. - *
- *
- * - * @param Type of the keys. Each element in a map is identified by its key value. - * @param Type of the mapped value. Each element in a map stores some data as its mapped value. - * - * @author Jeongho Nam - */ - abstract class MapContainer extends Container> { - /** - *

{@link List} storing elements.

- * - *

Storing elements and keeping those sequence of the {@link MapContainer} are implemented by - * {@link data_ this list container}. Implementing index-table is also related with {@link data_ this list} - * by storing {@link ListIterator iterators} ({@link MapIterator} references {@link ListIterator}) who are - * created from {@link data_ here}.

- */ - private data_; - /** - * Default Constructor. - */ - protected constructor(); - /** - * @inheritdoc - */ - assign>>(first: InputIterator, last: InputIterator): void; - /** - * @inheritdoc - */ - clear(): void; - /** - *

Get iterator to element.

- * - *

Searches the container for an element with a identifier equivalent to key and returns an - * iterator to it if found, otherwise it returns an iterator to {@link end end()}.

- * - *

Two keys are considered equivalent if the container's comparison object returns false reflexively - * (i.e., no matter the order in which the elements are passed as arguments).

- * - *

Another member functions, {@link has has()} and {@link count count()}, can be used to just check - * whether a particular key exists.

- * - * @param key Key to be searched for - * @return An iterator to the element, if an element with specified key is found, or - * {@link end end()} otherwise. - */ - abstract find(key: Key): MapIterator; - /** - *

Return iterator to beginning.

- * - *

Returns an iterator referring the first element in the

- * - *

Note

- *

If the container is {@link empty}, the returned iterator is same with {@link end end()}.

- * - * @return An iterator to the first element in the The iterator containes the first element's value. - */ - begin(): MapIterator; - /** - *

Return iterator to end.

- *

Returns an iterator referring to the past-the-end element in the

- * - *

The past-the-end element is the theoretical element that would follow the last element in the - * It does not point to any element, and thus shall not be dereferenced.

- * - *

Because the ranges used by functions of the container do not include the element reference by their - * closing iterator, this function is often used in combination with {@link MapContainer}.{@link begin} to - * specify a range including all the elements in the

- * - *

Note

- *

Returned iterator from {@link MapContainer}.{@link end} does not refer any element. Trying to accessing - * element by the iterator will cause throwing exception ({@link OutOfRange}).

- * - *

If the container is {@link empty}, this function returns the same as {@link begin}.

- * - * @return An iterator to the end element in the - */ - end(): MapIterator; - /** - *

Return {@link MapReverseIterator reverse iterator} to reverse beginning.

- * - *

Returns a {@link MapReverseIterator reverse iterator} pointing to the last element in the container - * (i.e., its reverse beginning).

- * - * {@link MapReverseIterator Reverse iterators} iterate backwards: increasing them moves them towards the - * beginning of the container.

- * - *

{@link rbegin} points to the element preceding the one that would be pointed to by member {@link end}. - *

7 - * - * @return A {@link MapReverseIterator reverse iterator} to the reverse beginning of the sequence - * - */ - rbegin(): MapReverseIterator; - /** - *

Return {@link MapReverseIterator reverse iterator} to reverse end.

- * - *

Returns a {@link MapReverseIterator reverse iterator} pointing to the theoretical element right before - * the first element in the {@link MapContainer map container} (which is considered its reverse end). - *

- * - *

The range between {@link MapContainer}.{@link rbegin} and {@link MapContainer}.{@link rend} contains - * all the elements of the container (in reverse order).

- * - * @return A {@link MapReverseIterator reverse iterator} to the reverse end of the sequence - */ - rend(): MapReverseIterator; - /** - *

Whether have the item or not.

- * - *

Indicates whether a map has an item having the specified identifier.

- * - * @param key Key value of the element whose mapped value is accessed. - * - * @return Whether the map has an item having the specified identifier. - */ - has(key: Key): boolean; - /** - *

Count elements with a specific key.

- * - *

Searches the container for elements whose key is key and returns the number of elements found.

- * - * @param key Key value to be searched for. - * - * @return The number of elements in the container with a key. - */ - abstract count(key: Key): number; - /** - * Return the number of elements in the map. - */ - size(): number; - /** - * @inheritdoc - */ - push(...args: Pair[]): number; - /** - * @inheritdoc - */ - push(...args: [Key, T][]): number; - /** - * Construct and insert element with hint - * - * Inserts a new element in the {@link MapContainer map container}. This new element is constructed in - * place using *args* as the arguments for the element's constructor. *hint* points to a location in the - * container suggested as a hint on where to start the search for its insertion point (the container may or - * may not use this suggestion to optimize the insertion operation). - * - * A similar member function exists, {@link insert}, which either copies or moves an existing object into - * the container, and may also take a position *hint*. - * - * @param hint Hint for the position where the element can be inserted. - * @param key The key used both to look up and to insert if not found. - * @param value Value, the item. - * - * @return An iterator pointing to either the newly inserted element or to the element that already had an - * equivalent key in the {@link MapContainer}. - */ - emplace_hint(hint: MapIterator, key: Key, val: T): MapIterator; - /** - * Construct and insert element with hint - * - * Inserts a new element in the {@link MapContainer map container}. This new element is constructed in - * place using *args* as the arguments for the element's constructor. *hint* points to a location in the - * container suggested as a hint on where to start the search for its insertion point (the container may or - * may not use this suggestion to optimize the insertion operation). - * - * A similar member function exists, {@link insert}, which either copies or moves an existing object into - * the container, and may also take a position *hint*. - * - * @param hint Hint for the position where the element can be inserted. - * @param key The key used both to look up and to insert if not found. - * @param value Value, the item. - * - * @return An {@link MapIterator iterator} pointing to either the newly inserted element or to the element - * that already had an equivalent key in the {@link MapContainer}. - */ - emplace_hint(hint: MapReverseIterator, key: Key, val: T): MapReverseIterator; - /** - * Construct and insert element with hint - * - * Inserts a new element in the {@link MapContainer map container}. This new element is constructed in - * place using *args* as the arguments for the element's constructor. *hint* points to a location in the - * container suggested as a hint on where to start the search for its insertion point (the container may or - * may not use this suggestion to optimize the insertion operation). - * - * A similar member function exists, {@link insert}, which either copies or moves an existing object into - * the container, and may also take a position *hint*. - * - * @param hint Hint for the position where the element can be inserted. - * @param pair A single argument of a {@link Pair} type with a value for the *key* as - * {@link Pair.first first} member, and a *value* for the mapped value as - * {@link Pair.second second}. - * - * @return An iterator pointing to either the newly inserted element or to the element that already had an - * equivalent key in the {@link MapContainer}. - */ - emplace_hint(hint: MapIterator, pair: Pair): MapIterator; - /** - * Construct and insert element with hint - * - * Inserts a new element in the {@link MapContainer map container}. This new element is constructed in - * place using *args* as the arguments for the element's constructor. *hint* points to a location in the - * container suggested as a hint on where to start the search for its insertion point (the container may or - * may not use this suggestion to optimize the insertion operation). - * - * A similar member function exists, {@link insert}, which either copies or moves an existing object into - * the container, and may also take a position *hint*. - * - * @param hint Hint for the position where the element can be inserted. - * @param pair A single argument of a {@link Pair} type with a value for the *key* as - * {@link Pair.first first} member, and a *value* for the mapped value as - * {@link Pair.second second}. - * - * @return An {@link MapIterator iterator} pointing to either the newly inserted element or to the element - * that already had an equivalent key in the {@link MapContainer}. - */ - emplace_hint(hint: MapReverseIterator, pair: Pair): MapReverseIterator; - /** - *

Insert an element.

- * - *

Extends the container by inserting a new element, effectively increasing the container {@link size} - * by the number of element inserted (zero or one).

- * - * @param hint Hint for the position where the element can be inserted. - * @param pair A single argument of a {@link Pair} type with a value for the *key* as - * {@link Pair.first first} member, and a *value* for the mapped value as - * {@link Pair.second second}. - * - * @return An iterator pointing to either the newly inserted element or to the element that already had an - * equivalent key in the {@link MapContainer}. - */ - insert(hint: MapIterator, pair: Pair): MapIterator; - /** - *

Insert an element.

- * - *

Extends the container by inserting a new element, effectively increasing the container {@link size} - * by the number of element inserted (zero or one).

- * - * @param hint Hint for the position where the element can be inserted. - * @param pair A single argument of a {@link Pair} type with a value for the *key* as - * {@link Pair.first first} member, and a *value* for the mapped value as - * {@link Pair.second second}. - * - * @return An iterator pointing to either the newly inserted element or to the element that already had an - * equivalent key in the {@link MapContainer}. - */ - insert(hint: MapReverseIterator, pair: Pair): MapReverseIterator; - /** - *

Insert an element.

- * - *

Extends the container by inserting new elements, effectively increasing the container {@link size} - * by the number of elements inserted.

- * - * @param hint Hint for the position where the element can be inserted. - * @param tuple Tuple represensts the {@link Pair} to be inserted as an element. - * - * @return An iterator pointing to either the newly inserted element or to the element that already had an - * equivalent key in the {@link MapContainer}. - */ - insert(hint: MapIterator, tuple: [L, U]): MapIterator; - /** - *

Insert an element.

- * - *

Extends the container by inserting new elements, effectively increasing the container {@link size} - * by the number of elements inserted.

- * - * @param hint Hint for the position where the element can be inserted. - * @param tuple Tuple represensts the {@link Pair} to be inserted as an element. - * - * @return An iterator pointing to either the newly inserted element or to the element that already had an - * equivalent key in the {@link MapContainer}. - */ - insert(hint: MapReverseIterator, tuple: [L, U]): MapReverseIterator; - /** - *

Insert elements from range iterators.

- * - *

Extends the container by inserting new elements, effectively increasing the container {@link size} by - * the number of elements inserted.

- * - * @param begin Input iterator specifying initial position of a range of elements. - * @param end Input iterator specifying final position of a range of elements. - * Notice that the range includes all the elements between begin and end, - * including the element pointed by begin but not the one pointed by end. - */ - insert>>(first: InputIterator, last: InputIterator): void; - /** - * @hidden - */ - protected abstract _Insert_by_pair(pair: Pair): any; - /** - * @hidden - */ - private insert_by_tuple(tuple); - /** - * @hidden - */ - protected abstract _Insert_by_hint(hint: MapIterator, pair: Pair): MapIterator; - /** - * @hidden - */ - private insert_by_hint_with_tuple(hint, tuple); - /** - * @hidden - */ - protected abstract _Insert_by_range>>(first: InputIterator, last: InputIterator): void; - /** - *

Erase an elemet by key.

- * - *

Removes from the {@link MapContainer map container} a single element.

- * - *

This effectively reduces the container {@link size} by the number of element removed (zero or one), - * which are destroyed.

- * - * @param key Key of the element to be removed from the {@link MapContainer}. - */ - erase(key: Key): number; - /** - *

Erase an elemet by iterator.

- * - *

Removes from the {@link MapContainer map container} a single element.

- * - *

This effectively reduces the container {@link size} by the number of element removed (zero or one), - * which are destroyed.

- * - * @param it Iterator specifying position winthin the {@link MapContainer map contaier} to be removed. - */ - erase(it: MapIterator): MapIterator; - /** - *

Erase elements by range iterators.

- * - *

Removes from the {@link MapContainer map container} a range of elements.

- * - *

This effectively reduces the container {@link size} by the number of elements removed, which are - * destroyed.

- * - * @param begin An iterator specifying initial position of a range within {@link MApContainer map container} - * to be removed. - * @param end An iterator specifying initial position of a range within {@link MApContainer map container} - * to be removed. - * Notice that the range includes all the elements between begin and end, - * including the element pointed by begin but not the one pointed by end. - */ - erase(begin: MapIterator, end: MapIterator): MapIterator; - /** - *

Erase an elemet by iterator.

- * - *

Removes from the {@link MapContainer map container} a single element.

- * - *

This effectively reduces the container {@link size} by the number of element removed (zero or one), - * which are destroyed.

- * - * @param it Iterator specifying position winthin the {@link MapContainer map contaier} to be removed. - */ - erase(it: MapReverseIterator): MapReverseIterator; - /** - *

Erase elements by range iterators.

- * - *

Removes from the {@link MapContainer map container} a range of elements.

- * - *

This effectively reduces the container {@link size} by the number of elements removed, which are - * destroyed.

- * - * @param begin An iterator specifying initial position of a range within {@link MApContainer map container} - * to be removed. - * @param end An iterator specifying initial position of a range within {@link MApContainer map container} - * to be removed. - * Notice that the range includes all the elements between begin and end, - * including the element pointed by begin but not the one pointed by end. - */ - erase(begin: MapReverseIterator, end: MapReverseIterator): MapReverseIterator; - /** - * @hidden - */ - private erase_by_key(key); - /** - * @hidden - */ - private erase_by_iterator(first, last?); - /** - * @hidden - */ - private erase_by_range(first, last); - /** - * @hidden - */ - protected _Swap(obj: MapContainer): void; - /** - * Merge two maps. - * - * Extracts and transfers elements from *source* to this container. - * - * @param source A {@link MapContainer map container} to transfer the elements from. - */ - abstract merge(source: MapContainer): void; - /** - *

Abstract method handling insertions for indexing.

- * - *

This method, {@link _Handle_insert} is designed to register the first to last to somewhere storing - * those {@link MapIterator iterators} for indexing, fast accessment and retrievalance.

- * - *

When {@link insert} is called, new elements will be inserted into the {@link data_ list container} and new - * {@link MapIterator iterators} first to last, pointing the inserted elements, will be created and the - * newly created iterators first to last will be shifted into this method {@link _Handle_insert} after the - * insertions.

- * - *

If the derived one is {@link RBTree tree-based} like {@link TreeSet}, the {@link MapIterator iterators} - * will be registered into the {@link TreeSet.tree_ tree} as a {@link XTreeNode tree node item}. Else if the - * derived one is {@link HashBuckets hash-based} like {@link HashSet}, the first to last will be - * registered into the {@link HashSet.hash_buckets_ hash bucket}.

- * - * @param first An {@link MapIterator} to the initial position in a sequence. - * @param last An {@link MapIterator} to the final position in a sequence. The range used is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - */ - protected abstract _Handle_insert(first: MapIterator, last: MapIterator): void; - /** - *

Abstract method handling deletions for indexing.

- * - *

This method, {@link _Handle_erase} is designed to unregister the first to last to somewhere storing - * those {@link MapIterator iterators} for indexing, fast accessment and retrievalance.

- * - *

When {@link erase} is called with first to last, {@link MapIterator iterators} positioning somewhere - * place to be deleted, is memorized and shifted to this method {@link _Handle_erase} after the deletion process is - * terminated.

- * - *

If the derived one is {@link RBTree tree-based} like {@link TreeSet}, the {@link MapIterator iterators} - * will be unregistered from the {@link TreeSet.tree_ tree} as a {@link XTreeNode tree node item}. Else if the - * derived one is {@link HashBuckets hash-based} like {@link HashSet}, the first to last will be - * unregistered from the {@link HashSet.hash_buckets_ hash bucket}.

- * - * @param first An {@link MapIterator} to the initial position in a sequence. - * @param last An {@link MapIterator} to the final position in a sequence. The range used is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - */ - protected abstract _Handle_erase(first: MapIterator, last: MapIterator): void; - } - /** - * @hidden - */ - class MapElementList extends ListContainer, MapIterator> { - private associative_; - private rend_; - constructor(associative: MapContainer); - protected _Create_iterator(prev: MapIterator, next: MapIterator, val: Pair): MapIterator; - protected _Set_begin(it: MapIterator): void; - get_associative(): MapContainer; - rbegin(): MapReverseIterator; - rend(): MapReverseIterator; - } -} -declare namespace std { - /** - *

An iterator of {@link MapContainer map container}.

- * - *

- *

- * - * @author Jeongho Nam - */ - class MapIterator extends base.ListIteratorBase> implements IComparable> { - /** - * Construct from the {@link MapContainer source map} and {@link ListIterator list iterator}. - * - * @param source The source {@link MapContainer}. - * @param list_iterator A {@link ListIterator} pointing {@link Pair} of key and value. - */ - constructor(source: base.MapElementList, prev: MapIterator, next: MapIterator, val: Pair); - /** - * Get iterator to previous element. - */ - prev(): MapIterator; - /** - * Get iterator to next element. - */ - next(): MapIterator; - /** - * Advances the Iterator by n element positions. - * - * @param step Number of element positions to advance. - * @return An advanced Iterator. - */ - advance(step: number): MapIterator; - /** - * @hidden - */ - get_source(): base.MapContainer; - /** - * Get first, key element. - */ - readonly first: Key; - /** - * Get second, value element. - */ - /** - * Set second value. - */ - second: T; - /** - * @inheritdoc - */ - less(obj: MapIterator): boolean; - /** - * @inheritdoc - */ - equals(obj: MapIterator): boolean; - /** - * @inheritdoc - */ - hashCode(): number; - /** - * @inheritdoc - */ - swap(obj: MapIterator): void; - } - /** - *

A reverse-iterator of {@link MapContainer map container}.

- * - *

- *

- * - * @author Jeongho Nam - */ - class MapReverseIterator extends ReverseIterator, MapIterator, MapReverseIterator> { - /** - * Construct from base iterator. - * - * @param base A reference of the base iterator, which iterates in the opposite direction. - */ - constructor(base: MapIterator); - /** - * @hidden - */ - protected _Create_neighbor(base: MapIterator): MapReverseIterator; - /** - * Get first, key element. - */ - readonly first: Key; - /** - * Get second, value element. - */ - /** - * Set second value. - */ - second: T; - } -} -declare namespace std.base { - /** - *

An abstract multi-map.

- * - *

{@link MultiMap MultiMaps} are associative containers that store elements formed by a combination of a - * key value (Key) and a mapped value (T), and which allows for fast retrieval of - * individual elements based on their keys.

- * - *

In a {@link MapContainer}, the key values are generally used to identify the elements, while the - * mapped values store the content associated to this key. The types of key and - * mapped value may differ, and are grouped together in member type value_type, which is a - * {@link Pair} type combining both:

- * - *

typedef pair value_type;

- * - *

{@link UniqueMap} stores elements, keeps sequence and enables indexing by inserting elements into a - * {@link List} and registering {@link ListIterator iterators} of the {@link data_ list container} to an index - * table like {@link RBTree tree} or {@link HashBuckets hash-table}.

- * - *

- *

- * - *

Container properties

- *
- *
Associative
- *
- * Elements in associative containers are referenced by their key and not by their absolute position - * in the container. - *
- * - *
Map
- *
- * Each element associates a key to a mapped value: - * Keys are meant to identify the elements whose main content is the mapped value. - *
- * - *
Multiple equivalent keys
- *
Multiple elements in the container can have equivalent keys.
- *
- * - * @param Type of the keys. Each element in a map is identified by its key value. - * @param Type of the mapped value. Each element in a map stores some data as its mapped value. - * - * @author Jeongho Nam - */ - abstract class MultiMap extends MapContainer { - /** - * Construct and insert element. - * - * Inserts a new element in the {@link MultiMap}. This new element is constructed in place using args - * as the arguments for the element's constructor. - * - * This effectively increases the container {@link size} by one. - * - * A similar member function exists, {@link insert}, which either copies or moves existing objects into the - * container. - * - * @param key The key used both to look up and to insert if not found. - * @param value Value, the item. - * - * @return An {@link MapIterator iterator} to the newly inserted element. - */ - emplace(key: Key, value: T): MapIterator; - /** - * Construct and insert element. - * - * Inserts a new element in the {@link MultiMap}. This new element is constructed in place using args - * as the arguments for the element's constructor. - * - * This effectively increases the container {@link size} by one. - * - * A similar member function exists, {@link insert}, which either copies or moves existing objects into the - * container. - * - * @param pair A single argument of a {@link Pair} type with a value for the *key* as - * {@link Pair.first first} member, and a *value* for the mapped value as - * {@link Pair.second second}. - * @return An {@link MapIterator iterator} to the newly inserted element. - */ - emplace(pair: Pair): MapIterator; - /** - *

Insert elements.

- * - *

Extends the container by inserting new elements, effectively increasing the container {@link size} by - * the number of elements inserted.

- * - * @param pair A single argument of a {@link Pair} type with a value for the *key* as - * {@link Pair.first first} member, and a *value* for the mapped value as - * {@link Pair.second second}. - * - * @return An iterator pointing to the newly inserted element. - */ - insert(pair: Pair): MapIterator; - /** - *

Insert elements.

- * - *

Extends the container by inserting new elements, effectively increasing the container {@link size} by - * the number of elements inserted.

- * - * @param tuple Tuple represensts the {@link Pair} to be inserted as an element. - * - * @return An iterator pointing to the newly inserted element. - */ - insert(tuple: [L, U]): MapIterator; - /** - * @inheritdoc - */ - insert(hint: MapIterator, pair: Pair): MapIterator; - /** - * @inheritdoc - */ - insert(hint: MapReverseIterator, pair: Pair): MapReverseIterator; - /** - * @inheritdoc - */ - insert(hint: MapIterator, tuple: [L, U]): MapIterator; - /** - * @inheritdoc - */ - insert(hint: MapReverseIterator, tuple: [L, U]): MapReverseIterator; - /** - * @inheritdoc - */ - insert>>(first: InputIterator, last: InputIterator): void; - /** - * @inheritdoc - */ - merge(source: MapContainer): void; - } -} -declare namespace std.base { - /** - *

An abstract set.

- * - *

{@link SetContainer SetContainers} are containers that store elements allowing fast retrieval of - * individual elements based on their value.

- * - *

In an {@link SetContainer}, the value of an element is at the same time its key, used to - * identify it. Keys are immutable, therefore, the elements in an {@link SetContainer} cannot be - * modified once in the container - they can be inserted and removed, though.

- * - *

{@link SetContainer} stores elements, keeps sequence and enables indexing by inserting elements into a - * {@link List} and registering {@link ListIterator iterators} of the {@link data_ list container} to an index - * table like {@link RBTree tree} or {@link HashBuckets hash-table}.

- * - *

- *

- * - *

Container properties

- *
- *
Associative
- *
- * Elements in associative containers are referenced by their key and not by their absolute - * position in the container. - *
- * - *
Set
- *
The value of an element is also the key used to identify it.
- *
- * - * @param Type of the elements. Each element in a {@link SetContainer} container is also identified - * by this value (each value is itself also the element's key). - * - * @author Jeongho Nam - */ - abstract class SetContainer extends Container { - /** - *

{@link List} storing elements.

- * - *

Storing elements and keeping those sequence of the {@link SetContainer} are implemented by - * {@link data_ this list container}. Implementing index-table is also related with {@link data_ this list} - * by storing {@link ListIterator iterators} ({@link SetIterator} references {@link ListIterator}) who are - * created from {@link data_ here}.

- */ - private data_; - /** - * Default Constructor. - */ - protected constructor(); - /** - * @inheritdoc - */ - assign>(begin: Iterator, end: Iterator): void; - /** - * @inheritdoc - */ - clear(): void; - /** - *

Get iterator to element.

- * - *

Searches the container for an element with key as value and returns an iterator to it if found, - * otherwise it returns an iterator to {@link end end()} (the element past the end of the container).

- * - *

Another member function, {@link count count()}, can be used to just check whether a particular element - * exists.

- * - * @param key Key to be searched for. - * - * @return An iterator to the element, if the specified value is found, or {@link end end()} if it is not - * found in the - */ - abstract find(val: T): SetIterator; - /** - * @inheritdoc - */ - begin(): SetIterator; - /** - * @inheritdoc - */ - end(): SetIterator; - /** - * @inheritdoc - */ - rbegin(): SetReverseIterator; - /** - * @inheritdoc - */ - rend(): SetReverseIterator; - /** - *

Whether have the item or not.

- * - *

Indicates whether a set has an item having the specified identifier.

- * - * @param key Key value of the element whose mapped value is accessed. - * - * @return Whether the set has an item having the specified identifier. - */ - has(val: T): boolean; - /** - *

Count elements with a specific key.

- * - *

Searches the container for elements with a value of k and returns the number of elements found.

- * - * @param key Value of the elements to be counted. - * - * @return The number of elements in the container with a key. - */ - abstract count(val: T): number; - /** - * @inheritdoc - */ - size(): number; - /** - * @inheritdoc - */ - push(...args: T[]): number; - /** - *

Insert an element with hint.

- * - *

Extends the container by inserting new elements, effectively increasing the container size by the - * number of elements inserted.

- * - * @param hint Hint for the position where the element can be inserted. - * @param val Value to be inserted as an element. - * - * @return An iterator pointing to either the newly inserted element or to the element that already had its - * same value in the {@link SetContainer}. - */ - insert(hint: SetIterator, val: T): SetIterator; - /** - *

Insert an element with hint.

- * - *

Extends the container by inserting new elements, effectively increasing the container size by the - * number of elements inserted.

- * - * @param hint Hint for the position where the element can be inserted. - * @param val Value to be inserted as an element. - * - * @return An iterator pointing to either the newly inserted element or to the element that already had its - * same value in the {@link SetContainer}. - */ - insert(hint: SetReverseIterator, val: T): SetReverseIterator; - /** - *

Insert elements with a range of a

- * - *

Extends the container by inserting new elements, effectively increasing the container size by the - * number of elements inserted.

- * - * @param begin An iterator specifying range of the begining element. - * @param end An iterator specifying range of the ending element. - */ - insert>(begin: InputIterator, end: InputIterator): void; - /** - * @hidden - */ - protected abstract _Insert_by_val(val: T): any; - /** - * @hidden - */ - protected abstract _Insert_by_hint(hint: SetIterator, val: T): SetIterator; - /** - * @hidden - */ - protected abstract _Insert_by_range>(begin: InputIterator, end: InputIterator): void; - /** - *

Erase an element.

- *

Removes from the set container the elements whose value is key.

- * - *

This effectively reduces the container size by the number of elements removed.

- * - * @param key Value of the elements to be erased. - * - * @return Number of elements erased. - */ - erase(val: T): number; - /** - * @inheritdoc - */ - erase(it: SetIterator): SetIterator; - /** - *

Erase elements.

- *

Removes from the set container a range of elements..

- * - *

This effectively reduces the container size by the number of elements removed.

- * - * @param begin An iterator specifying a range of beginning to erase. - * @param end An iterator specifying a range of end to erase. - */ - erase(begin: SetIterator, end: SetIterator): SetIterator; - /** - * @inheritdoc - */ - erase(it: SetReverseIterator): SetReverseIterator; - /** - *

Erase elements.

- *

Removes from the set container a range of elements..

- * - *

This effectively reduces the container size by the number of elements removed.

- * - * @param begin An iterator specifying a range of beginning to erase. - * @param end An iterator specifying a range of end to erase. - */ - erase(begin: SetReverseIterator, end: SetReverseIterator): SetReverseIterator; - /** - * @hidden - */ - private erase_by_iterator(first, last?); - /** - * @hidden - */ - private erase_by_val(val); - /** - * @hidden - */ - private erase_by_range(first, last); - /** - * @hidden - */ - protected _Swap(obj: SetContainer): void; - /** - * Merge two sets. - * - * Extracts and transfers elements from *source* to this container. - * - * @param source A {@link SetContainer set container} to transfer the elements from. - */ - abstract merge(source: SetContainer): void; - /** - *

Abstract method handling insertions for indexing.

- * - *

This method, {@link _Handle_insert} is designed to register the first to last to somewhere storing - * those {@link SetIterator iterators} for indexing, fast accessment and retrievalance.

- * - *

When {@link insert} is called, new elements will be inserted into the {@link data_ list container} and new - * {@link SetIterator iterators} first to last, pointing the inserted elements, will be created and the - * newly created iterators first to last will be shifted into this method {@link _Handle_insert} after the - * insertions.

- * - *

If the derived one is {@link RBTree tree-based} like {@link TreeSet}, the {@link SetIterator iterators} - * will be registered into the {@link TreeSet.tree_ tree} as a {@link XTreeNode tree node item}. Else if the - * derived one is {@link HashBuckets hash-based} like {@link HashSet}, the first to last will be - * registered into the {@link HashSet.hash_buckets_ hash bucket}.

- * - * @param first An {@link SetIterator} to the initial position in a sequence. - * @param last An {@link SetIterator} to the final position in a sequence. The range used is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - */ - protected abstract _Handle_insert(first: SetIterator, last: SetIterator): void; - /** - *

Abstract method handling deletions for indexing.

- * - *

This method, {@link _Handle_erase} is designed to unregister the first to last to somewhere storing - * those {@link SetIterator iterators} for indexing, fast accessment and retrievalance.

- * - *

When {@link erase} is called with first to last, {@link SetIterator iterators} positioning somewhere - * place to be deleted, is memorized and shifted to this method {@link _Handle_erase} after the deletion process is - * terminated.

- * - *

If the derived one is {@link RBTree tree-based} like {@link TreeSet}, the {@link SetIterator iterators} - * will be unregistered from the {@link TreeSet.tree_ tree} as a {@link XTreeNode tree node item}. Else if the - * derived one is {@link HashBuckets hash-based} like {@link HashSet}, the first to last will be - * unregistered from the {@link HashSet.hash_buckets_ hash bucket}.

- * - * @param first An {@link SetIterator} to the initial position in a sequence. - * @param last An {@link SetIterator} to the final position in a sequence. The range used is - * [first, last), which contains all the elements between first and last, - * including the element pointed by first but not the element pointed by last. - */ - protected abstract _Handle_erase(first: SetIterator, last: SetIterator): void; - } - /** - * @hidden - */ - class SetElementList extends ListContainer> { - private associative_; - private rend_; - constructor(associative: SetContainer); - protected _Create_iterator(prev: SetIterator, next: SetIterator, val: T): SetIterator; - protected _Set_begin(it: SetIterator): void; - get_associative(): SetContainer; - rbegin(): SetReverseIterator; - rend(): SetReverseIterator; - } -} -declare namespace std { - /** - *

An iterator of a Set.

- * - *

- *

- * - * @author Jeongho Nam - */ - class SetIterator extends base.ListIteratorBase implements IComparable> { - /** - *

Construct from source and index number.

- * - *

Note

- *

Do not create iterator directly.

- *

Use begin(), find() or end() in Map instead.

- * - * @param map The source Set to reference. - * @param index Sequence number of the element in the source Set. - */ - constructor(source: base.SetElementList, prev: SetIterator, next: SetIterator, val: T); - /** - * @inheritdoc - */ - get_source(): base.SetContainer; - /** - * @inheritdoc - */ - prev(): SetIterator; - /** - * @inheritdoc - */ - next(): SetIterator; - /** - * @inheritdoc - */ - advance(size: number): SetIterator; - /** - * @inheritdoc - */ - less(obj: SetIterator): boolean; - /** - * @inheritdoc - */ - equals(obj: SetIterator): boolean; - /** - * @inheritdoc - */ - hashCode(): number; - /** - * @inheritdoc - */ - swap(obj: SetIterator): void; - } - /** - *

A reverse-iterator of Set.

- * - *

- *

- * - * @param Type of the elements. - * - * @author Jeongho Nam - */ - class SetReverseIterator extends ReverseIterator, SetReverseIterator> { - /** - * Construct from base iterator. - * - * @param base A reference of the base iterator, which iterates in the opposite direction. - */ - constructor(base: SetIterator); - /** - * @hidden - */ - protected _Create_neighbor(base: SetIterator): SetReverseIterator; - } -} -declare namespace std.base { - /** - *

An abstract set.

- * - *

{@link SetContainer SetContainers} are containers that store elements allowing fast retrieval of - * individual elements based on their value.

- * - *

In an {@link SetContainer}, the value of an element is at the same time its key, used to - * identify it. Keys are immutable, therefore, the elements in an {@link SetContainer} cannot be - * modified once in the container - they can be inserted and removed, though.

- * - *

{@link SetContainer} stores elements, keeps sequence and enables indexing by inserting elements into a - * {@link List} and registering {@link ListIterator iterators} of the {@link data_ list container} to an index - * table like {@link RBTree tree} or {@link HashBuckets hash-table}.

- * - *

- *

- * - *

Container properties

- *
- *
Associative
- *
- * Elements in associative containers are referenced by their key and not by their absolute - * position in the container. - *
- * - *
Set
- *
The value of an element is also the key used to identify it.
- * - *
Multiple equivalent keys
- *
Multiple elements in the container can have equivalent keys.
- *
- * - * @param Type of the elements. Each element in a {@link SetContainer} container is also identified - * by this value (each value is itself also the element's key). - * - * @author Jeongho Nam - */ - abstract class MultiSet extends SetContainer { - /** - *

Insert an element.

- * - *

Extends the container by inserting new elements, effectively increasing the container {@link size} by - * the number of elements inserted.

- * - * @param key Value to be inserted as an element. - * - * @return An iterator to the newly inserted element. - */ - insert(val: T): SetIterator; - /** - * @inheritdoc - */ - insert(hint: SetIterator, val: T): SetIterator; - /** - * @inheritdoc - */ - insert(hint: SetReverseIterator, val: T): SetReverseIterator; - /** - * @inheritdoc - */ - insert>(begin: InputIterator, end: InputIterator): void; - /** - * @inheritdoc - */ - merge(source: SetContainer): void; - } -} -declare namespace std.base { - /** - *

Red-black Tree.

- * - *

A red-black tree is a kind of self-balancing - * binary search tree. Each node of the binary tree has an extra bit, and that bit is often interpreted as the - * color (red or black) of the node. These color bits - * are used to ensure the tree remains approximately balanced during insertions and deletions.

- * - *

Balance is preserved by painting each node of the tree with one of two colors (typically called - * 'red' and 'black') in a way that satisfies certain - * properties, which collectively constrain how unbalanced the tree can become in the worst case. When the tree - * is modified, the new tree is subsequently rearranged and repainted to restore the coloring properties. The - * properties are designed in such a way that this rearranging and recoloring can be performed efficiently.

- * - *

The balancing of the tree is not perfect but it is good enough to allow it to guarantee searching in - * O(log n) time, where n is the total number of elements in the tree. The insertion and deletion operations, - * along with the tree rearrangement and recoloring, are also performed in O(log n) time.

- * - *

Tracking the color of each node requires only 1 bit of information per node because there are only two - * colors. The tree does not contain any other data specific to its being a - * red-black tree so its memory footprint is almost - * identical to a classic (uncolored) binary search tree. In many cases the additional bit of information can - * be stored at no additional memory cost.

- * - *

Properties

- *

In addition to the requirements imposed on a binary search tree the following must be satisfied by a - * red-black tree:

- * - *
    - *
  1. A node is either red or black.
  2. - *
  3. - * The root is black. This rule is sometimes omitted. Since the root can - * always be changed from red to black, but not - * necessarily vice versa, this rule has little effect on analysis. - *
  4. - *
  5. All leaves (NIL; null) are black.
  6. - *
  7. - * If a node is red, then both its children are - * black. - *
  8. - *
  9. - * Every path from a given node to any of its descendant NIL nodes contains the same number of - * black nodes. Some definitions: the number of - * black nodes from the root to a node is the node's - * black depth; the uniform number of black - * nodes in all paths from root to the leaves is called the black-height of - * the red-black tree. - *
  10. - *
- * - *

- * - *

These constraints enforce a critical property of red-black trees: the path from the root to the farthest - * leaf is no more than twice as long as the path from the root to the nearest leaf. The result is that the tree - * is roughly height-balanced. Since operations such as inserting, deleting, and finding values require - * worst-case time proportional to the height of the tree, this theoretical upper bound on the height allows - * red-black trees to be efficient in the worst case, unlike ordinary binary search trees.

- * - *

To see why this is guaranteed, it suffices to consider the effect of properties 4 and 5 together. For a - * red-black tree T, let B be the number of black nodes in property 5. Let the - * shortest possible path from the root of T to any leaf consist of B black nodes. - * Longer possible paths may be constructed by inserting red nodes. However, property 4 - * makes it impossible to insert more than one consecutive red node. Therefore, - * ignoring any black NIL leaves, the longest possible path consists of 2*B nodes, - * alternating black and red (this is the worst case). - * Counting the black NIL leaves, the longest possible path consists of 2*B-1 - * nodes.

- * - *

The shortest possible path has all black nodes, and the longest possible - * path alternates between red and black nodes. Since all - * maximal paths have the same number of black nodes, by property 5, this shows - * that no path is more than twice as long as any other path.

- * - * @param Type of elements. - * - * @reference https://en.wikipedia.org/w/index.php?title=Red%E2%80%93black_tree - * @inventor Rudolf Bayer - * @author Migrated by Jeongho Nam - */ - abstract class XTree { - /** - * Root node. - */ - protected root_: XTreeNode; - /** - * Default Constructor. - */ - protected constructor(); - /** - * Clear, removes all tree nodes. - */ - clear(): void; - /** - * Find a node from its contained value. - * - * @param val Value to find. - */ - find(val: T): XTreeNode; - /** - * Fetch maximum (the rightes?) node from one. - * - * @param node A node to fetch its maximum node. - * @return The maximum node. - */ - protected fetch_maximum(node: XTreeNode): XTreeNode; - abstract is_less(left: T, right: T): boolean; - abstract is_equal_to(left: T, right: T): boolean; - /** - *

Insert an element with a new node.

- * - *

Insertion begins by adding the node as any binary search tree insertion does and by coloring it - * red. Whereas in the binary search tree, we always add a leaf, in the red-black - * tree, leaves contain no information, so instead we add a red interior node, with - * two black leaves, in place of an existing - * black leaf.

- * - *

What happens next depends on the color of other nearby nodes. The term uncle node will be used to - * refer to the sibling of a node's parent, as in human family trees. Note that:

- * - *
    - *
  • property 3 (all leaves are black) always holds.
  • - *
  • - * property 4 (both children of every red node are - * black) is threatened only by adding a red - * node, repainting a black node red, or a - * rotation. - *
  • - *
  • - * property 5 (all paths from any given node to its leaf nodes contain the same number of - * black nodes) is threatened only by adding a - * black node, repainting a red node - * black (or vice versa), or a rotation. - *
  • - *
- * - *

Notes

- *
    - *
  1. - * The label N will be used to denote the current node (colored - * red). In the diagrams N carries a blue contour. At the - * beginning, this is the new node being inserted, but the entire procedure may also be applied - * recursively to other nodes (see case 3). {@link XTreeNode.parent P} will denote - * N's parent node, {@link XTreeNode.grand_parent G} will denote N's - * grandparent, and {@link XTreeNode.uncle U} will denote N's uncle. In between - * some cases, the roles and labels of the nodes are exchanged, but in each case, every label continues - * to represent the same node it represented at the beginning of the case. - *
  2. - *
  3. - * If a node in the right (target) half of a diagram carries a blue contour it will become the current - * node in the next iteration and there the other nodes will be newly assigned relative to it. Any - * color shown in the diagram is either assumed in its case or implied by those assumptions. - *
  4. - *
  5. - * A numbered triangle represents a subtree of unspecified depth. A black - * circle atop a triangle means that black-height of subtree is greater - * by one compared to subtree without this circle.
  6. - *
- * - *

There are several cases of red-black tree insertion to handle:

- * - *
    - *
  • N is the root node, i.e., first node of red-black tree.
  • - *
  • - * N's parent ({@link XTreeNode.parent P}) is black. - *
  • - *
  • - * N's parent ({@link XTreeNode.parent P}) and uncle - * ({@link XTreeNode.uncle U}) are red. - *
  • - *
  • - * N is added to right of left child of grandparent, or N is added to left - * of right child of grandparent ({@link XTreeNode.parent P} is red and - * {@link XTreeNode.uncle U} is black). - *
  • - *
  • - * N is added to left of left child of grandparent, or N is added to right - * of right child of grandparent ({@link XTreeNode.parent P} is red and - * {@link XTreeNode.uncle U} is black). - *
  • - *
- * - *

Note

- *

Note that inserting is actually in-place, since all the calls above use tail recursion.

- * - *

In the algorithm above, all cases are chained in order, except in insert case 3 where it can recurse - * to case 1 back to the grandparent node: this is the only case where an iterative implementation will - * effectively loop. Because the problem of repair is escalated to the next higher level but one, it takes - * maximally h⁄2 iterations to repair the tree (where h is the height of the tree). Because the probability - * for escalation decreases exponentially with each iteration the average insertion cost is constant.

- * - * @param val An element to insert. - */ - insert(val: T): void; - /** - *

N is the root node, i.e., first node of red-black tree.

- * - *

The current node N is at the {@link root_ root} of the tree.

- * - *

In this case, it is repainted black to satisfy property 2 (the root is - * black). Since this adds one black node to - * every path at once, property 5 (all paths from any given node to its leaf nodes contain the same number - * of black nodes) is not violated.

- * - * @param N A node to be inserted or swapped. - */ - private insert_case1(N); - /** - *

N's parent ({@link XTreeNode.parent P}) is black.

- * - *

The current node's parent {@link XTreeNode.parent P} is black, - * so property 4 (both children of every red node are - * black) is not invalidated.

- * - *

In this case, the tree is still valid. Property 5 (all paths from any given node to its leaf nodes - * contain the same number of black nodes) is not threatened, because the - * current node N has two black leaf children, but because - * N is red, the paths through each of its children have the same - * number of black nodes as the path through the leaf it replaced, which was - * black, and so this property remains satisfied.

- * - * @param N A node to be inserted or swapped. - */ - private insert_case2(N); - /** - *

N's parent ({@link XTreeNode.parent P}) and uncle - * ({@link XTreeNode.uncle U}) are red.

- * - *

If both the parent {@link XTreeNode.parent P} and the uncle {@link XTreeNode.uncle U} - * are red, then both of them can be repainted black - * and the grandparent {@link XTreeNode.grand_parent G} becomes red (to - * maintain property 5 (all paths from any given node to its leaf nodes contain the same number of - * black nodes)).

- * - *

Now, the current red node N has a - * black parent. Since any path through the parent or uncle must pass through - * the grandparent, the number of black nodes on these paths has not changed. - * - *

However, the grandparent {@link XTreeNode.grand_parent G} may now violate properties 2 (The - * root is black) or 4 (Both children of every red - * node are black) (property 4 possibly being violated since - * {@link XTreeNode.grand_parent G} may have a red parent).

- * - *

To fix this, the entire procedure is recursively performed on {@link XTreeNode.grand_parent G} - * from case 1. Note that this is a tail-recursive call, so it could be rewritten as a loop; since this is - * the only loop, and any rotations occur after this loop, this proves that a constant number of rotations - * occur.

- * - *

- * - * @param N A node to be inserted or swapped. - */ - private insert_case3(N); - /** - *

N is added to right of left child of grandparent, or N is added to left - * of right child of grandparent ({@link XTreeNode.parent P} is red and - * {@link XTreeNode.uncle U} is black).

- * - *

The parent {@link XTreeNode.parent P} is red but the uncle - * {@link XTreeNode.uncle U} is black; also, the current node - * N is the right child of {@link XTreeNode.parent P}, and - * {@link XTreeNode.parent P} in turn is the left child of its parent - * {@link XTreeNode.grand_parent G}.

- * - *

In this case, a left rotation on {@link XTreeNode.parent P} that switches the roles of the - * current node N and its parent {@link XTreeNode.parent P} can be performed; then, - * the former parent node {@link XTreeNode.parent P} is dealt with using case 5 - * (relabeling N and {@link XTreeNode.parent P}) because property 4 (both children of - * every red node are black) is still violated.

- * - *

The rotation causes some paths (those in the sub-tree labelled "1") to pass through the node - * N where they did not before. It also causes some paths (those in the sub-tree labelled "3") - * not to pass through the node {@link XTreeNode.parent P} where they did before. However, both of - * these nodes are red, so property 5 (all paths from any given node to its leaf - * nodes contain the same number of black nodes) is not violated by the - * rotation.

- * - *

After this case has been completed, property 4 (both children of every red - * node are black) is still violated, but now we can resolve this by - * continuing to case 5.

- * - *

- * - * @param N A node to be inserted or swapped. - */ - private insert_case4(node); - /** - *

N is added to left of left child of grandparent, or N is added to right - * of right child of grandparent ({@link XTreeNode.parent P} is red and - * {@link XTreeNode.uncle U} is black).

- * - *

The parent {@link XTreeNode.parent P} is red but the uncle - * {@link XTreeNode.uncle U} is black, the current node N - * is the left child of {@link XTreeNode.parent P}, and {@link XTreeNode.parent P} is the left - * child of its parent {@link XTreeNode.grand_parent G}.

- * - *

In this case, a right rotation on {@link XTreeNode.grand_parent G} is performed; the result is a - * tree where the former parent {@link XTreeNode.parent P} is now the parent of both the current node - * N and the former grandparent {@link XTreeNode.grand_parent G}.

- * - *

{@link XTreeNode.grand_parent G} is known to be black, since its - * former child {@link XTreeNode.parent P} could not have been red otherwise - * (without violating property 4). Then, the colors of {@link XTreeNode.parent P} and - * {@link XTreeNode.grand_parent G} are switched, and the resulting tree satisfies property 4 (both - * children of every red node are black). Property 5 - * (all paths from any given node to its leaf nodes contain the same number of - * black nodes) also remains satisfied, since all paths that went through any - * of these three nodes went through {@link XTreeNode.grand_parent G} before, and now they all go - * through {@link XTreeNode.parent P}. In each case, this is the only - * black node of the three.

- * - *

- * - * @param N A node to be inserted or swapped. - */ - private insert_case5(node); - /** - *

Erase an element with its node.

- * - *

In a regular binary search tree when deleting a node with two non-leaf children, we find either the - * maximum element in its left subtree (which is the in-order predecessor) or the minimum element in its - * right subtree (which is the in-order successor) and move its value into the node being deleted (as shown - * here). We then delete the node we copied the value from, which must have fewer than two non-leaf children. - * (Non-leaf children, rather than all children, are specified here because unlike normal binary search - * trees, red-black trees can have leaf nodes anywhere, so that all nodes are either internal nodes with - * two children or leaf nodes with, by definition, zero children. In effect, internal nodes having two leaf - * children in a red-black tree are like the leaf nodes in a regular binary search tree.) Because merely - * copying a value does not violate any red-black properties, this reduces to the problem of deleting a node - * with at most one non-leaf child. Once we have solved that problem, the solution applies equally to the - * case where the node we originally want to delete has at most one non-leaf child as to the case just - * considered where it has two non-leaf children.

- * - *

Therefore, for the remainder of this discussion we address the deletion of a node with at most one - * non-leaf child. We use the label M to denote the node to be deleted; C will denote a - * selected child of M, which we will also call "its child". If M does have a non-leaf child, - * call that its child, C; otherwise, choose either leaf as its child, C.

- * - *

If M is a red node, we simply replace it with its child C, - * which must be black by property 4. (This can only occur when M has - * two leaf children, because if the red node M had a - * black non-leaf child on one side but just a leaf child on the other side, - * then the count of black nodes on both sides would be different, thus the - * tree would violate property 5.) All paths through the deleted node will simply pass through one fewer - * red node, and both the deleted node's parent and child must be - * black, so property 3 (all leaves are black) - * and property 4 (both children of every red node are - * black) still hold.

- * - *

Another simple case is when M is black and C is - * red. Simply removing a black node could break - * Properties 4 (“Both children of every red node are - * black”) and 5 (“All paths from any given node to its leaf nodes contain the - * same number of black nodes”), but if we repaint C - * black, both of these properties are preserved.

- * - *

The complex case is when both M and C are black. (This - * can only occur when deleting a black node which has two leaf children, - * because if the black node M had a black - * non-leaf child on one side but just a leaf child on the other side, then the count of - * black nodes on both sides would be different, thus the tree would have been - * an invalid red-black tree by violation of property 5.) We begin by replacing M with its child - * C. We will relabel this child C (in its new position) N, and its sibling (its - * new parent's other child) {@link XTreeNode.sibling S}. ({@link XTreeNode.sibling S} was - * previously the sibling of M.)

- * - *

In the diagrams below, we will also use {@link XTreeNode.parent P} for N's new - * parent (M's old parent), SL for {@link XTreeNode.sibling S}'s left child, and - * SR for {@link XTreeNode.sibling S}'s right child ({@link XTreeNode.sibling S} cannot - * be a leaf because if M and C were black, then - * {@link XTreeNode.parent P}'s one subtree which included M counted two - * black-height and thus {@link XTreeNode.parent P}'s other subtree - * which includes {@link XTreeNode.sibling S} must also count two - * black-height, which cannot be the case if {@link XTreeNode.sibling S} - * is a leaf node).

- * - *

Notes

- *
    - *
  1. - * The label N will be used to denote the current node (colored - * black). In the diagrams N carries a blue contour. At the - * beginning, this is the replacement node and a leaf, but the entire procedure may also be applied - * recursively to other nodes (see case 3). In between some cases, the roles and labels of the nodes - * are exchanged, but in each case, every label continues to represent the same node it represented at - * the beginning of the case. - *
  2. - *
  3. - * If a node in the right (target) half of a diagram carries a blue contour it will become the current - * node in the next iteration and there the other nodes will be newly assigned relative to it. Any - * color shown in the diagram is either assumed in its case or implied by those assumptions. - * White represents an arbitrary color (either red or - * black), but the same in both halves of the diagram. - *
  4. - *
  5. - * A numbered triangle represents a subtree of unspecified depth. A black - * circle atop a triangle means that black-height of subtree is greater - * by one compared to subtree without this circle. - *
  6. - *
- * - *

If both N and its original parent are black, then - * deleting this original parent causes paths which proceed through N to have one fewer - * black node than paths that do not. As this violates property 5 (all paths - * from any given node to its leaf nodes contain the same number of black - * nodes), the tree must be rebalanced. There are several cases to consider:

- * - *
    - *
  1. N is the new root.
  2. - *
  3. {@link XTreeNode.sibling S} is red.
  4. - *
  5. - * {@link XTreeNode.parent P}, {@link XTreeNode.sibling S}, and - * {@link XTreeNode.sibling S}'s children are black.
  6. - *
  7. - * {@link XTreeNode.sibling S} and {@link XTreeNode.sibling S}'s children are - * black, but {@link XTreeNode.parent P} is - * red. - *
  8. - *
  9. - * {@link XTreeNode.sibling S} is black, - * {@link XTreeNode.sibling S}'s left child is red, - * {@link XTreeNode.sibling S}'s right child is black, and - * N is the left child of its parent. - *
  10. - *
  11. - * {@link XTreeNode.sibling S} is black, - * {@link XTreeNode.sibling S}'s right child is red, and - * N is the left child of its parent {@link XTreeNode.parent P}. - *
  12. - *
- * - *

Again, the function calls all use tail recursion, so the algorithm is in-place.

- * - *

In the algorithm above, all cases are chained in order, except in delete case 3 where it can recurse - * to case 1 back to the parent node: this is the only case where an iterative implementation will - * effectively loop. No more than h loops back to case 1 will occur (where h is the height of the tree). - * And because the probability for escalation decreases exponentially with each iteration the average - * removal cost is constant.

- * - *

Additionally, no tail recursion ever occurs on a child node, so the tail recursion loop can only - * move from a child back to its successive ancestors. If a rotation occurs in case 2 (which is the only - * possibility of rotation within the loop of cases 1–3), then the parent of the node N - * becomes red after the rotation and we will exit the loop. Therefore, at most one - * rotation will occur within this loop. Since no more than two additional rotations will occur after - * exiting the loop, at most three rotations occur in total.

- * - * @param val An element to erase. - */ - erase(val: T): void; - /** - *

N is the new root.

- * - *

In this case, we are done. We removed one black node from every path, - * and the new root is black, so the properties are preserved.

- * - *

Note

- *

In cases 2, 5, and 6, we assume N is the left child of its parent - * {@link XTreeNode.parent P}. If it is the right child, left and right should be reversed throughout - * these three cases. Again, the code examples take both cases into account.

- * - * @param N A node to be erased or swapped. - */ - private erase_case1(N); - /** - *

{@link XTreeNode.sibling S} is red.

- * - *

- * - *

In this case we reverse the colors of {@link XTreeNode.parent P} and - * {@link XTreeNode.sibling S}, and then rotate left at {@link XTreeNode.parent P}, turning - * {@link XTreeNode.sibling S} into N's grandparent.

- * - *

Note that {@link XTreeNode.parent P} has to be black as it had a - * red child. The resulting subtree has a path short one - * black node so we are not done. Now N has a - * black sibling and a red parent, so we can proceed - * to step 4, 5, or 6. (Its new sibling is black because it was once the child - * of the red {@link XTreeNode.sibling S}.) In later cases, we will re-label - * N's new sibling as {@link XTreeNode.sibling S}.

- * - * @param N A node to be erased or swapped. - */ - private erase_case2(N); - /** - *

{@link XTreeNode.parent P}, {@link XTreeNode.sibling S}, and {@link XTreeNode.sibling - * S}'s children are black.

- * - *

- * - *

In this case, we simply repaint {@link XTreeNode.sibling S} red. The - * result is that all paths passing through {@link XTreeNode.sibling S}, which are precisely those - * paths not passing through N, have one less black node. - * Because deleting N's original parent made all paths passing through N have - * one less black node, this evens things up.

- * - *

However, all paths through {@link XTreeNode.parent P} now have one fewer - * black node than paths that do not pass through - * {@link XTreeNode.parent P}, so property 5 (all paths from any given node to its leaf nodes contain - * the same number of black nodes) is still violated.

- * - *

To correct this, we perform the rebalancing procedure on {@link XTreeNode.parent P}, starting - * at case 1.

- * - * @param N A node to be erased or swapped. - */ - private erase_case3(N); - /** - *

{@link XTreeNode.sibling S} and {@link XTreeNode.sibling S}'s children are - * black, but {@link XTreeNode.parent P} is red.

- * - *

- * - *

In this case, we simply exchange the colors of {@link XTreeNode.sibling S} and - * {@link XTreeNode.parent P}. This does not affect the number of black - * nodes on paths going through {@link XTreeNode.sibling S}, but it does add one to the number of - * black nodes on paths going through N, making up for the - * deleted black node on those paths.

- * - * @param N A node to be erased or swapped. - */ - private erase_case4(N); - /** - *

{@link XTreeNode.sibling S} is black, {@link XTreeNode.sibling S}'s - * left child is red, {@link XTreeNode.sibling S}'s right child is - * black, and N is the left child of its parent.

- * - *

- * - *

In this case we rotate right at {@link XTreeNode.sibling S}, so that - * {@link XTreeNode.sibling S}'s left child becomes {@link XTreeNode.sibling S}'s parent and - * N's new sibling. We then exchange the colors of {@link XTreeNode.sibling S} and its - * new parent.

- * - *

All paths still have the same number of black nodes, but now - * N has a black sibling whose right child is - * red, so we fall into case 6. Neither N nor its parent are affected - * by this transformation. (Again, for case 6, we relabel N's new sibling as - * {@link XTreeNode.sibling S}.)

- * - * @param N A node to be erased or swapped. - */ - private erase_case5(N); - /** - *

{@link XTreeNode.sibling S} is black, - * {@link XTreeNode.sibling S}'s right child is red, and N is - * the left child of its parent {@link XTreeNode.parent P}.

- * - *

In this case we rotate left at {@link XTreeNode.parent P}, so that - * {@link XTreeNode.sibling S} becomes the parent of {@link XTreeNode.parent P} and - * {@link XTreeNode.sibling S}'s right child. We then exchange the colors of - * {@link XTreeNode.parent P} and {@link XTreeNode.sibling S}, and make - * {@link XTreeNode.sibling S}'s right child black.

- * - *

The subtree still has the same color at its root, so Properties 4 (Both children of every - * red node are black) and 5 (All paths from any - * given node to its leaf nodes contain the same number of black nodes) are - * not violated. However, N now has one additional black - * ancestor: either {@link XTreeNode.parent P} has become black, or it - * was black and {@link XTreeNode.sibling S} was added as a - * black grandparent.

- * - *

Thus, the paths passing through N pass through one additional - * black node.

- * - *

- * - *

Meanwhile, if a path does not go through N, then there are two possibilities:

- *
    - *
  1. - * It goes through N's new sibling SL, a node with arbitrary color and the root of - * the subtree labeled 3 (s. diagram). Then, it must go through {@link XTreeNode.sibling S} and - * {@link XTreeNode.parent P}, both formerly and currently, as they have only exchanged colors - * and places. Thus the path contains the same number of black nodes. - *
  2. - *
  3. - * It goes through N's new uncle, {@link XTreeNode.sibling S}'s right child. Then, - * it formerly went through {@link XTreeNode.sibling S}, {@link XTreeNode.sibling S}'s - * parent, and {@link XTreeNode.sibling S}'s right child SR (which was - * red), but now only goes through {@link XTreeNode.sibling S}, which - * has assumed the color of its former parent, and {@link XTreeNode.sibling S}'s right child, - * which has changed from red to black (assuming - * {@link XTreeNode.sibling S}'s color: black). The net effect is - * that this path goes through the same number of black nodes. - *
  4. - *
- * - *

Either way, the number of black nodes on these paths does not change. - * Thus, we have restored Properties 4 (Both children of every red node are - * black) and 5 (All paths from any given node to its leaf nodes contain the - * same number of black nodes). The white node in the diagram can be either - * red or black, but must refer to the same color - * both before and after the transformation.

- * - * @param N A node to be erased or swapped. - */ - private erase_case6(node); - /** - * Rotate a node left. - * - * @param node Node to rotate left. - */ - protected rotate_left(node: XTreeNode): void; - /** - * Rotate a node to right. - * - * @param node A node to rotate right. - */ - protected rotate_right(node: XTreeNode): void; - /** - * Replace a node. - * - * @param oldNode Ordinary node to be replaced. - * @param newNode Target node to replace. - */ - protected replace_node(oldNode: XTreeNode, newNode: XTreeNode): void; - /** - * Fetch color from a node. - * - * @param node A node to fetch color. - * @retur color. - */ - private fetch_color(node); - } -} -declare namespace std.base { - /** - *

Common interface for tree-structured map.

- * - *

{@link ITreeMap ITreeMaps} are associative containers that store elements formed by a combination of - * a key value and a mapped value, following a specific order.

- * - *

In a {@link ITreeMap}, the key values are generally used to sort and uniquely identify - * the elements, while the mapped values store the content associated to this key. The types of - * key and mapped value may differ, and are grouped together in member type - * value_type, which is a {@link Pair} type combining both:

- * - *

typedef Pair value_type;

- * - *

Internally, the elements in a {@link ITreeMap}are always sorted by its key following a - * strict weak ordering criterion indicated by its internal comparison method (of {@link less}).

- * - *

{@link ITreeMap}containers are generally slower than {@link IHashMap} containers - * to access individual elements by their key, but they allow the direct iteration on subsets based - * on their order.

- * - *

{@link ITreeMap TreeMultiMaps} are typically implemented as binary search trees.

- * - *

- *

- * - *

Container properties

- *
- *
Associative
- *
Elements in associative containers are referenced by their key and not by their absolute - * position in the container.
- * - *
Ordered
- *
The elements in the container follow a strict order at all times. All inserted elements are - * given a position in this order.
- * - *
Map
- *
Each element associates a key to a mapped value: - * Keys are meant to identify the elements whose main content is the mapped value.
- *
- * - * @param Type of the keys. Each element in a map is uniquely identified by its key value. - * @param Type of the mapped value. Each element in a map stores some data as its mapped value. - * - * @reference http://www.cplusplus.com/reference/map - * @author Jeongho Nam - */ - interface ITreeMap { - /** - *

Return key comparison function.

- * - *

Returns a references of the comparison function used by the container to compare keys.

- * - *

The comparison object of a {@link ITreeMap tree-map object} is set on - * {@link TreeMap.constructor construction}. Its type (Key) is the last parameter of the - * {@link ITreeMap.constructor constructors}. By default, this is a {@link less} function, which returns the same - * as operator<.

- * - *

This function determines the order of the elements in the container: it is a function pointer that takes - * two arguments of the same type as the element keys, and returns true if the first argument - * is considered to go before the second in the strict weak ordering it defines, and false otherwise. - *

- * - *

Two keys are considered equivalent if {@link key_comp} returns false reflexively (i.e., no - * matter the order in which the keys are passed as arguments).

- * - * @return The comparison function. - */ - key_comp(): (x: Key, y: Key) => boolean; - /** - *

Return value comparison function.

- * - *

Returns a comparison function that can be used to compare two elements to get whether the key of the first - * one goes before the second.

- * - *

The arguments taken by this function object are of member type std.Pair (defined in - * {@link ITreeMap}), but the mapped type (T) part of the value is not taken into consideration in this - * comparison.

- * - *

This comparison class returns true if the {@link Pair.first key} of the first argument - * is considered to go before that of the second (according to the strict weak ordering specified by the - * container's comparison function, {@link key_comp}), and false otherwise.

- * - * @return The comparison function for element values. - */ - value_comp(): (x: Pair, y: Pair) => boolean; - /** - *

Return iterator to lower bound.

- * - *

Returns an iterator pointing to the first element in the container whose key is not considered to - * go before k (i.e., either it is equivalent or goes after).

- * - *

The function uses its internal comparison object (key_comp) to determine this, returning an - * iterator to the first element for which key_comp(k, element_key) would return false.

- * - *

If the {@link ITreeMap} class is instantiated with the default comparison type ({@link less}), - * the function returns an iterator to the first element whose key is not less than k

. - * - *

A similar member function, {@link upper_bound}, has the same behavior as {@link lower_bound}, except - * in the case that the {@link ITreeMap} contains an element with a key equivalent to k: In this - * case, {@link lower_bound} returns an iterator pointing to that element, whereas {@link upper_bound} - * returns an iterator pointing to the next element.

- * - * @param k Key to search for. - * - * @return An iterator to the the first element in the container whose key is not considered to go before - * k, or {@link ITreeMap.end} if all keys are considered to go before k. - */ - lower_bound(key: Key): MapIterator; - /** - *

Return iterator to upper bound.

- * - *

Returns an iterator pointing to the first element in the container whose key is considered to - * go after k

. - * - *

The function uses its internal comparison object (key_comp) to determine this, returning an - * iterator to the first element for which key_comp(k, element_key) would return true.

- * - *

If the {@link ITreeMap} class is instantiated with the default comparison type ({@link less}), - * the function returns an iterator to the first element whose key is greater than k

. - * - *

A similar member function, {@link lower_bound}, has the same behavior as {@link upper_bound}, except - * in the case that the map contains an element with a key equivalent to k: In this case - * {@link lower_bound} returns an iterator pointing to that element, whereas {@link upper_bound} returns an - * iterator pointing to the next element.

- * - * @param k Key to search for. - * - * @return An iterator to the the first element in the container whose key is considered to go after - * k, or {@link TreeMap.end end} if no keys are considered to go after k. - */ - upper_bound(key: Key): MapIterator; - /** - *

Get range of equal elements.

- * - *

Returns the bounds of a range that includes all the elements in the container which have a key - * equivalent to k

. - * - *

If no matches are found, the range returned has a length of zero, with both iterators pointing to - * the first element that has a key considered to go after k according to the container's internal - * comparison object (key_comp).

- * - *

Two keys are considered equivalent if the container's comparison object returns false reflexively - * (i.e., no matter the order in which the keys are passed as arguments).

- * - * @param k Key to search for. - * - * @return The function returns a {@link Pair}, whose member {@link Pair.first} is the lower bound of - * the range (the same as {@link lower_bound}), and {@link Pair.second} is the upper bound - * (the same as {@link upper_bound}). - */ - equal_range(key: Key): Pair, MapIterator>; - } -} -declare namespace std.base { - /** - *

A red-black tree storing {@link MapIterator MapIterators}.

- * - *

- *

- * - * @author Jeongho Nam - */ - class PairTree extends XTree> { - /** - * @hidden - */ - private map_; - /** - * @hidden - */ - private compare_; - /** - * Default Constructor. - */ - constructor(map: TreeMap | TreeMultiMap, compare?: (x: Key, y: Key) => boolean); - find(key: Key): XTreeNode>; - find(it: MapIterator): XTreeNode>; - /** - * @hidden - */ - private find_by_key(key); - /** - *

Return iterator to lower bound.

- * - *

Returns an iterator pointing to the first element in the container whose key is not considered to - * go before k (i.e., either it is equivalent or goes after).

- * - *

The function uses its internal comparison object (key_comp) to determine this, returning an - * iterator to the first element for which key_comp(k, element_key) would return false.

- * - *

If the {@link ITreeMap} class is instantiated with the default comparison type ({@link less}), - * the function returns an iterator to the first element whose key is not less than k

. - * - *

A similar member function, {@link upper_bound}, has the same behavior as {@link lower_bound}, except - * in the case that the {@link ITreeMap} contains an element with a key equivalent to k: In this - * case, {@link lower_bound} returns an iterator pointing to that element, whereas {@link upper_bound} - * returns an iterator pointing to the next element.

- * - * @param k Key to search for. - * - * @return An iterator to the the first element in the container whose key is not considered to go before - * k, or {@link ITreeMap.end} if all keys are considered to go before k. - */ - lower_bound(key: Key): MapIterator; - /** - *

Return iterator to upper bound.

- * - *

Returns an iterator pointing to the first element in the container whose key is considered to - * go after k

. - * - *

The function uses its internal comparison object (key_comp) to determine this, returning an - * iterator to the first element for which key_comp(k, element_key) would return true.

- * - *

If the {@link ITreeMap} class is instantiated with the default comparison type ({@link less}), - * the function returns an iterator to the first element whose key is greater than k

. - * - *

A similar member function, {@link lower_bound}, has the same behavior as {@link upper_bound}, except - * in the case that the map contains an element with a key equivalent to k: In this case - * {@link lower_bound} returns an iterator pointing to that element, whereas {@link upper_bound} returns an - * iterator pointing to the next element.

- * - * @param k Key to search for. - * - * @return An iterator to the the first element in the container whose key is considered to go after - * k, or {@link TreeMap.end end} if no keys are considered to go after k. - */ - upper_bound(key: Key): MapIterator; - /** - *

Get range of equal elements.

- * - *

Returns the bounds of a range that includes all the elements in the container which have a key - * equivalent to k

. - * - *

If no matches are found, the range returned has a length of zero, with both iterators pointing to - * the first element that has a key considered to go after k according to the container's internal - * comparison object (key_comp).

- * - *

Two keys are considered equivalent if the container's comparison object returns false reflexively - * (i.e., no matter the order in which the keys are passed as arguments).

- * - * @param k Key to search for. - * - * @return The function returns a {@link Pair}, whose member {@link Pair.first} is the lower bound of - * the range (the same as {@link lower_bound}), and {@link Pair.second} is the upper bound - * (the same as {@link upper_bound}). - */ - equal_range(key: Key): Pair, MapIterator>; - /** - *

Return key comparison function.

- * - *

Returns a references of the comparison function used by the container to compare keys.

- * - *

The comparison object of a {@link ITreeMap tree-map object} is set on - * {@link TreeMap.constructor construction}. Its type (Key) is the last parameter of the - * {@link ITreeMap.constructor constructors}. By default, this is a {@link less} function, which returns the same - * as operator<.

- * - *

This function determines the order of the elements in the container: it is a function pointer that takes - * two arguments of the same type as the element keys, and returns true if the first argument - * is considered to go before the second in the strict weak ordering it defines, and false otherwise. - *

- * - *

Two keys are considered equivalent if {@link key_comp} returns false reflexively (i.e., no - * matter the order in which the keys are passed as arguments).

- * - * @return The comparison function. - */ - key_comp(): (x: Key, y: Key) => boolean; - /** - *

Return value comparison function.

- * - *

Returns a comparison function that can be used to compare two elements to get whether the key of the first - * one goes before the second.

- * - *

The arguments taken by this function object are of member type std.Pair (defined in - * {@link ITreeMap}), but the mapped type (T) part of the value is not taken into consideration in this - * comparison.

- * - *

This comparison class returns true if the {@link Pair.first key} of the first argument - * is considered to go before that of the second (according to the strict weak ordering specified by the - * container's comparison function, {@link key_comp}), and false otherwise.

- * - * @return The comparison function for element values. - */ - value_comp(): (x: Pair, y: Pair) => boolean; - /** - * @inheritdoc - */ - is_equal_to(left: MapIterator, right: MapIterator): boolean; - /** - * @inheritdoc - */ - is_less(left: MapIterator, right: MapIterator): boolean; - } -} -declare namespace std.base { - /** - *

A common interface for tree-structured set.

- * - *

{@link ITreeSet TreeMultiSets} are containers that store elements following a specific order.

- * - *

In a {@link ITreeSet}, the value of an element also identifies it (the value is itself - * the key, of type T). The value of the elements in a {@link ITreeSet} cannot - * be modified once in the container (the elements are always const), but they can be inserted or removed - * from the

- * - *

Internally, the elements in a {@link ITreeSet TreeMultiSets} are always sorted following a strict - * weak ordering criterion indicated by its internal comparison method (of {@link IComparable.less less}).

- * - *

{@link ITreeSet} containers are generally slower than {@link IHashSet} containers - * to access individual elements by their key, but they allow the direct iteration on subsets based on - * their order.

- * - *

{@link ITreeSet TreeMultiSets} are typically implemented as binary search trees.

- * - *

- *

- * - *

Container properties

- *
- *
Associative
- *
- * Elements in associative containers are referenced by their key and not by their absolute - * position in the container. - *
- * - *
Ordered
- *
- * The elements in the container follow a strict order at all times. All inserted elements are - * given a position in this order. - *
- * - *
Set
- *
The value of an element is also the key used to identify it.
- *
- * - * @param Type of the elements. Each element in a {@link ITreeSet} container is also identified - * by this value (each value is itself also the element's key). - * - * @reference http://www.cplusplus.com/reference/set - * @author Jeongho Nam - */ - interface ITreeSet { - /** - *

Return comparison function.

- * - *

Returns a copy of the comparison function used by the container.

- * - *

By default, this is a {@link less} object, which returns the same as operator<.

- * - *

This object determines the order of the elements in the container: it is a function pointer or a function - * object that takes two arguments of the same type as the container elements, and returns true if - * the first argument is considered to go before the second in the strict weak ordering it - * defines, and false otherwise.

- * - *

Two elements of a {@link ITreeSet} are considered equivalent if {@link key_comp} returns false - * reflexively (i.e., no matter the order in which the elements are passed as arguments).

- * - *

In {@link ITreeSet} containers, the keys to sort the elements are the values (T) themselves, - * therefore {@link key_comp} and its sibling member function {@link value_comp} are equivalent.

- * - * @return The comparison function. - */ - key_comp(): (x: T, y: T) => boolean; - /** - *

Return comparison function.

- * - *

Returns a copy of the comparison function used by the container.

- * - *

By default, this is a {@link less} object, which returns the same as operator<.

- * - *

This object determines the order of the elements in the container: it is a function pointer or a function - * object that takes two arguments of the same type as the container elements, and returns true if - * the first argument is considered to go before the second in the strict weak ordering it - * defines, and false otherwise.

- * - *

Two elements of a {@link ITreeSet} are considered equivalent if {@link key_comp} returns false - * reflexively (i.e., no matter the order in which the elements are passed as arguments).

- * - *

In {@link ITreeSet} containers, the keys to sort the elements are the values (T) themselves, - * therefore {@link key_comp} and its sibling member function {@link value_comp} are equivalent.

- * - * @return The comparison function. - */ - value_comp(): (x: T, y: T) => boolean; - /** - *

Return iterator to lower bound.

- * - *

Returns an iterator pointing to the first element in the container which is not considered to - * go before val (i.e., either it is equivalent or goes after).

- * - *

The function uses its internal comparison object (key_comp) to determine this, returning an - * iterator to the first element for which key_comp(element,val) would return false.

- * - *

If the {@link ITreeSet} class is instantiated with the default comparison type ({@link less}), - * the function returns an iterator to the first element that is not less than val.

- - *

A similar member function, {@link upper_bound}, has the same behavior as {@link lower_bound}, except - * in the case that the {@link ITreeSet} contains elements equivalent to val: In this case - * {@link lower_bound} returns an iterator pointing to the first of such elements, whereas - * {@link upper_bound} returns an iterator pointing to the element following the last.

- * - * @param val Value to compare. - * - * @return An iterator to the the first element in the container which is not considered to go before - * val, or {@link ITreeSet.end} if all elements are considered to go before val. - */ - lower_bound(val: T): SetIterator; - /** - *

Return iterator to upper bound.

- * - *

Returns an iterator pointing to the first element in the container which is considered to go after - * val.

- - *

The function uses its internal comparison object (key_comp) to determine this, returning an - * iterator to the first element for which key_comp(val,element) would return true.

- - *

If the {@code ITreeSet} class is instantiated with the default comparison type (less), the - * function returns an iterator to the first element that is greater than val.

- * - *

A similar member function, {@link lower_bound}, has the same behavior as {@link upper_bound}, except - * in the case that the {@ITreeSet} contains elements equivalent to val: In this case - * {@link lower_bound} returns an iterator pointing to the first of such elements, whereas - * {@link upper_bound} returns an iterator pointing to the element following the last.

- * - * @param val Value to compare. - * - * @return An iterator to the the first element in the container which is considered to go after - * val, or {@link TreeSet.end end} if no elements are considered to go after val. - */ - upper_bound(val: T): SetIterator; - /** - *

Get range of equal elements.

- * - *

Returns the bounds of a range that includes all the elements in the container that are equivalent - * to val.

- * - *

If no matches are found, the range returned has a length of zero, with both iterators pointing to - * the first element that is considered to go after val according to the container's - * internal comparison object (key_comp).

- * - *

Two elements of a multiset are considered equivalent if the container's comparison object returns - * false reflexively (i.e., no matter the order in which the elements are passed as arguments).

- * - * @param key Value to search for. - * - * @return The function returns a {@link Pair}, whose member {@link Pair.first} is the lower bound of - * the range (the same as {@link lower_bound}), and {@link Pair.second} is the upper bound - * (the same as {@link upper_bound}). - */ - equal_range(val: T): Pair, SetIterator>; - } -} -declare namespace std.base { - /** - *

A red-black Tree storing {@link SetIterator SetIterators}.

- * - *

- *

- * - * @author Jeongho Nam - */ - class AtomicTree extends XTree> { - /** - * @hidden - */ - private set_; - /** - * @hidden - */ - private compare_; - /** - * Default Constructor. - */ - constructor(set: TreeSet | TreeMultiSet, compare?: (x: T, y: T) => boolean); - find(val: T): XTreeNode>; - find(it: SetIterator): XTreeNode>; - /** - * @hidden - */ - private find_by_val(val); - /** - *

Return iterator to lower bound.

- * - *

Returns an iterator pointing to the first element in the container which is not considered to - * go before val (i.e., either it is equivalent or goes after).

- * - *

The function uses its internal comparison object (key_comp) to determine this, returning an - * iterator to the first element for which key_comp(element,val) would return false.

- * - *

If the {@link ITreeSet} class is instantiated with the default comparison type ({@link less}), - * the function returns an iterator to the first element that is not less than val.

- - *

A similar member function, {@link upper_bound}, has the same behavior as {@link lower_bound}, except - * in the case that the {@link ITreeSet} contains elements equivalent to val: In this case - * {@link lower_bound} returns an iterator pointing to the first of such elements, whereas - * {@link upper_bound} returns an iterator pointing to the element following the last.

- * - * @param val Value to compare. - * - * @return An iterator to the the first element in the container which is not considered to go before - * val, or {@link ITreeSet.end} if all elements are considered to go before val. - */ - lower_bound(val: T): SetIterator; - /** - *

Return iterator to upper bound.

- * - *

Returns an iterator pointing to the first element in the container which is considered to go after - * val.

- - *

The function uses its internal comparison object (key_comp) to determine this, returning an - * iterator to the first element for which key_comp(val,element) would return true.

- - *

If the {@code ITreeSet} class is instantiated with the default comparison type (less), the - * function returns an iterator to the first element that is greater than val.

- * - *

A similar member function, {@link lower_bound}, has the same behavior as {@link upper_bound}, except - * in the case that the {@ITreeSet} contains elements equivalent to val: In this case - * {@link lower_bound} returns an iterator pointing to the first of such elements, whereas - * {@link upper_bound} returns an iterator pointing to the element following the last.

- * - * @param val Value to compare. - * - * @return An iterator to the the first element in the container which is considered to go after - * val, or {@link TreeSet.end end} if no elements are considered to go after val. - */ - upper_bound(val: T): SetIterator; - /** - *

Get range of equal elements.

- * - *

Returns the bounds of a range that includes all the elements in the container that are equivalent - * to val.

- * - *

If no matches are found, the range returned has a length of zero, with both iterators pointing to - * the first element that is considered to go after val according to the container's - * internal comparison object (key_comp).

- * - *

Two elements of a multiset are considered equivalent if the container's comparison object returns - * false reflexively (i.e., no matter the order in which the elements are passed as arguments).

- * - * @param key Value to search for. - * - * @return The function returns a {@link Pair}, whose member {@link Pair.first} is the lower bound of - * the range (the same as {@link lower_bound}), and {@link Pair.second} is the upper bound - * (the same as {@link upper_bound}). - */ - equal_range(val: T): Pair, SetIterator>; - /** - *

Return comparison function.

- * - *

Returns a copy of the comparison function used by the container.

- * - *

By default, this is a {@link less} object, which returns the same as operator<.

- * - *

This object determines the order of the elements in the container: it is a function pointer or a function - * object that takes two arguments of the same type as the container elements, and returns true if - * the first argument is considered to go before the second in the strict weak ordering it - * defines, and false otherwise.

- * - *

Two elements of a {@link ITreeSet} are considered equivalent if {@link key_comp} returns false - * reflexively (i.e., no matter the order in which the elements are passed as arguments).

- * - *

In {@link ITreeSet} containers, the keys to sort the elements are the values (T) themselves, - * therefore {@link key_comp} and its sibling member function {@link value_comp} are equivalent.

- * - * @return The comparison function. - */ - key_comp(): (x: T, y: T) => boolean; - /** - *

Return comparison function.

- * - *

Returns a copy of the comparison function used by the container.

- * - *

By default, this is a {@link less} object, which returns the same as operator<.

- * - *

This object determines the order of the elements in the container: it is a function pointer or a function - * object that takes two arguments of the same type as the container elements, and returns true if - * the first argument is considered to go before the second in the strict weak ordering it - * defines, and false otherwise.

- * - *

Two elements of a {@link ITreeSet} are considered equivalent if {@link key_comp} returns false - * reflexively (i.e., no matter the order in which the elements are passed as arguments).

- * - *

In {@link ITreeSet} containers, the keys to sort the elements are the values (T) themselves, - * therefore {@link key_comp} and its sibling member function {@link value_comp} are equivalent.

- * - * @return The comparison function. - */ - value_comp(): (x: T, y: T) => boolean; - /** - * @inheritdoc - */ - is_equal_to(left: SetIterator, right: SetIterator): boolean; - /** - * @inheritdoc - */ - is_less(left: SetIterator, right: SetIterator): boolean; - } -} -declare namespace std.base { - /** - *

An abstract unique-map.

- * - *

{@link UniqueMap UniqueMaps} are associative containers that store elements formed by a combination of a - * key value (Key) and a mapped value (T), and which allows for fast retrieval of - * individual elements based on their keys.

- * - *

In a {@link MapContainer}, the key values are generally used to uniquely identify the elements, - * while the mapped values store the content associated to this key. The types of key and - * mapped value may differ, and are grouped together in member type value_type, which is a - * {@link Pair} type combining both:

- * - *

typedef pair value_type;

- * - *

{@link UniqueMap} stores elements, keeps sequence and enables indexing by inserting elements into a - * {@link List} and registering {@link ListIterator iterators} of the {@link data_ list container} to an index - * table like {@link RBTree tree} or {@link HashBuckets hash-table}.

- * - *

- *

- * - *

Container properties

- *
- *
Associative
- *
- * Elements in associative containers are referenced by their key and not by their absolute position - * in the container. - *
- * - *
Map
- *
- * Each element associates a key to a mapped value: - * Keys are meant to identify the elements whose main content is the mapped value. - *
- * - *
Unique keys
- *
No two elements in the container can have equivalent keys.
- *
- * - * @param Type of the keys. Each element in a map is uniquely identified by its key value. - * @param Type of the mapped value. Each element in a map stores some data as its mapped value. - * - * @author Jeongho Nam - */ - abstract class UniqueMap extends MapContainer { - /** - * @inheritdoc - */ - count(key: Key): number; - /** - *

Get an element

- * - *

Returns a reference to the mapped value of the element identified with key.

- * - * @param key Key value of the element whose mapped value is accessed. - * - * @throw exception out of range - * - * @return A reference object of the mapped value (_Ty) - */ - get(key: Key): T; - /** - *

Set an item as the specified identifier.

- * - *

If the identifier is already in map, change value of the identifier. If not, then insert the object - * with the identifier.

- * - * @param key Key value of the element whose mapped value is accessed. - * @param val Value, the item. - */ - set(key: Key, val: T): void; - /** - * Construct and insert element. - * - * Inserts a new element in the {@link UniqueMap} if its *key* is unique. This new element is constructed in - * place using args as the arguments for the construction of a *value_type* (which is an object of a - * {@link Pair} type). - * - * The insertion only takes place if no other element in the container has a *key equivalent* to the one - * being emplaced (*keys* in a {@link UniqueMap} container are unique). - * - * If inserted, this effectively increases the container {@link size} by one. - * - * A similar member function exists, {@link insert}, which either copies or moves existing objects into the - * container. - * - * @param key The key used both to look up and to insert if not found. - * @param value Value, the item. - * - * @return If the function successfully inserts the element (because no equivalent element existed already in - * the {@link UniqueMap}), the function returns a {@link Pair} of an {@link MapIterator iterator} to - * the newly inserted element and a value of true. Otherwise, it returns an - * {@link MapIterator iterator} to the equivalent element within the container and a value of false. - */ - emplace(key: Key, value: T): Pair, boolean>; - /** - * Construct and insert element. - * - * Inserts a new element in the {@link UniqueMap} if its *key* is unique. This new element is constructed in - * place using args as the arguments for the construction of a *value_type* (which is an object of a - * {@link Pair} type). - * - * The insertion only takes place if no other element in the container has a *key equivalent* to the one - * being emplaced (*keys* in a {@link UniqueMap} container are unique). - * - * If inserted, this effectively increases the container {@link size} by one. - * - * A similar member function exists, {@link insert}, which either copies or moves existing objects into the - * container. - * - * @param pair A single argument of a {@link Pair} type with a value for the *key* as - * {@link Pair.first first} member, and a *value* for the mapped value as - * {@link Pair.second second}. - * - * @return If the function successfully inserts the element (because no equivalent element existed already in - * the {@link UniqueMap}), the function returns a {@link Pair} of an {@link MapIterator iterator} to - * the newly inserted element and a value of true. Otherwise, it returns an - * {@link MapIterator iterator} to the equivalent element within the container and a value of false. - */ - emplace(pair: Pair): Pair, boolean>; - /** - *

Insert an element.

- * - *

Extends the container by inserting new elements, effectively increasing the container {@link size} by - * one.

- * - *

Because element keys in a {@link UniqueMap} are unique, the insertion operation checks whether - * each inserted element has a key equivalent to the one of an element already in the container, and - * if so, the element is not inserted, returning an iterator to this existing element (if the function - * returns a value).

- * - *

For a similar container allowing for duplicate elements, see {@link MultiMap}.

- * - * @param pair A single argument of a {@link Pair} type with a value for the *key* as - * {@link Pair.first first} member, and a *value* for the mapped value as - * {@link Pair.second second}. - * - * @return A {@link Pair}, with its member {@link Pair.first} set to an iterator pointing to either the newly - * inserted element or to the element with an equivalent key in the {@link UniqueMap}. The - * {@link Pair.second} element in the {@link Pair} is set to true if a new element was inserted or - * false if an equivalent key already existed. - */ - insert(pair: Pair): Pair, boolean>; - /** - *

Insert an element.

- * - *

Extends the container by inserting a new element, effectively increasing the container size by the - * number of elements inserted.

- * - *

Because element keys in a {@link UniqueMap} are unique, the insertion operation checks whether - * each inserted element has a key equivalent to the one of an element already in the container, and - * if so, the element is not inserted, returning an iterator to this existing element (if the function - * returns a value).

- * - *

For a similar container allowing for duplicate elements, see {@link MultiMap}.

- * - * @param tuple Tuple represensts the {@link Pair} to be inserted as an element. - * - * @return A {@link Pair}, with its member {@link Pair.first} set to an iterator pointing to either the newly - * inserted element or to the element with an equivalent key in the {@link UniqueMap}. The - * {@link Pair.second} element in the {@link Pair} is set to true if a new element was inserted or - * false if an equivalent key already existed. - */ - insert(tuple: [L, U]): Pair, boolean>; - /** - * @inheritdoc - */ - insert(hint: MapIterator, pair: Pair): MapIterator; - /** - * @inheritdoc - */ - insert(hint: MapReverseIterator, pair: Pair): MapReverseIterator; - /** - * @inheritdoc - */ - insert(hint: MapIterator, tuple: [L, U]): MapIterator; - /** - * @inheritdoc - */ - insert(hint: MapReverseIterator, tuple: [L, U]): MapReverseIterator; - /** - * @inheritdoc - */ - insert>>(first: InputIterator, last: InputIterator): void; - /** - *

Insert or assign an element.

- * - *

Inserts an element or assigns to the current element if the key already exists.

- * - *

Because element keys in a {@link UniqueMap} are unique, the insertion operation checks whether - * each inserted element has a key equivalent to the one of an element already in the container, and - * if so, the element is assigned, returning an iterator to this existing element (if the function returns a - * value).

- * - *

For a similar container allowing for duplicate elements, see {@link MultiMap}.

- * - * @param key The key used both to look up and to insert if not found. - * @param value Value, the item. - * - * @return A {@link Pair}, with its member {@link Pair.first} set to an iterator pointing to either the newly - * inserted element or to the element with an equivalent key in the {@link UniqueMap}. The - * {@link Pair.second} element in the {@link Pair} is set to true if a new element was inserted or - * false if an equivalent key already existed so the value is assigned. - */ - insert_or_assign(key: Key, value: T): Pair, boolean>; - /** - *

Insert or assign an element.

- * - *

Inserts an element or assigns to the current element if the key already exists.

- * - *

Because element keys in a {@link UniqueMap} are unique, the insertion operation checks whether - * each inserted element has a key equivalent to the one of an element already in the container, and - * if so, the element is assigned, returning an iterator to this existing element (if the function returns a - * value).

- * - *

For a similar container allowing for duplicate elements, see {@link MultiMap}.

- * - * @param hint Hint for the position where the element can be inserted. - * @param key The key used both to look up and to insert if not found. - * @param value Value, the item. - * - * @return An iterator pointing to either the newly inserted element or to the element that already had an - * equivalent key in the {@link UniqueMap}. - */ - insert_or_assign(hint: MapIterator, key: Key, value: T): MapIterator; - /** - *

Insert or assign an element.

- * - *

Inserts an element or assigns to the current element if the key already exists.

- * - *

Because element keys in a {@link UniqueMap} are unique, the insertion operation checks whether - * each inserted element has a key equivalent to the one of an element already in the container, and - * if so, the element is assigned, returning an iterator to this existing element (if the function returns a - * value).

- * - *

For a similar container allowing for duplicate elements, see {@link MultiMap}.

- * - * @param hint Hint for the position where the element can be inserted. - * @param key The key used both to look up and to insert if not found. - * @param value Value, the item. - * - * @return An iterator pointing to either the newly inserted element or to the element that already had an - * equivalent key in the {@link UniqueMap}. - */ - insert_or_assign(hint: MapReverseIterator, key: Key, value: T): MapReverseIterator; - /** - * @hidden - */ - private insert_or_assign_with_key_value(key, value); - /** - * @hidden - */ - private insert_or_assign_with_hint(hint, key, value); - /** - *

Extract an element.

- * - *

Extracts the element pointed to by key and erases it from the {@link UniqueMap}.

- * - * @param key Key value of the element whose mapped value is accessed. - * - * @return A {@link Pair} containing the value pointed to by key. - */ - extract(key: Key): Pair; - /** - *

Extract an element.

- * - *

Extracts the element pointed to by key and erases it from the {@link UniqueMap}.

- * - * @param it An iterator pointing an element to extract. - * - * @return An iterator pointing to the element immediately following it prior to the element being - * erased. If no such element exists,returns {@link end end()}. - */ - extract(it: MapIterator): MapIterator; - /** - *

Extract an element.

- * - *

Extracts the element pointed to by key and erases it from the {@link UniqueMap}.

- * - * @param it An iterator pointing an element to extract. - * - * @return An iterator pointing to the element immediately following it prior to the element being - * erased. If no such element exists,returns {@link end end()}. - */ - extract(it: MapReverseIterator): MapReverseIterator; - /** - * @hidden - */ - private extract_by_key(key); - /** - * @hidden - */ - private extract_by_iterator(it); - /** - * @hidden - */ - private extract_by_reverse_iterator(it); - /** - * Merge two maps. - * - * Attempts to extract each element in *source* and insert it into this container. If there's an element in this - * container with key equivalent to the key of an element from *source*, tnen that element is not extracted from - * the *source*. Otherwise, no element with same key exists in this container, then that element will be - * transfered from the *source* to this container. - * - * @param source A {@link MapContainer map container} to transfer the elements from. - */ - merge(source: MapContainer): void; - } -} -declare namespace std.base { - /** - *

An abstract set.

- * - *

{@link SetContainer SetContainers} are containers that store elements allowing fast retrieval of - * individual elements based on their value.

- * - *

In an {@link SetContainer}, the value of an element is at the same time its key, used to uniquely - * identify it. Keys are immutable, therefore, the elements in an {@link SetContainer} cannot be modified - * once in the container - they can be inserted and removed, though.

- * - *

{@link SetContainer} stores elements, keeps sequence and enables indexing by inserting elements into a - * {@link List} and registering {@link ListIterator iterators} of the {@link data_ list container} to an index - * table like {@link RBTree tree} or {@link HashBuckets hash-table}.

- * - *

- *

- * - *

Container properties

- *
- *
Associative
- *
- * Elements in associative containers are referenced by their key and not by their absolute - * position in the container. - *
- * - *
Set
- *
The value of an element is also the key used to identify it.
- * - *
Unique keys
- *
No two elements in the container can have equivalent keys.
- *
- * - * @param Type of the elements. Each element in a {@link SetContainer} container is also identified - * by this value (each value is itself also the element's key). - * - * @author Jeongho Nam - */ - abstract class UniqueSet extends SetContainer { - /** - * @inheritdoc - */ - count(key: T): number; - /** - *

Insert an element.

- * - *

Extends the container by inserting new elements, effectively increasing the container {@link size} by - * the number of element inserted (zero or one).

- * - *

Because elements in a {@link UniqueSet UniqueSets} are unique, the insertion operation checks whether - * each inserted element is equivalent to an element already in the container, and if so, the element is not - * inserted, returning an iterator to this existing element (if the function returns a value).

- * - *

For a similar container allowing for duplicate elements, see {@link MultiSet}.

- * - * @param key Value to be inserted as an element. - * - * @return A {@link Pair}, with its member {@link Pair.first} set to an iterator pointing to either the newly - * inserted element or to the equivalent element already in the {@link UniqueSet}. The - * {@link Pair.second} element in the {@link Pair} is set to true if a new element was inserted or - * false if an equivalent element already existed. - */ - insert(val: T): Pair, boolean>; - /** - * @inheritdoc - */ - insert(hint: SetIterator, val: T): SetIterator; - /** - * @inheritdoc - */ - insert(hint: SetReverseIterator, val: T): SetReverseIterator; - /** - * @inheritdoc - */ - insert>(begin: InputIterator, end: InputIterator): void; - /** - *

Extract an element.

- * - *

Extracts the element pointed to by val and erases it from the {@link UniqueSet}.

- * - * @param val Value to be extracted. - * - * @return A value. - */ - extract(val: T): T; - /** - *

Extract an element.

- * - *

Extracts the element pointed to by key and erases it from the {@link UniqueMap}.

- * - * @param it An iterator pointing an element to extract. - * - * @return An iterator pointing to the element immediately following it prior to the element being - * erased. If no such element exists,returns {@link end end()}. - */ - extract(it: SetIterator): SetIterator; - /** - *

Extract an element.

- * - *

Extracts the element pointed to by key and erases it from the {@link UniqueMap}.

- * - * @param it An iterator pointing an element to extract. - * - * @return An iterator pointing to the element immediately following it prior to the element being - * erased. If no such element exists,returns {@link end end()}. - */ - extract(it: SetReverseIterator): SetReverseIterator; - /** - * @hidden - */ - private extract_by_key(val); - /** - * @hidden - */ - private extract_by_iterator(it); - /** - * @hidden - */ - private extract_by_reverse_iterator(it); - /** - * Merge two sets. - * - * Attempts to extract each element in *source* and insert it into this container. If there's an element in this - * container with key equivalent to the key of an element from *source*, tnen that element is not extracted from - * the *source*. Otherwise, no element with same key exists in this container, then that element will be - * transfered from the *source* to this container. - * - * @param source A {@link SetContainer set container} to transfer the elements from. - */ - merge(source: SetContainer): void; - } -} -declare namespace std.base { - /** - *

A node in an XTree.

- * - * @param Type of elements. - * - * @inventor Rudolf Bayer - * @author Migrated by Jeongho Nam - */ - class XTreeNode { - /** - * Parent of the node. - */ - parent: XTreeNode; - /** - * Left child in the node. - */ - left: XTreeNode; - /** - * Right child in the node. - */ - right: XTreeNode; - /** - * Value stored in the node. - */ - value: T; - /** - * Color of the node. - */ - color: Color; - /** - * Construct from value and color of node. - * - * @param value Value to be stored in. - * @param color Color of the node, red or black. - */ - constructor(value: T, color: Color); - /** - * Get grand-parent. - */ - readonly grand_parent: XTreeNode; - /** - * Get sibling, opposite side node in same parent. - */ - readonly sibling: XTreeNode; - /** - * Get uncle, parent's sibling. - */ - readonly uncle: XTreeNode; - } -} -declare namespace std.Deque { - type iterator = std.DequeIterator; - type reverse_iterator = std.DequeReverseIterator; -} -declare namespace std { - /** - *

Double ended queue.

- * - *

{@link Deque} (usually pronounced like "deck") is an irregular acronym of - * double-ended queue. Double-ended queues are sequence containers with dynamic sizes that can be - * expanded or contracted on both ends (either its front or its back).

- * - *

Specific libraries may implement deques in different ways, generally as some form of dynamic array. But in any - * case, they allow for the individual elements to be accessed directly through random access iterators, with storage - * handled automatically by expanding and contracting the container as needed.

- * - *

Therefore, they provide a functionality similar to vectors, but with efficient insertion and deletion of - * elements also at the beginning of the sequence, and not only at its end. But, unlike {@link Vector Vectors}, - * {@link Deque Deques} are not guaranteed to store all its elements in contiguous storage locations: accessing - * elements in a deque by offsetting a pointer to another element causes undefined behavior.

- * - *

Both {@link Vector}s and {@link Deque}s provide a very similar interface and can be used for similar purposes, - * but internally both work in quite different ways: While {@link Vector}s use a single array that needs to be - * occasionally reallocated for growth, the elements of a {@link Deque} can be scattered in different chunks of - * storage, with the container keeping the necessary information internally to provide direct access to any of its - * elements in constant time and with a uniform sequential interface (through iterators). Therefore, - * {@link Deque Deques} are a little more complex internally than {@link Vector}s, but this allows them to grow more - * efficiently under certain circumstances, especially with very long sequences, where reallocations become more - * expensive.

- * - *

For operations that involve frequent insertion or removals of elements at positions other than the beginning or - * the end, {@link Deque Deques} perform worse and have less consistent iterators and references than - * {@link List Lists}.

- * - *

- * - *

- * - *

Container properties

- *
- *
Sequence
- *
Elements in sequence containers are ordered in a strict linear sequence. Individual elements - * are accessed by their position in this sequence.
- * - *
Dynamic array
- *
Generally implemented as a dynamic array, it allows direct access to any element in the - * sequence and provides relatively fast addition/removal of elements at the beginning or the end - * of the sequence.
- *
- * - * @param Type of the elements. - * - * @reference http://www.cplusplus.com/reference/deque/deque/ - * @author Jeongho Nam - */ - class Deque extends base.Container implements base.IArrayContainer, base.IDequeContainer { - /** - * @hidden - */ - private static readonly ROW; - /** - * @hidden - */ - private static readonly MIN_CAPACITY; - /** - * @hidden - */ - private matrix_; - /** - * @hidden - */ - private size_; - /** - * @hidden - */ - private capacity_; - /** - * @hidden - */ - private get_col_size(); - /** - * @hidden - */ - private end_; - /** - * @hidden - */ - private rend_; - /** - *

Default Constructor.

- * - *

Constructs an empty container, with no elements.

- */ - constructor(); - /** - *

Initializer list Constructor.

- * - *

Constructs a container with a copy of each of the elements in array, in the same order.

- * - * @param array An array containing elements to be copied and contained. - */ - constructor(items: Array); - /** - *

Fill Constructor.

- * - *

Constructs a container with n elements. Each element is a copy of val (if provided).

- * - * @param n Initial container size (i.e., the number of elements in the container at construction). - * @param val Value to fill the container with. Each of the n elements in the container is - * initialized to a copy of this value. - */ - constructor(size: number, val: T); - /** - *

Copy Constructor.

- * - *

Constructs a container with a copy of each of the elements in container, in the same order.

- * - * @param container Another container object of the same type (with the same class template - * arguments T), whose contents are either copied or acquired. - */ - constructor(container: Deque); - /** - *

Range Constructor.

- * - *

Constructs a container with as many elements as the range (begin, end), with each - * element emplace-constructed from its corresponding element in that range, in the same order.

- * - * @param begin Input interator of the initial position in a sequence. - * @param end Input interator of the final position in a sequence. - */ - constructor(begin: Iterator, end: Iterator); - /** - * @inheritdoc - */ - assign>(begin: InputIterator, end: InputIterator): void; - /** - * @inheritdoc - */ - assign(n: number, val: T): void; - /** - * @inheritdoc - */ - reserve(capacity: number): void; - /** - * @inheritdoc - */ - clear(): void; - /** - * @inheritdoc - */ - begin(): DequeIterator; - /** - * @inheritdoc - */ - end(): DequeIterator; - /** - * @inheritdoc - */ - rbegin(): DequeReverseIterator; - /** - * @inheritdoc - */ - rend(): DequeReverseIterator; - /** - * @inheritdoc - */ - size(): number; - /** - * @inheritdoc - */ - empty(): boolean; - /** - * @inheritdoc - */ - capacity(): number; - /** - * @inheritdoc - */ - at(index: number): T; - /** - * @inheritdoc - */ - set(index: number, val: T): void; - /** - * @inheritdoc - */ - front(): T; - /** - * @inheritdoc - */ - back(): T; - /** - // Fetch row and column's index. - /** - * @hidden - */ - private fetch_index(index); - /** - * @inheritdoc - */ - push(...items: T[]): number; - /** - * @inheritdoc - */ - push_front(val: T): void; - /** - * @inheritdoc - */ - push_back(val: T): void; - /** - * @inheritdoc - */ - pop_front(): void; - /** - * @inheritdoc - */ - pop_back(): void; - /** - * @inheritdoc - */ - insert(position: DequeIterator, val: T): DequeIterator; - /** - * @inheritdoc - */ - insert(position: DequeIterator, n: number, val: T): DequeIterator; - /** - * @inheritdoc - */ - insert>(position: DequeIterator, begin: InputIterator, end: InputIterator): DequeIterator; - /** - * @inheritdoc - */ - insert(position: DequeReverseIterator, val: T): DequeReverseIterator; - /** - * @inheritdoc - */ - insert(position: DequeReverseIterator, n: number, val: T): DequeReverseIterator; - /** - * @inheritdoc - */ - insert>(position: DequeReverseIterator, begin: InputIterator, end: InputIterator): DequeReverseIterator; - /** - * @hidden - */ - private insert_by_val(position, val); - /** - * @hidden - */ - protected _Insert_by_repeating_val(position: DequeIterator, n: number, val: T): DequeIterator; - /** - * @hidden - */ - protected _Insert_by_range>(position: DequeIterator, begin: InputIterator, end: InputIterator): DequeIterator; - /** - * @hidden - */ - private insert_by_items(position, items); - /** - * @inheritdoc - */ - erase(position: DequeIterator): DequeIterator; - /** - * @inheritdoc - */ - erase(first: DequeIterator, last: DequeIterator): DequeIterator; - /** - * @inheritdoc - */ - erase(position: DequeReverseIterator): DequeReverseIterator; - /** - * @inheritdoc - */ - erase(first: DequeReverseIterator, last: DequeReverseIterator): DequeReverseIterator; - /** - * @hidden - */ - protected _Erase_by_range(first: DequeIterator, last: DequeIterator): DequeIterator; - /** - *

Swap content.

- * - *

Exchanges the content of the container by the content of obj, which is another - * {@link Deque container} object with same type of elements. Sizes and container type may differ.

- * - *

After the call to this member function, the elements in this container are those which were in obj - * before the call, and the elements of obj are those which were in this. All iterators, references and - * pointers remain valid for the swapped objects.

- * - *

Notice that a non-member function exists with the same name, {@link std.swap swap}, overloading that - * algorithm with an optimization that behaves like this member function.

- * - * @param obj Another {@link Deque container} of the same type of elements (i.e., instantiated - * with the same template parameter, T) whose content is swapped with that of this - * {@link container Deque}. - */ - swap(obj: Deque): void; - /** - * @inheritdoc - */ - swap(obj: base.IContainer): void; - } -} -declare namespace std { - /** - *

An iterator of {@link Deque}.

- * - *

- * - *

- * - * @author Jeongho Nam - */ - class DequeIterator extends Iterator implements base.IArrayIterator { - /** - * Sequence number of iterator in the source {@link Deque}. - */ - private index_; - /** - *

Construct from the source {@link Deque container}.

- * - *

Note

- *

Do not create the iterator directly, by yourself.

- *

Use {@link Deque.begin begin()}, {@link Deque.end end()} in {@link Deque container} instead.

- * - * @param source The source {@link Deque container} to reference. - * @param index Sequence number of the element in the source {@link Deque}. - */ - constructor(source: Deque, index: number); - /** - * @hidden - */ - private readonly deque; - /** - * @inheritdoc - */ - /** - * Set value of the iterator is pointing to. - * - * @param val Value to set. - */ - value: T; - /** - * @inheritdoc - */ - readonly index: number; - /** - * @inheritdoc - */ - prev(): DequeIterator; - /** - * @inheritdoc - */ - next(): DequeIterator; - /** - * @inheritdoc - */ - advance(n: number): DequeIterator; - /** - * @inheritdoc - */ - equals(obj: DequeIterator): boolean; - /** - * @inheritdoc - */ - swap(obj: DequeIterator): void; - } -} -declare namespace std { - /** - *

A reverse-iterator of Deque.

- * - *

- * - *

- * - * @param Type of the elements. - * - * @author Jeongho Nam - */ - class DequeReverseIterator extends ReverseIterator, DequeReverseIterator> implements base.IArrayIterator { - /** - * Construct from base iterator. - * - * @param base A reference of the base iterator, which iterates in the opposite direction. - */ - constructor(base: DequeIterator); - /** - * @hidden - */ - protected _Create_neighbor(base: DequeIterator): DequeReverseIterator; - /** - * @inheritdoc - */ - /** - * Set value of the iterator is pointing to. - * - * @param val Value to set. - */ - value: T; - /** - * Get index. - */ - readonly index: number; - } -} -declare namespace std { - /** - *

Function handling termination on exception

- * - *

Calls the current terminate handler.

- * - *

By default, the terminate handler calls abort. But this behavior can be redefined by calling - * {@link set_terminate}.

- * - *

This function is automatically called when no catch handler can be found for a thrown exception, - * or for some other exceptional circumstance that makes impossible to continue the exception handling process.

- * - *

This function is provided so that the terminate handler can be explicitly called by a program that needs to - * abnormally terminate, and works even if {@link set_terminate} has not been used to set a custom terminate handler - * (calling abort in this case).

- */ - function terminate(): void; - /** - *

Set terminate handler function.

- * - *

A terminate handler function is a function automatically called when the exception handling process has - * to be abandoned for some reason. This happens when no catch handler can be found for a thrown exception, or for - * some other exceptional circumstance that makes impossible to continue the exception handling process.

- * - *

Before this function is called by the program for the first time, the default behavior is to call abort.

- * - *

A program may explicitly call the current terminate handler function by calling {@link terminate}.

- * - * @param f Function that takes no parameters and returns no value (void). - */ - function set_terminate(f: () => void): void; - /** - *

Get terminate handler function.

- * - *

The terminate handler function is automatically called when no catch handler can be found - * for a thrown exception, or for some other exceptional circumstance that makes impossible to continue the exception - * handling process.

- * - *

If no such function has been set by a previous call to {@link set_terminate}, the function returns a - * null-pointer.

- * - * @return If {@link set_terminate} has previously been called by the program, the function returns the current - * terminate handler function. Otherwise, it returns a null-pointer. - */ - function get_terminate(): () => void; - /** - *

Standard exception class.

- * - *

Base class for standard exceptions.

- * - *

All objects thrown by components of the standard library are derived from this class. - * Therefore, all standard exceptions can be caught by catching this type by reference.

- * - *

- *

- * - * @reference http://www.cplusplus.com/reference/exception/exception - * @author Jeongho Nam - */ - class Exception extends Error { - /** - * A message representing specification about the Exception. - */ - private description; - /** - * Default Constructor. - */ - constructor(); - /** - *

Construct from a message.

- * - * @param message A message representing specification about the Exception. - */ - constructor(message: string); - /** - *

Get string identifying exception.

- *

Returns a string that may be used to identify the exception.

- * - *

The particular representation pointed by the returned value is implementation-defined. - * As a virtual function, derived classes may redefine this function so that specify value are - * returned.

- */ - what(): string; - /** - * @inheritdoc - */ - readonly message: string; - /** - * @inheritdoc - */ - readonly name: string; - } - /** - *

Logic error exception.

- * - *

This class defines the type of objects thrown as exceptions to report errors in the internal - * logical of the program, such as violation of logical preconditions or class invariants.

- * - *

These errors are presumably detectable before the program executes.

- * - *

It is used as a base class for several logical error exceptions.

- * - *

- *

- * - * @reference http://www.cplusplus.com/reference/stdexcept/logic_error - * @author Jeongho Nam - */ - class LogicError extends Exception { - /** - *

Construct from a message.

- * - * @param message A message representing specification about the Exception. - */ - constructor(message: string); - } - /** - *

Domain error exception.

- * - *

This class defines the type of objects thrown as exceptions to report domain errors.

- * - *

Generally, the domain of a mathematical function is the subset of values that it is defined for. - * For example, the square root function is only defined for non-negative numbers. Thus, a negative number - * for such a function would qualify as a domain error.

- * - *

No component of the standard library throws exceptions of this type. It is designed as a standard - * exception to be thrown by programs.

- * - *

- *

- * - * @reference http://www.cplusplus.com/reference/stdexcept/domain_error - * @author Jeongho Nam - */ - class DomainError extends LogicError { - /** - *

Construct from a message.

- * - * @param message A message representing specification about the Exception. - */ - constructor(message: string); - } - /** - *

Invalid argument exception.

- * - *

This class defines the type of objects thrown as exceptions to report an invalid argument.

- * - *

It is a standard exception that can be thrown by programs. Some components of the standard library - * also throw exceptions of this type to signal invalid arguments.

- * - *

- *

- * - * @reference http://www.cplusplus.com/reference/stdexcept/invalid_argument - * @author Jeongho Nam - */ - class InvalidArgument extends LogicError { - /** - *

Construct from a message.

- * - * @param message A message representing specification about the Exception. - */ - constructor(message: string); - } - /** - *

Length error exception.

- * - *

This class defines the type of objects thrown as exceptions to report a length error.

- * - *

It is a standard exception that can be thrown by programs. Some components of the standard library, - * such as vector and string also throw exceptions of this type to signal errors resizing.

- * - *

- *

- * - * @reference http://www.cplusplus.com/reference/stdexcept/length_error - * @author Jeongho Nam - */ - class LengthError extends LogicError { - /** - *

Construct from a message.

- * - * @param message A message representing specification about the Exception. - */ - constructor(message: string); - } - /** - *

Out-of-range exception.

- * - *

This class defines the type of objects thrown as exceptions to report an out-of-range error.

- * - *

It is a standard exception that can be thrown by programs. Some components of the standard library, - * such as vector, deque, string and bitset also throw exceptions of this type to signal arguments - * out of range.

- * - *

- *

- * - * @reference http://www.cplusplus.com/reference/stdexcept/out_of_range - * @author Jeongho Nam - */ - class OutOfRange extends LogicError { - /** - *

Construct from a message.

- * - * @param message A message representing specification about the Exception. - */ - constructor(message: string); - } - /** - *

Runtime error exception.

- * - *

This class defines the type of objects thrown as exceptions to report errors that can only be - * detected during runtime.

- * - *

It is used as a base class for several runtime error exceptions.

- * - *

- *

- * - * @reference http://www.cplusplus.com/reference/stdexcept/runtime_error - * @author Jeongho Nam - */ - class RuntimeError extends Exception { - /** - *

Construct from a message.

- * - * @param message A message representing specification about the Exception. - */ - constructor(message: string); - } - /** - *

Overflow error exception.

- * - *

This class defines the type of objects thrown as exceptions to arithmetic overflow errors.

- * - *

It is a standard exception that can be thrown by programs. Some components of the standard library - * also throw exceptions of this type to signal range errors.

- * - *

- *

- * - * @reference http://www.cplusplus.com/reference/stdexcept/overflow_error - * @author Jeongho Nam - */ - class OverflowError extends RuntimeError { - /** - *

Construct from a message.

- * - * @param message A message representing specification about the Exception. - */ - constructor(message: string); - } - /** - *

Underflow error exception.

- * - *

This class defines the type of objects thrown as exceptions to arithmetic underflow errors.

- * - *

No component of the standard library throws exceptions of this type. It is designed as a standard - * exception to be thrown by programs.

- * - *

- *

- * - * @reference http://www.cplusplus.com/reference/stdexcept/underflow_error - * @author Jeongho Nam - */ - class UnderflowError extends RuntimeError { - /** - *

Construct from a message.

- * - * @param message A message representing specification about the Exception. - */ - constructor(message: string); - } - /** - *

Range error exception.

- * - *

This class defines the type of objects thrown as exceptions to report range errors in internal - * computations.

- * - *

It is a standard exception that can be thrown by programs. Some components of the standard library - * also throw exceptions of this type to signal range errors.

- * - *

- *

- * - * @reference http://www.cplusplus.com/reference/stdexcept/range_error - * @author Jeongho Nam - */ - class RangeError extends RuntimeError { - /** - *

Construct from a message.

- * - * @param message A message representing specification about the Exception. - */ - constructor(message: string); - } -} -declare namespace std { - /** - *

Function object class for equality comparison.

- * - *

Binary function object class whose call returns whether its two arguments compare equal (as returned by - * operator ==).

- * - *

Generically, function objects are instances of a class with member function {@link IComparable.equal_to equal_to} - * defined. This member function allows the object to be used with the same syntax as a function call.

- * - * @param x First element to compare. - * @param y Second element to compare. - * - * @return Whether the arguments are equal. - */ - function equal_to(x: T, y: T): boolean; - /** - *

Function object class for non-equality comparison.

- * - *

Binary function object class whose call returns whether its two arguments compare not equal (as returned - * by operator operator!=).

- * - *

Generically, function objects are instances of a class with member function {@link IComparable.equal_to equal_to} - * defined. This member function allows the object to be used with the same syntax as a function call.

- * - * @param x First element to compare. - * @param y Second element to compare. - * - * @return Whether the arguments are not equal. - */ - function not_equal_to(x: T, y: T): boolean; - /** - *

Function for less-than inequality comparison.

- * - *

Binary function returns whether the its first argument compares less than the second.

- * - *

Generically, function objects are instances of a class with member function {@link IComparable.less less} - * defined. If an object doesn't have the method, then its own uid will be used to compare insteadly. - * This member function allows the object to be used with the same syntax as a function call.

- * - *

Objects of this class can be used on standard algorithms such as {@link sort sort()}, - * {@link merge merge()} or {@link TreeMap.lower_bound lower_bound()}.

- * - * @param Type of arguments to compare by the function call. The type shall supporrt the operation - * operator<() or method {@link IComparable.less less}. - * - * @param x First element, the standard of comparison. - * @param y Second element compare with the first. - * - * @return Whether the first parameter is less than the second. - */ - function less(x: T, y: T): boolean; - /** - *

Function object class for less-than-or-equal-to comparison.

- * - *

Binary function object class whose call returns whether the its first argument compares {@link less less than} or - * {@link equal_to equal to} the second (as returned by operator <=).

- * - *

Generically, function objects are instances of a class with member function {@link IComparable.less less} - * and {@link IComparable.equal_to equal_to} defined. This member function allows the object to be used with the same - * syntax as a function call.

- * - * @param x First element, the standard of comparison. - * @param y Second element compare with the first. - * - * @return Whether the x is {@link less less than} or {@link equal_to equal to} the y. - */ - function less_equal(x: T, y: T): boolean; - /** - *

Function for greater-than inequality comparison.

- * - *

Binary function returns whether the its first argument compares greater than the second.

- * - *

Generically, function objects are instances of a class with member function {@link less} and - * {@link equal_to equal_to()} defined. If an object doesn't have those methods, then its own uid will be used - * to compare insteadly. This member function allows the object to be used with the same syntax as a function - * call.

- * - *

Objects of this class can be used on standard algorithms such as {@link sort sort()}, - * {@link merge merge()} or {@link TreeMap.lower_bound lower_bound()}.

- * - * @param Type of arguments to compare by the function call. The type shall supporrt the operation - * operator>() or method {@link IComparable.greater greater}. - * - * @return Whether the x is greater than the y. - */ - function greater(x: T, y: T): boolean; - /** - *

Function object class for greater-than-or-equal-to comparison.

- * - *

Binary function object class whose call returns whether the its first argument compares - * {@link greater greater than} or {@link equal_to equal to} the second (as returned by operator >=).

- * - *

Generically, function objects are instances of a class with member function {@link IComparable.less less} - * defined. If an object doesn't have the method, then its own uid will be used to compare insteadly. - * This member function allows the object to be used with the same syntax as a function call.

- * - * @param x First element, the standard of comparison. - * @param y Second element compare with the first. - * - * @return Whether the x is {@link greater greater than} or {@link equal_to equal to} the y. - */ - function greater_equal(x: T, y: T): boolean; - /** - *

Logical AND function object class.

- * - *

Binary function object class whose call returns the result of the logical "and" operation between its two - * arguments (as returned by operator &&).

- * - *

Generically, function objects are instances of a class with member function operator() defined. This member - * function allows the object to be used with the same syntax as a function call.

- * - * @param x First element. - * @param y Second element. - * - * @return Result of logical AND operation. - */ - function logical_and(x: T, y: T): boolean; - /** - *

Logical OR function object class.

- * - *

Binary function object class whose call returns the result of the logical "or" operation between its two - * arguments (as returned by operator ||).

- * - *

Generically, function objects are instances of a class with member function operator() defined. This member - * function allows the object to be used with the same syntax as a function call.

- * - * @param x First element. - * @param y Second element. - * - * @return Result of logical OR operation. - */ - function logical_or(x: T, y: T): boolean; - /** - *

Logical NOT function object class.

- * - *

Unary function object class whose call returns the result of the logical "not" operation on its argument - * (as returned by operator !).

- * - *

Generically, function objects are instances of a class with member function operator() defined. This member - * function allows the object to be used with the same syntax as a function call.

- * - * @param x Target element. - * - * @return Result of logical NOT operation. - */ - function logical_not(x: T): boolean; - /** - *

Bitwise AND function object class.

- * - *

Binary function object class whose call returns the result of applying the bitwise "and" operation between - * its two arguments (as returned by operator &).

- * - * @param x First element. - * @param y Second element. - * - * @return Result of bitwise AND operation. - */ - function bit_and(x: number, y: number): number; - /** - *

Bitwise OR function object class.

- * - *

Binary function object class whose call returns the result of applying the bitwise "and" operation between - * its two arguments (as returned by operator &).

- * - * @param x First element. - * @param y Second element. - * - * @return Result of bitwise OR operation. - */ - function bit_or(x: number, y: number): number; - /** - *

Bitwise XOR function object class.

- * - *

Binary function object class whose call returns the result of applying the bitwise "exclusive or" - * operation between its two arguments (as returned by operator ^).

- * - * @param x First element. - * @param y Second element. - * - * @return Result of bitwise XOR operation. - */ - function bit_xor(x: number, y: number): number; - /** - *

Default hash function for number.

- * - *

Unary function that defines the default hash function used by the standard library.

- * - *

The functional call returns a hash value of its argument: A hash value is a value that depends solely on - * its argument, returning always the same value for the same argument (for a given execution of a program). The - * value returned shall have a small likelihood of being the same as the one returned for a different argument. - *

- * - * @param val Value to be hashed. - * - * @return Returns a hash value for its argument, as a value of type number. The number is an unsigned integer. - */ - function hash(val: number): number; - /** - *

Default hash function for string.

- * - *

Unary function that defines the default hash function used by the standard library.

- * - *

The functional call returns a hash value of its argument: A hash value is a value that depends solely on - * its argument, returning always the same value for the same argument (for a given execution of a program). The - * value returned shall have a small likelihood of being the same as the one returned for a different argument. - *

- * - * @param str A string to be hashed. - * - * @return Returns a hash value for its argument, as a value of type number. The number is an unsigned integer. - */ - function hash(str: string): number; - /** - *

Default hash function for Object.

- * - *

Unary function that defines the default hash function used by the standard library.

- * - *

The functional call returns a hash value of its argument: A hash value is a value that depends solely on - * its argument, returning always the same value for the same argument (for a given execution of a program). The - * value returned shall have a small likelihood of being the same as the one returned for a different argument. - *

- * - *

The default {@link hash} function of Object returns a value returned from {@link hash hash(number)} with - * an unique id of each Object. If you want to specify {@link hash} function of a specific class, then - * define a member function public hash(): number in the class.

- * - * @param obj Object to be hashed. - * - * @return Returns a hash value for its argument, as a value of type number. The number is an unsigned integer. - */ - function hash(obj: Object): number; - /** - *

Exchange contents of {@link IContainers containers}.

- * - *

The contents of container left are exchanged with those of right. Both container objects must have - * same type of elements (same template parameters), although sizes may differ.

- * - *

After the call to this member function, the elements in left are those which were in right before - * the call, and the elements of right are those which were in left. All iterators, references and - * pointers remain valid for the swapped objects.

- * - *

This is an overload of the generic algorithm swap that improves its performance by mutually transferring - * ownership over their assets to the other container (i.e., the containers exchange references to their data, without - * actually performing any element copy or movement): It behaves as if left. - * {@link IContainer.swap swap}(right) was called.

- * - * @param left A {@link IContainer container} to swap its contents. - * @param right A {@link IContainer container} to swap its contents. - */ - function swap(left: base.IContainer, right: base.IContainer): void; - /** - *

Exchange contents of queues.

- * - *

Exchanges the contents of left and right.

- * - * @param left A {@link Queue} container of the same type. Size may differ. - * @param right A {@link Queue} container of the same type. Size may differ. - */ - function swap(left: Queue, right: Queue): void; - /** - *

Exchange contents of {@link PriorityQueue PriorityQueues}.

- * - *

Exchanges the contents of left and right.

- * - * @param left A {@link PriorityQueue} container of the same type. Size may differ. - * @param right A {@link PriorityQueue} container of the same type. Size may differ. - */ - function swap(left: PriorityQueue, right: PriorityQueue): void; - /** - *

Exchange contents of {@link Stack Stacks}.

- * - *

Exchanges the contents of left and right.

- * - * @param left A {@link Stack} container of the same type. Size may differ. - * @param right A {@link Stack} container of the same type. Size may differ. - */ - function swap(left: Stack, right: Stack): void; - /** - *

Exchanges the contents of two {@link UniqueMap unique maps}.

- * - *

The contents of container left are exchanged with those of right. Both container objects must - * be of the same type (same template parameters), although sizes may differ.

- * - *

After the call to this member function, the elements in left are those which were in right - * before the call, and the elements of right are those which were in left. All iterators, references - * and pointers remain valid for the swapped objects.

- * - *

This is an overload of the generic algorithm swap that improves its performance by mutually transferring - * ownership over their assets to the other container (i.e., the containers exchange references to their data, - * without actually performing any element copy or movement): It behaves as if - * left.{@link UniqueMap.swap swap}(right) was called.

- * - * @param left An {@link UniqueMap unique map} to swap its conents. - * @param right An {@link UniqueMap unique map} to swap its conents. - */ - function swap(left: base.UniqueMap, right: base.UniqueMap): void; - /** - *

Exchanges the contents of two {@link MultiMap multi maps}.

- * - *

The contents of container left are exchanged with those of right. Both container objects must - * be of the same type (same template parameters), although sizes may differ.

- * - *

After the call to this member function, the elements in left are those which were in right - * before the call, and the elements of right are those which were in left. All iterators, references - * and pointers remain valid for the swapped objects.

- * - *

This is an overload of the generic algorithm swap that improves its performance by mutually transferring - * ownership over their assets to the other container (i.e., the containers exchange references to their data, - * without actually performing any element copy or movement): It behaves as if - * left.{@link MultiMap.swap swap}(right) was called.

- * - * @param left A {@link MultiMap multi map} to swap its conents. - * @param right A {@link MultiMap multi map} to swap its conents. - */ - function swap(left: base.MultiMap, right: base.MultiMap): void; -} -declare namespace std { - /** - *

Bind function arguments.

- * - *

Returns a function object based on fn, but with its arguments bound to args.

- * - *

Each argument may either be bound to a value or be a {@link placeholders placeholder}:

- *
    - *
  • If bound to a value, calling the returned function object will always use that value as argument.
  • - *
  • - * If a {@link placeholders placeholder}, calling the returned function object forwards an argument passed to the - * call (the one whose order number is specified by the placeholder). - *
  • - *
- * - *

Calling the returned object returns the same type as fn.

- * - * @param fn A function object, pointer to function or pointer to member. - * @param args List of arguments to bind: either values, or {@link placeholders}. - * - * @return A function object that, when called, calls fn with its arguments bound to args. If fn is - * a pointer to member, the first argument expected by the returned function is an object of the class fn - * is a member. - */ - function bind(fn: (...args: any[]) => Ret, ...args: any[]): (...args: any[]) => Ret; - /** - *

Bind function arguments.

- * - *

Returns a function object based on fn, but with its arguments bound to args.

- * - *

Each argument may either be bound to a value or be a {@link placeholders placeholder}:

- *
    - *
  • If bound to a value, calling the returned function object will always use that value as argument.
  • - *
  • - * If a {@link placeholders placeholder}, calling the returned function object forwards an argument passed to the - * call (the one whose order number is specified by the placeholder). - *
  • - *
- * - *

Calling the returned object returns the same type as fn.

- * - * @param fn A function object, pointer to function or pointer to member. - * @param thisArg This argument, owner object of the member method fn. - * @param args List of arguments to bind: either values, or {@link placeholders}. - * - * @return A function object that, when called, calls fn with its arguments bound to args. If fn is - * a pointer to member, the first argument expected by the returned function is an object of the class fn - * is a member. - */ - function bind(fn: (...args: any[]) => Ret, thisArg: T, ...args: any[]): (...args: any[]) => Ret; -} -/** - *

Bind argument placeholders.

- * - *
- * - *

When the function object returned by bind is called, an argument with placeholder {@link _1} is replaced by the - * first argument in the call, {@link _2} is replaced by the second argument in the call, and so on... For example:

- * - * - * let vec: Vector = new Vector(); - * - * let bind = std.bind(Vector.insert, _1, vec.end(), _2, _3); - * bind.apply(vec, 5, 1); // vec.insert(vec.end(), 5, 1); - * // [1, 1, 1, 1, 1] - * - * - *

When a call to {@link bind} is used as a subexpression in another call to bind, the {@link placeholders} - * are relative to the outermost {@link bind} expression.

- * - * @reference http://www.cplusplus.com/reference/functional/placeholders/ - * @author Jeongho Nam - */ -declare namespace std.placeholders { - /** - * @hidden - */ - class PlaceHolder { - private index_; - constructor(index: number); - readonly index: number; - } - /** - * Replaced by the first argument in the function call. - */ - const _1: PlaceHolder; - /** - * Replaced by the second argument in the function call. - */ - const _2: PlaceHolder; - /** - * Replaced by the third argument in the function call. - */ - const _3: PlaceHolder; - const _4: PlaceHolder; - const _5: PlaceHolder; - const _6: PlaceHolder; - const _7: PlaceHolder; - const _8: PlaceHolder; - const _9: PlaceHolder; - const _10: PlaceHolder; - const _11: PlaceHolder; - const _12: PlaceHolder; - const _13: PlaceHolder; - const _14: PlaceHolder; - const _15: PlaceHolder; - const _16: PlaceHolder; - const _17: PlaceHolder; - const _18: PlaceHolder; - const _19: PlaceHolder; - const _20: PlaceHolder; -} -declare namespace std.HashMap { - type iterator = std.MapIterator; - type reverse_iterator = std.MapReverseIterator; -} -declare namespace std { - /** - *

Hashed, unordered map.

- * - *

{@link HashMap}s are associative containers that store elements formed by the combination of a key value - * and a mapped value, and which allows for fast retrieval of individual elements based on their keys. - *

- * - *

In an {@link HashMap}, the key value is generally used to uniquely identify the element, while the - * mapped value is an object with the content associated to this key. Types of key and - * mapped value may differ.

- * - *

Internally, the elements in the {@link HashMap} are not sorted in any particular order with respect to either - * their key or mapped values, but organized into buckets depending on their hash values to allow - * for fast access to individual elements directly by their key values (with a constant average time complexity - * on average).

- * - *

{@link HashMap} containers are faster than {@link TreeMap} containers to access individual elements by their - * key, although they are generally less efficient for range iteration through a subset of their elements.

- * - *

- * - *

- * - *

Container properties

- *
- *
Associative
- *
Elements in associative containers are referenced by their key and not by their absolute - * position in the container.
- * - *
Hashed
- *
Hashed containers organize their elements using hash tables that allow for fast access to elements - * by their key.
- * - *
Map
- *
Each element associates a key to a mapped value: - * Keys are meant to identify the elements whose main content is the mapped value.
- * - *
Unique keys
- *
No two elements in the container can have equivalent keys.
- *
- * - * @param Type of the key values. - * Each element in an {@link HashMap} is uniquely identified by its key value. - * @param Type of the mapped value. - * Each element in an {@link HashMap} is used to store some data as its mapped value. - * - * @reference http://www.cplusplus.com/reference/unordered_map/unordered_map - * @author Jeongho Nam - */ - class HashMap extends base.UniqueMap implements base.IHashMap { - /** - * @hidden - */ - private hash_buckets_; - /** - * Default Constructor. - */ - constructor(); - /** - * Construct from elements. - */ - constructor(items: Pair[]); - /** - * Contruct from tuples. - * - * @param array Tuples to be contained. - */ - constructor(array: [Key, T][]); - /** - * Copy Constructor. - */ - constructor(container: HashMap); - /** - * Construct from range iterators. - */ - constructor(begin: Iterator>, end: Iterator>); - /** - * @inheritdoc - */ - clear(): void; - /** - * @inheritdoc - */ - find(key: Key): MapIterator; - /** - * @inheritdoc - */ - begin(): MapIterator; - /** - * @inheritdoc - */ - begin(index: number): MapIterator; - /** - * @inheritdoc - */ - end(): MapIterator; - /** - * @inheritdoc - */ - end(index: number): MapIterator; - /** - * @inheritdoc - */ - rbegin(): MapReverseIterator; - /** - * @inheritdoc - */ - rbegin(index: number): MapReverseIterator; - /** - * @inheritdoc - */ - rend(): MapReverseIterator; - /** - * @inheritdoc - */ - rend(index: number): MapReverseIterator; - /** - * @inheritdoc - */ - bucket_count(): number; - /** - * @inheritdoc - */ - bucket_size(index: number): number; - /** - * @inheritdoc - */ - max_load_factor(): number; - /** - * @inheritdoc - */ - max_load_factor(z: number): void; - /** - * @inheritdoc - */ - bucket(key: Key): number; - /** - * @inheritdoc - */ - reserve(n: number): void; - /** - * @inheritdoc - */ - rehash(n: number): void; - /** - * @hidden - */ - protected _Insert_by_pair(pair: Pair): any; - /** - * @hidden - */ - protected _Insert_by_hint(hint: MapIterator, pair: Pair): MapIterator; - /** - * @hidden - */ - protected _Insert_by_range>>(first: InputIterator, last: InputIterator): void; - /** - * @inheritdoc - */ - protected _Handle_insert(first: MapIterator, last: MapIterator): void; - /** - * @inheritdoc - */ - protected _Handle_erase(first: MapIterator, last: MapIterator): void; - /** - *

Swap content.

- * - *

Exchanges the content of the container by the content of obj, which is another - * {@link HashMap map} of the same type. Sizes abd container type may differ.

- * - *

After the call to this member function, the elements in this container are those which were - * in obj before the call, and the elements of obj are those which were in this. All - * iterators, references and pointers remain valid for the swapped objects.

- * - *

Notice that a non-member function exists with the same name, {@link std.swap swap}, overloading that - * algorithm with an optimization that behaves like this member function.

- * - * @param obj Another {@link HashMap map container} of the same type of elements as this (i.e., - * with the same template parameters, Key and T) whose content is swapped - * with that of this {@link HashMap container}. - */ - swap(obj: HashMap): void; - /** - * @inheritdoc - */ - swap(obj: base.IContainer>): void; - } -} -declare namespace std.HashMultiMap { - type iterator = std.MapIterator; - type reverse_iterator = std.MapReverseIterator; -} -declare namespace std { - /** - *

Hashed, unordered Multimap.

- * - *

{@link HashMultiMap}s are associative containers that store elements formed by the combination of - * a key value and a mapped value, much like {@link HashMultiMap} containers, but allowing - * different elements to have equivalent keys.

- * - *

In an {@link HashMultiMap}, the key value is generally used to uniquely identify the - * element, while the mapped value is an object with the content associated to this key. - * Types of key and mapped value may differ.

- * - *

Internally, the elements in the {@link HashMultiMap} are not sorted in any particular order with - * respect to either their key or mapped values, but organized into buckets depending on - * their hash values to allow for fast access to individual elements directly by their key values - * (with a constant average time complexity on average).

- * - *

Elements with equivalent keys are grouped together in the same bucket and in such a way that - * an iterator can iterate through all of them. Iterators in the container are doubly linked iterators.

- * - *

- * - *

- * - *

Container properties

- *
- *
Associative
- *
Elements in associative containers are referenced by their key and not by their absolute - * position in the container.
- * - *
Hashed
- *
Hashed containers organize their elements using hash tables that allow for fast access to elements - * by their key.
- * - *
Map
- *
Each element associates a key to a mapped value: - * Keys are meant to identify the elements whose main content is the mapped value.
- * - *
Multiple equivalent keys
- *
The container can hold multiple elements with equivalent keys.
- *
- * - * @param Type of the key values. - * Each element in an {@link HashMultiMap} is identified by a key value. - * @param Type of the mapped value. - * Each element in an {@link HashMultiMap} is used to store some data as its mapped value. - * - * @reference http://www.cplusplus.com/reference/unordered_map/unordered_multimap - * @author Jeongho Nam - */ - class HashMultiMap extends base.MultiMap { - /** - * @hidden - */ - private hash_buckets_; - /** - * Default Constructor. - */ - constructor(); - /** - * Construct from elements. - */ - constructor(items: Pair[]); - /** - * Contruct from tuples. - * - * @param array Tuples to be contained. - */ - constructor(array: [Key, T][]); - /** - * Copy Constructor. - */ - constructor(container: HashMultiMap); - /** - * Construct from range iterators. - */ - constructor(begin: Iterator>, end: Iterator>); - /** - * @inheritdoc - */ - clear(): void; - /** - * @inheritdoc - */ - find(key: Key): MapIterator; - /** - * @inheritdoc - */ - count(key: Key): number; - /** - * @inheritdoc - */ - begin(): MapIterator; - /** - * @inheritdoc - */ - begin(index: number): MapIterator; - /** - * @inheritdoc - */ - end(): MapIterator; - /** - * @inheritdoc - */ - end(index: number): MapIterator; - /** - * @inheritdoc - */ - rbegin(): MapReverseIterator; - /** - * @inheritdoc - */ - rbegin(index: number): MapReverseIterator; - /** - * @inheritdoc - */ - rend(): MapReverseIterator; - /** - * @inheritdoc - */ - rend(index: number): MapReverseIterator; - /** - * @inheritdoc - */ - bucket_count(): number; - /** - * @inheritdoc - */ - bucket_size(n: number): number; - /** - * @inheritdoc - */ - max_load_factor(): number; - /** - * @inheritdoc - */ - max_load_factor(z: number): void; - /** - * @inheritdoc - */ - bucket(key: Key): number; - /** - * @inheritdoc - */ - reserve(n: number): void; - /** - * @inheritdoc - */ - rehash(n: number): void; - /** - * @hidden - */ - protected _Insert_by_pair(pair: Pair): any; - /** - * @hidden - */ - protected _Insert_by_hint(hint: MapIterator, pair: Pair): MapIterator; - /** - * @hidden - */ - protected _Insert_by_range>>(first: InputIterator, last: InputIterator): void; - /** - * @inheritdoc - */ - protected _Handle_insert(first: MapIterator, last: MapIterator): void; - /** - * @inheritdoc - */ - protected _Handle_erase(first: MapIterator, last: MapIterator): void; - /** - *

Swap content.

- * - *

Exchanges the content of the container by the content of obj, which is another - * {@link HashMultiMap map} of the same type. Sizes abd container type may differ.

- * - *

After the call to this member function, the elements in this container are those which were - * in obj before the call, and the elements of obj are those which were in this. All - * iterators, references and pointers remain valid for the swapped objects.

- * - *

Notice that a non-member function exists with the same name, {@link std.swap swap}, overloading that - * algorithm with an optimization that behaves like this member function.

- * - * @param obj Another {@link HashMultiMap map container} of the same type of elements as this (i.e., - * with the same template parameters, Key and T) whose content is swapped - * with that of this {@link HashMultiMap container}. - */ - swap(obj: HashMultiMap): void; - /** - * @inheritdoc - */ - swap(obj: base.IContainer>): void; - } -} -declare namespace std.HashMultiSet { - type iterator = std.SetIterator; - type reverse_iterator = std.SetReverseIterator; -} -declare namespace std { - /** - *

Hashed, unordered Multiset.

- * - *

{@link HashMultiSet HashMultiSets} are containers that store elements in no particular order, allowing fast - * retrieval of individual elements based on their value, much like {@link HashMultiSet} containers, - * but allowing different elements to have equivalent values.

- * - *

In an {@link HashMultiSet}, the value of an element is at the same time its key, used to - * identify it. Keys are immutable, therefore, the elements in an {@link HashMultiSet} cannot be - * modified once in the container - they can be inserted and removed, though.

- * - *

Internally, the elements in the {@link HashMultiSet} are not sorted in any particular, but - * organized into buckets depending on their hash values to allow for fast access to individual - * elements directly by their values (with a constant average time complexity on average).

- * - *

Elements with equivalent values are grouped together in the same bucket and in such a way that an - * iterator can iterate through all of them. Iterators in the container are doubly linked iterators.

- * - *

- *

- * - *

Container properties

- *
- *
Associative
- *
Elements in associative containers are referenced by their key and not by their absolute - * position in the container.
- * - *
Hashed
- *
Hashed containers organize their elements using hash tables that allow for fast access to elements - * by their key.
- * - *
Set
- *
The value of an element is also the key used to identify it.
- * - *
Multiple equivalent keys
- *
The container can hold multiple elements with equivalent keys.
- *
- * - * @param Type of the elements. - * Each element in an {@link UnorderedMultiSet} is also identified by this value.. - * - * @reference http://www.cplusplus.com/reference/unordered_set/unordered_multiset - * @author Jeongho Nam - */ - class HashMultiSet extends base.MultiSet { - /** - * @hidden - */ - private hash_buckets_; - /** - * Default Constructor. - */ - constructor(); - /** - * Construct from elements. - */ - constructor(items: T[]); - /** - * Copy Constructor. - */ - constructor(container: HashMultiSet); - /** - * Construct from range iterators. - */ - constructor(begin: Iterator, end: Iterator); - /** - * @inheritdoc - */ - clear(): void; - /** - * @inheritdoc - */ - find(key: T): SetIterator; - /** - * @inheritdoc - */ - count(key: T): number; - /** - * @inheritdoc - */ - begin(): SetIterator; - /** - * @inheritdoc - */ - begin(index: number): SetIterator; - /** - * @inheritdoc - */ - end(): SetIterator; - /** - * @inheritdoc - */ - end(index: number): SetIterator; - /** - * @inheritdoc - */ - rbegin(): SetReverseIterator; - /** - * @inheritdoc - */ - rbegin(index: number): SetReverseIterator; - /** - * @inheritdoc - */ - rend(): SetReverseIterator; - /** - * @inheritdoc - */ - rend(index: number): SetReverseIterator; - /** - * @inheritdoc - */ - bucket_count(): number; - /** - * @inheritdoc - */ - bucket_size(n: number): number; - /** - * @inheritdoc - */ - max_load_factor(): number; - /** - * @inheritdoc - */ - max_load_factor(z: number): void; - /** - * @inheritdoc - */ - bucket(key: T): number; - /** - * @inheritdoc - */ - reserve(n: number): void; - /** - * @inheritdoc - */ - rehash(n: number): void; - /** - * @hidden - */ - protected _Insert_by_val(val: T): any; - /** - * @hidden - */ - protected _Insert_by_hint(hint: SetIterator, val: T): SetIterator; - /** - * @hidden - */ - protected _Insert_by_range>(first: InputIterator, last: InputIterator): void; - /** - * @inheritdoc - */ - protected _Handle_insert(first: SetIterator, last: SetIterator): void; - /** - * @inheritdoc - */ - protected _Handle_erase(first: SetIterator, last: SetIterator): void; - /** - *

Swap content.

- * - *

Exchanges the content of the container by the content of obj, which is another - * {@link HashMultiSet set} of the same type. Sizes abd container type may differ.

- * - *

After the call to this member function, the elements in this container are those which were - * in obj before the call, and the elements of obj are those which were in this. All - * iterators, references and pointers remain valid for the swapped objects.

- * - *

Notice that a non-member function exists with the same name, {@link std.swap swap}, overloading that - * algorithm with an optimization that behaves like this member function.

- * - * @param obj Another {@link HashMultiSet set container} of the same type of elements as this (i.e., - * with the same template parameters, Key and T) whose content is swapped - * with that of this {@link HashMultiSet container}. - */ - swap(obj: HashMultiSet): void; - /** - * @inheritdoc - */ - swap(obj: base.IContainer): void; - } -} -declare namespace std.HashSet { - type iterator = std.SetIterator; - type reverse_iterator = std.SetReverseIterator; -} -declare namespace std { - /** - *

Hashed, unordered set.

- * - *

{@link HashSet}s are containers that store unique elements in no particular order, and which - * allow for fast retrieval of individual elements based on their value.

- * - *

In an {@link HashSet}, the value of an element is at the same time its key, that - * identifies it uniquely. Keys are immutable, therefore, the elements in an {@link HashSet} cannot be - * modified once in the container - they can be inserted and removed, though.

- * - *

Internally, the elements in the {@link HashSet} are not sorted in any particular order, but - * organized into buckets depending on their hash values to allow for fast access to individual elements - * directly by their values (with a constant average time complexity on average).

- * - *

{@link HashSet} containers are faster than {@link TreeSet} containers to access individual - * elements by their key, although they are generally less efficient for range iteration through a - * subset of their elements.

- * - *

- *

- * - *

Container properties

- *
- *
Associative
- *
Elements in associative containers are referenced by their key and not by their absolute - * position in the container.
- * - *
Hashed
- *
Hashed containers organize their elements using hash tables that allow for fast access to elements - * by their key.
- * - *
Set
- *
The value of an element is also the key used to identify it.
- * - *
Unique keys
- *
No two elements in the container can have equivalent keys.
- *
- * - * @param Type of the elements. - * Each element in an {@link HashSet} is also uniquely identified by this value. - * - * @reference http://www.cplusplus.com/reference/unordered_set/unordered_set - * @author Jeongho Nam - */ - class HashSet extends base.UniqueSet implements base.IHashSet { - /** - * @hidden - */ - private hash_buckets_; - /** - * Default Constructor. - */ - constructor(); - /** - * Construct from elements. - */ - constructor(items: T[]); - /** - * Copy Constructor. - */ - constructor(container: HashSet); - /** - * Construct from range iterators. - */ - constructor(begin: Iterator, end: Iterator); - /** - * @inheritdoc - */ - clear(): void; - /** - * @inheritdoc - */ - find(key: T): SetIterator; - /** - * @inheritdoc - */ - begin(): SetIterator; - /** - * @inheritdoc - */ - begin(index: number): SetIterator; - /** - * @inheritdoc - */ - end(): SetIterator; - /** - * @inheritdoc - */ - end(index: number): SetIterator; - /** - * @inheritdoc - */ - rbegin(): SetReverseIterator; - /** - * @inheritdoc - */ - rbegin(index: number): SetReverseIterator; - /** - * @inheritdoc - */ - rend(): SetReverseIterator; - /** - * @inheritdoc - */ - rend(index: number): SetReverseIterator; - /** - * @inheritdoc - */ - bucket_count(): number; - /** - * @inheritdoc - */ - bucket_size(n: number): number; - /** - * @inheritdoc - */ - max_load_factor(): number; - /** - * @inheritdoc - */ - max_load_factor(z: number): void; - /** - * @inheritdoc - */ - bucket(key: T): number; - /** - * @inheritdoc - */ - reserve(n: number): void; - /** - * @inheritdoc - */ - rehash(n: number): void; - /** - * @hidden - */ - protected _Insert_by_val(val: T): any; - /** - * @hidden - */ - protected _Insert_by_hint(hint: SetIterator, val: T): SetIterator; - /** - * @hidden - */ - protected _Insert_by_range>(first: InputIterator, last: InputIterator): void; - /** - * @inheritdoc - */ - protected _Handle_insert(first: SetIterator, last: SetIterator): void; - /** - * @inheritdoc - */ - protected _Handle_erase(first: SetIterator, last: SetIterator): void; - /** - *

Swap content.

- * - *

Exchanges the content of the container by the content of obj, which is another - * {@link HashSet set} of the same type. Sizes abd container type may differ.

- * - *

After the call to this member function, the elements in this container are those which were - * in obj before the call, and the elements of obj are those which were in this. All - * iterators, references and pointers remain valid for the swapped objects.

- * - *

Notice that a non-member function exists with the same name, {@link std.swap swap}, overloading that - * algorithm with an optimization that behaves like this member function.

- * - * @param obj Another {@link HashSet set container} of the same type of elements as this (i.e., - * with the same template parameters, Key and T) whose content is swapped - * with that of this {@link HashSet container}. - */ - swap(obj: HashSet): void; - /** - * @inheritdoc - */ - swap(obj: base.IContainer): void; - } -} -declare namespace std { - /** - *

Comparable instance.

- * - *

{@link IComparable} is a common interface for objects who can compare each other.

- * - * @reference https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html - * @author Jeongho Nam - */ - interface IComparable extends Object { - /** - *

Indicates whether some other object is "equal to" this one.

- * - *

The {@link equal_to} method implements an equivalence relation on non-null object references:

- * - *
    - *
  • - * It is reflexive: for any non-null reference value x, x.equal_to(x) - * should return true. - *
  • - *
  • - * It is symmetric: for any non-null reference values x and y, - * x.equal_to(y) should return true if and only if y.equal_to(x) - * returns true.
  • - *
  • - * It is transitive: for any non-null reference values x, y, and - * z, if x.equal_to(y) returns true and y.equal_to(z) - * returns true, then x.equal_to(z) should return true. - *
  • - *
  • - * It is consistent: for any non-null reference values x and y, multiple - * invocations of x.equal_to(y) consistently return true or consistently return - * false, provided no information used in equal_to comparisons on the objects is modified. - *
  • - *
  • - * For any non-null reference value x, x.equal_to(null) should return - * false. - *
  • - *
- * - *

The {@link equal_to} method for interface {@link IComparable} implements the most discriminating possible - * equivalence relation on objects; that is, for any non-null reference values x and - * y, this method returns true if and only if x and y - * refer to the same object (x == y has the value true).

- * - *

Note that it is generally necessary to override the {@link hash_code} method whenever this method is - * overridden, so as to maintain the general contract for the {@link hash_code} method, which states that - * equal objects must have equal hash codes.

- * - *
    - *
  • {@link IComparable.equal_to} is called by {@link std.equal_to}.
  • - *
- * - * @param obj the reference object with which to compare. - * - * @return true if this object is the same as the obj argument; false otherwise. - */ - equals(obj: T): boolean; - /** - *

Less-than inequality comparison.

- * - *

Binary method returns whether the the instance compares less than the obj.

- * - *
    - *
  • - * {@link IComparable.less} is called by {@link std.less}. Also, this method can be used on standard - * algorithms such as {@link sort sort()}, {@link merge merge()} or - * {@link TreeMap.lower_bound lower_bound()}. - *
  • - *
- * - * @param obj the reference object with which to compare. - * - * @return Whether the first parameter is less than the second. - */ - less(obj: T): boolean; - /** - *

Issue a hash code.

- * - *

Returns a hash code value for the object. This method is supported for the benefit of hash tables such - * as those provided by hash containers; {@link HashSet}, {@link HashMap}, {@link MultiHashSet} and - * {@link MultiHashMap}.

- * - *

As much as is reasonably practical, the {@link hash_code} method defined by interface - * {@link IComparable} does return distinct integers for distinct objects. (This is typically implemented by - * converting the internal address of the object into an integer, but this implementation technique is not - * required by the JavaScript programming language.)

- * - *
    - *
  • - * {@link IComparable.hash_code} is called by {@link std.hash_code}. If you want to keep basically - * provided hash function, then returns {@link std.Hash.code}; return std.Hash.code(this); - *
  • - *
- * - * @return An hash code who represents the object. - */ - hashCode?(): number; - } -} -declare namespace std.List { - type iterator = std.ListIterator; - type reverse_iterator = std.ListReverseIterator; -} -declare namespace std { - /** - *

Doubly linked list.

- * - *

{@link List}s are sequence containers that allow constant time insert and erase operations anywhere within the - * sequence, and iteration in both directions.

- * - *

List containers are implemented as doubly-linked lists; Doubly linked lists can store each of the elements they - * contain in different and unrelated storage locations. The ordering is kept internally by the association to each - * element of a link to the element preceding it and a link to the element following it.

- * - *

Compared to other base standard sequence containers (array, vector and deque), lists perform generally better - * in inserting, extracting and moving elements in any position within the container for which an iterator has already - * been obtained, and therefore also in algorithms that make intensive use of these, like sorting algorithms.

- * - *

The main drawback of lists and forward_lists compared to these other sequence containers is that they lack - * direct access to the elements by their position; For example, to access the sixth element in a list, one has to - * iterate from a known position (like the beginning or the end) to that position, which takes linear time in the - * distance between these. They also consume some extra memory to keep the linking information associated to each - * element (which may be an important factor for large lists of small-sized elements).

- * - *

- * - *

- * - *

Container properties

- *
- *
Sequence
- *
Elements in sequence containers are ordered in a strict linear sequence. Individual elements are accessed by - * their position in this sequence.
- * - *
Doubly-linked list
- *
Each element keeps information on how to locate the next and the previous elements, allowing constant time - * insert and erase operations before or after a specific element (even of entire ranges), but no direct random - * access.
- *
- * - * @param Type of the elements. - * - * @reference http://www.cplusplus.com/reference/list/list/ - * @author Jeongho Nam - */ - class List extends base.ListContainer> { - private rend_; - /** - *

Default Constructor.

- * - *

Constructs an empty container, with no elements.

- */ - constructor(); - /** - *

Initializer list Constructor.

- * - *

Constructs a container with a copy of each of the elements in array, in the same order.

- * - * @param array An array containing elements to be copied and contained. - */ - constructor(items: Array); - /** - *

Fill Constructor.

- * - *

Constructs a container with n elements. Each element is a copy of val (if provided).

- * - * @param n Initial container size (i.e., the number of elements in the container at construction). - * @param val Value to fill the container with. Each of the n elements in the container is - * initialized to a copy of this value. - */ - constructor(size: number, val: T); - /** - *

Copy Constructor.

- * - *

Constructs a container with a copy of each of the elements in container, in the same order.

- * - * @param container Another container object of the same type (with the same class template - * arguments T), whose contents are either copied or acquired. - */ - constructor(container: List); - /** - *

Range Constructor.

- * - *

Constructs a container with as many elements as the range (begin, end), with each - * element emplace-constructed from its corresponding element in that range, in the same order.

- * - * @param begin Input interator of the initial position in a sequence. - * @param end Input interator of the final position in a sequence. - */ - constructor(begin: Iterator, end: Iterator); - /** - * @hidden - */ - protected _Create_iterator(prev: ListIterator, next: ListIterator, val: T): ListIterator; - /** - * @hidden - */ - protected _Set_begin(it: ListIterator): void; - /** - * @inheritdoc - */ - assign(n: number, val: T): void; - /** - * @inheritdoc - */ - assign>(begin: InputIterator, end: InputIterator): void; - /** - * @inheritdoc - */ - rbegin(): ListReverseIterator; - /** - * @inheritdoc - */ - rend(): ListReverseIterator; - /** - * @inheritdoc - */ - front(): T; - /** - * @inheritdoc - */ - back(): T; - /** - *

Insert an element.

- * - *

The container is extended by inserting a new element before the element at the specified - * position. This effectively increases the {@link List.size List size} by the amount of elements - * inserted.

- * - *

Unlike other standard sequence containers, {@link List} is specifically designed to be efficient - * inserting and removing elements in any position, even in the middle of the sequence.

- * - * @param position Position in the container where the new element is inserted. - * {@link iterator}> is a member type, defined as a - * {@link ListIterator bidirectional iterator} type that points to elements. - * @param val Value to be inserted as an element. - * - * @return An iterator that points to the newly inserted element; val. - */ - insert(position: ListIterator, val: T): ListIterator; - /** - *

Insert elements by repeated filling.

- * - *

The container is extended by inserting a new element before the element at the specified - * position. This effectively increases the {@link List.size List size} by the amount of elements - * inserted.

- * - *

Unlike other standard sequence containers, {@link List} is specifically designed to be efficient - * inserting and removing elements in any position, even in the middle of the sequence.

- * - * @param position Position in the container where the new elements are inserted. The {@link iterator} is a - * member type, defined as a {@link ListIterator bidirectional iterator} type that points to - * elements. - * @param size Number of elements to insert. - * @param val Value to be inserted as an element. - * - * @return An iterator that points to the first of the newly inserted elements. - */ - insert(position: ListIterator, size: number, val: T): ListIterator; - /** - *

Insert elements by range iterators.

- * - *

The container is extended by inserting a new element before the element at the specified - * position. This effectively increases the {@link List.size List size} by the amount of elements - * inserted.

- * - *

Unlike other standard sequence containers, {@link List} is specifically designed to be efficient - * inserting and removing elements in any position, even in the middle of the sequence.

- * - * @param position Position in the container where the new elements are inserted. The {@link iterator} is a - * member type, defined as a {@link ListIterator bidirectional iterator} type that points to - * elements. - * @param begin An iterator specifying range of the begining element. - * @param end An iterator specifying range of the ending element. - * - * @return An iterator that points to the first of the newly inserted elements. - */ - insert>(position: ListIterator, begin: InputIterator, end: InputIterator): ListIterator; - /** - *

Insert an element.

- * - *

The container is extended by inserting a new element before the element at the specified - * position. This effectively increases the {@link List.size List size} by the amount of elements - * inserted.

- * - *

Unlike other standard sequence containers, {@link List} is specifically designed to be efficient - * inserting and removing elements in any position, even in the middle of the sequence.

- * - * @param position Position in the container where the new element is inserted. - * {@link iterator}> is a member type, defined as a - * {@link ListReverseIterator bidirectional iterator} type that points to elements. - * @param val Value to be inserted as an element. - * - * @return An iterator that points to the newly inserted element; val. - */ - insert(position: ListReverseIterator, val: T): ListReverseIterator; - /** - *

Insert elements by repeated filling.

- * - *

The container is extended by inserting a new element before the element at the specified - * position. This effectively increases the {@link List.size List size} by the amount of elements - * inserted.

- * - *

Unlike other standard sequence containers, {@link List} is specifically designed to be efficient - * inserting and removing elements in any position, even in the middle of the sequence.

- * - * @param position Position in the container where the new elements are inserted. The {@link iterator} is a - * member type, defined as a {@link ListReverseIterator bidirectional iterator} type that points to - * elements. - * @param size Number of elements to insert. - * @param val Value to be inserted as an element. - * - * @return An iterator that points to the first of the newly inserted elements. - */ - insert(position: ListReverseIterator, size: number, val: T): ListReverseIterator; - /** - *

Insert elements by range iterators.

- * - *

The container is extended by inserting a new element before the element at the specified - * position. This effectively increases the {@link List.size List size} by the amount of elements - * inserted.

- * - *

Unlike other standard sequence containers, {@link List} is specifically designed to be efficient - * inserting and removing elements in any position, even in the middle of the sequence.

- * - * @param position Position in the container where the new elements are inserted. The {@link iterator} is a - * member type, defined as a {@link ListReverseIterator bidirectional iterator} type that points to - * elements. - * @param begin An iterator specifying range of the begining element. - * @param end An iterator specifying range of the ending element. - * - * @return An iterator that points to the first of the newly inserted elements. - */ - insert>(position: ListReverseIterator, begin: InputIterator, end: InputIterator): ListReverseIterator; - /** - *

Erase an element.

- * - *

Removes from the {@link List} either a single element; position.

- * - *

This effectively reduces the container size by the number of element removed.

- * - *

Unlike other standard sequence containers, {@link List} objects are specifically designed to be - * efficient inserting and removing elements in any position, even in the middle of the sequence.

- * - * @param position Iterator pointing to a single element to be removed from the {@link List}. - * - * @return An iterator pointing to the element that followed the last element erased by the function call. - * This is the {@link end end()} if the operation erased the last element in the sequence. - */ - erase(position: ListIterator): ListIterator; - /** - *

Erase elements.

- * - *

Removes from the {@link List} container a range of elements.

- * - *

This effectively reduces the container {@link size} by the number of elements removed.

- * - *

Unlike other standard sequence containers, {@link List} objects are specifically designed to be - * efficient inserting and removing elements in any position, even in the middle of the sequence.

- * - * @param begin An iterator specifying a range of beginning to erase. - * @param end An iterator specifying a range of end to erase. - * - * @return An iterator pointing to the element that followed the last element erased by the function call. - * This is the {@link end end()} if the operation erased the last element in the sequence. - */ - erase(begin: ListIterator, end: ListIterator): ListIterator; - /** - *

Erase an element.

- * - *

Removes from the {@link List} either a single element; position.

- * - *

This effectively reduces the container size by the number of element removed.

- * - *

Unlike other standard sequence containers, {@link List} objects are specifically designed to be - * efficient inserting and removing elements in any position, even in the middle of the sequence.

- * - * @param position Iterator pointing to a single element to be removed from the {@link List}. - * - * @return An iterator pointing to the element that followed the last element erased by the function call. - * This is the {@link rend rend()} if the operation erased the last element in the sequence. - */ - erase(position: ListReverseIterator): ListReverseIterator; - /** - *

Erase elements.

- * - *

Removes from the {@link List} container a range of elements.

- * - *

This effectively reduces the container {@link size} by the number of elements removed.

- * - *

Unlike other standard sequence containers, {@link List} objects are specifically designed to be - * efficient inserting and removing elements in any position, even in the middle of the sequence.

- * - * @param begin An iterator specifying a range of beginning to erase. - * @param end An iterator specifying a range of end to erase. - * - * @return An iterator pointing to the element that followed the last element erased by the function call. - * This is the {@link rend rend()} if the operation erased the last element in the sequence. - */ - erase(begin: ListReverseIterator, end: ListReverseIterator): ListReverseIterator; - /** - *

Remove duplicate values.

- * - *

Removes all but the first element from every consecutive group of equal elements in the

- * - *

Notice that an element is only removed from the {@link List} container if it compares equal to the - * element immediately preceding it. Thus, this function is especially useful for sorted lists.

- */ - unique(): void; - /** - *

Remove duplicate values.

- * - *

Removes all but the first element from every consecutive group of equal elements in the

- * - *

The argument binary_pred is a specific comparison function that determine the uniqueness - * of an element. In fact, any behavior can be implemented (and not only an equality comparison), but notice - * that the function will call binary_pred(it.value, it.prev().value) for all pairs of elements - * (where it is an iterator to an element, starting from the second) and remove it - * from the {@link List} if the predicate returns true. - * - *

Notice that an element is only removed from the {@link List} container if it compares equal to the - * element immediately preceding it. Thus, this function is especially useful for sorted lists.

- * - * @param binary_pred Binary predicate that, taking two values of the same type than those contained in the - * {@link List}, returns true to remove the element passed as first argument - * from the container, and false otherwise. This shall be a function pointer - * or a function object. - */ - unique(binary_pred: (left: T, right: T) => boolean): void; - /** - *

Remove elements with specific value.

- * - *

Removes from the container all the elements that compare equal to val. This calls the - * destructor of these objects and reduces the container {@link size} by the number of elements removed.

- * - *

Unlike member function {@link List.erase}, which erases elements by their position (using an - * iterator), this function ({@link List.remove}) removes elements by their value.

- * - *

A similar function, {@link List.remove_if}, exists, which allows for a condition other than an - * equality comparison to determine whether an element is removed.

- * - * @param val Value of the elements to be removed. - */ - remove(val: T): void; - /** - *

Remove elements fulfilling condition.

- * - *

Removes from the container all the elements for which pred returns true. This - * calls the destructor of these objects and reduces the container {@link size} by the number of elements - * removed.

- * - *

The function calls pred(it.value) for each element (where it is an iterator - * to that element). Any of the elements in the list for which this returns true, are removed - * from the

- * - * @param pred Unary predicate that, taking a value of the same type as those contained in the forward_list - * object, returns true for those values to be removed from the container, and - * false for those remaining. This can either be a function pointer or a function - * object. - */ - remove_if(pred: (val: T) => boolean): void; - /** - *

Merge sorted {@link List Lists}.

- * - *

Merges obj into the {@link List} by transferring all of its elements at their respective - * ordered positions into the container (both containers shall already be ordered). - *

- * - *

This effectively removes all the elements in obj (which becomes {@link empty}), and inserts - * them into their ordered position within container (which expands in {@link size} by the number of elements - * transferred). The operation is performed without constructing nor destroying any element: they are - * transferred, no matter whether obj is an lvalue or an rvalue, or whether the value_type supports - * move-construction or not.

- * - *

This function requires that the {@link List} containers have their elements already ordered by value - * ({@link less}) before the call. For an alternative on unordered {@link List Lists}, see - * {@link List.splice}.

- * - *

Assuming such ordering, each element of obj is inserted at the position that corresponds to its - * value according to the strict weak ordering defined by {@link less}. The resulting order of equivalent - * elements is stable (i.e., equivalent elements preserve the relative order they had before the call, and - * existing elements precede those equivalent inserted from obj).

- * - * The function does nothing if this == obj. - * - * @param obj A {@link List} object of the same type (i.e., with the same template parameters, T). - * Note that this function modifies obj no matter whether an lvalue or rvalue reference is - * passed. - */ - merge(obj: List): void; - /** - *

Merge sorted {@link List Lists}.

- * - *

Merges obj into the {@link List} by transferring all of its elements at their respective - * ordered positions into the container (both containers shall already be ordered). - *

- * - *

This effectively removes all the elements in obj (which becomes {@link empty}), and inserts - * them into their ordered position within container (which expands in {@link size} by the number of elements - * transferred). The operation is performed without constructing nor destroying any element: they are - * transferred, no matter whether obj is an lvalue or an rvalue, or whether the value_type supports - * move-construction or not.

- * - *

The argument compare is a specific predicate to perform the comparison operation between - * elements. This comparison shall produce a strict weak ordering of the elements (i.e., a consistent - * transitive comparison, without considering its reflexiveness). - * - *

This function requires that the {@link List} containers have their elements already ordered by - * compare before the call. For an alternative on unordered {@link List Lists}, see - * {@link List.splice}.

- * - *

Assuming such ordering, each element of obj is inserted at the position that corresponds to its - * value according to the strict weak ordering defined by compare. The resulting order of equivalent - * elements is stable (i.e., equivalent elements preserve the relative order they had before the call, and - * existing elements precede those equivalent inserted from obj).

- * - * The function does nothing if this == obj. - * - * @param obj A {@link List} object of the same type (i.e., with the same template parameters, T). - * Note that this function modifies obj no matter whether an lvalue or rvalue reference is - * passed. - * @param compare Binary predicate that, taking two values of the same type than those contained in the - * {@link list}, returns true if the first argument is considered to go before - * the second in the strict weak ordering it defines, and false otherwise. - * This shall be a function pointer or a function object. - */ - merge(obj: List, compare: (left: T, right: T) => boolean): void; - /** - *

Transfer elements from {@link List} to {@link List}.

- * - *

Transfers elements from obj into the container, inserting them at position.

- * - *

This effectively inserts all elements into the container and removes them from obj, altering - * the sizes of both containers. The operation does not involve the construction or destruction of any - * element. They are transferred, no matter whether obj is an lvalue or an rvalue, or whether the - * value_type supports move-construction or not.

- * - *

This first version (1) transfers all the elements of obj into the

- * - * @param position Position within the container where the elements of obj are inserted. - * @param obj A {@link List} object of the same type (i.e., with the same template parameters, T). - */ - splice(position: ListIterator, obj: List): void; - /** - *

Transfer an element from {@link List} to {@link List}.

- * - *

Transfers an element from obj, which is pointed by an {@link ListIterator iterator} it, - * into the container, inserting the element at specified position.

- * - *

This effectively inserts an element into the container and removes it from obj, altering the - * sizes of both containers. The operation does not involve the construction or destruction of any element. - * They are transferred, no matter whether obj is an lvalue or an rvalue, or whether the value_type - * supports move-construction or not.

- * - *

This second version (2) transfers only the element pointed by it from obj into the - *

- * - * @param position Position within the container where the element of obj is inserted. - * @param obj A {@link List} object of the same type (i.e., with the same template parameters, T). - * This parameter may be this if position points to an element not actually - * being spliced. - * @param it {@link ListIterator Iterator} to an element in obj. Only this single element is - * transferred. - */ - splice(position: ListIterator, obj: List, it: ListIterator): void; - /** - *

Transfer elements from {@link List} to {@link List}.

- * - *

Transfers elements from obj into the container, inserting them at position.

- * - *

This effectively inserts those elements into the container and removes them from obj, altering - * the sizes of both containers. The operation does not involve the construction or destruction of any - * element. They are transferred, no matter whether obj is an lvalue or an rvalue, or whether the - * value_type supports move-construction or not.

- * - *

This third version (3) transfers the range [begin, end) from obj into the - *

- * - * @param position Position within the container where the elements of obj are inserted. - * @param obj A {@link List} object of the same type (i.e., with the same template parameters, T). - * This parameter may be this if position points to an element not actually - * being spliced. - * @param begin {@link ListIterator An Iterator} specifying initial position of a range of elements in - * obj. Transfers the elements in the range [begin, end) to - * position. - * @param end {@link ListIterator An Iterator} specifying final position of a range of elements in - * obj. Transfers the elements in the range [begin, end) to - * position. Notice that the range includes all the elements between begin and - * end, including the element pointed by begin but not the one pointed by end. - */ - splice(position: ListIterator, obj: List, begin: ListIterator, end: ListIterator): void; - /** - *

Sort elements in

- * - *

Sorts the elements in the {@link List}, altering their position within the

- * - *

The sorting is performed by applying an algorithm that uses {@link less}. This comparison shall - * produce a strict weak ordering of the elements (i.e., a consistent transitive comparison, without - * considering its reflexiveness).

- * - *

The resulting order of equivalent elements is stable: i.e., equivalent elements preserve the relative - * order they had before the call.

- * - *

The entire operation does not involve the construction, destruction or copy of any element object. - * Elements are moved within the

- */ - sort(): void; - /** - *

Sort elements in

- * - *

Sorts the elements in the {@link List}, altering their position within the

- * - *

The sorting is performed by applying an algorithm that uses compare. This comparison shall - * produce a strict weak ordering of the elements (i.e., a consistent transitive comparison, without - * considering its reflexiveness).

- * - *

The resulting order of equivalent elements is stable: i.e., equivalent elements preserve the relative - * order they had before the call.

- * - *

The entire operation does not involve the construction, destruction or copy of any element object. - * Elements are moved within the

- * - * @param compare Binary predicate that, taking two values of the same type of those contained in the - * {@link List}, returns true if the first argument goes before the second - * argument in the strict weak ordering it defines, and false otherwise. This - * shall be a function pointer or a function object. - */ - sort(compare: (left: T, right: T) => boolean): void; - /** - * @hidden - */ - private qsort(first, last, compare); - /** - * @hidden - */ - private partition(first, last, compare); - /** - *

Swap content.

- * - *

Exchanges the content of the container by the content of obj, which is another - * {@link List container} object with same type of elements. Sizes and container type may differ.

- * - *

After the call to this member function, the elements in this container are those which were in obj - * before the call, and the elements of obj are those which were in this. All iterators, references and - * pointers remain valid for the swapped objects.

- * - *

Notice that a non-member function exists with the same name, {@link std.swap swap}, overloading that - * algorithm with an optimization that behaves like this member function.

- * - * @param obj Another {@link List container} of the same type of elements (i.e., instantiated - * with the same template parameter, T) whose content is swapped with that of this - * {@link container List}. - */ - swap(obj: List): void; - /** - * @inheritdoc - */ - swap(obj: base.IContainer): void; - } -} -declare namespace std { - /** - *

An iterator, node of a List.

- * - *

- * - *

- * - * @author Jeongho Nam - */ - class ListIterator extends base.ListIteratorBase { - /** - * Initializer Constructor. - * - * #### Note - * Do not create the iterator directly, by yourself. - * - * Use {@link List.begin begin()}, {@link List.end end()} in {@link List container} instead. - * - * @param source The source {@link List container} to reference. - * @param prev A refenrece of previous node ({@link ListIterator iterator}). - * @param next A refenrece of next node ({@link ListIterator iterator}). - * @param value Value to be stored in the node (iterator). - */ - constructor(source: List, prev: ListIterator, next: ListIterator, value: T); - /** - * @inheritdoc - */ - prev(): ListIterator; - /** - * @inheritdoc - */ - next(): ListIterator; - /** - * @inheritdoc - */ - advance(step: number): ListIterator; - /** - * @inheritdoc - */ - /** - * Set value of the iterator is pointing to. - * - * @param val Value to set. - */ - value: T; - /** - * @inheritdoc - */ - equals(obj: ListIterator): boolean; - /** - * @inheritdoc - */ - swap(obj: ListIterator): void; - } -} -declare namespace std { - /** - *

A reverse-iterator of List.

- * - *

- * - *

- * - * @param Type of the elements. - * - * @author Jeongho Nam - */ - class ListReverseIterator extends ReverseIterator, ListReverseIterator> implements base.ILinearIterator { - /** - * Construct from base iterator. - * - * @param base A reference of the base iterator, which iterates in the opposite direction. - */ - constructor(base: ListIterator); - /** - * @hidden - */ - protected _Create_neighbor(base: ListIterator): ListReverseIterator; - /** - * @inheritdoc - */ - /** - * Set value of the iterator is pointing to. - * - * @param val Value to set. - */ - value: T; - } -} -declare namespace std.Vector { - type iterator = std.VectorIterator; - type reverse_iterator = std.VectorReverseIterator; -} -declare namespace std { - /** - *

Vector, the dynamic array.

- * - *

{@link Vector}s are sequence containers representing arrays that can change in size.

- * - *

Just like arrays, {@link Vector}s use contiguous storage locations for their elements, which means that - * their elements can also be accessed using offsets on regular pointers to its elements, and just as efficiently - * as in arrays. But unlike arrays, their size can change dynamically, with their storage being handled - * automatically by the container.

- * - *

Internally, {@link Vector}s use a dynamically allocated array to store their elements. This array may need - * to be reallocated in order to grow in size when new elements are inserted, which implies allocating a new - * array and moving all elements to it. This is a relatively expensive task in terms of processing time, and - * thus, {@link Vector}s do not reallocate each time an element is added to the container.

- * - *

Instead, {@link Vector} containers may allocate some extra storage to accommodate for possible growth, and - * thus the container may have an actual {@link capacity} greater than the storage strictly needed to contain its - * elements (i.e., its {@link size}). Libraries can implement different strategies for growth to balance between - * memory usage and reallocations, but in any case, reallocations should only happen at logarithmically growing - * intervals of {@link size} so that the insertion of individual elements at the end of the {@link Vector} can be - * provided with amortized constant time complexity (see {@link push_back push_back()}).

- * - *

Therefore, compared to arrays, {@link Vector}s consume more memory in exchange for the ability to manage - * storage and grow dynamically in an efficient way.

- * - *

Compared to the other dynamic sequence containers ({@link Deque}s, {@link List}s), {@link Vector Vectors} - * are very efficient accessing its elements (just like arrays) and relatively efficient adding or removing - * elements from its end. For operations that involve inserting or removing elements at positions other than the - * end, they perform worse than the others, and have less consistent iterators and references than {@link List}s. - *

- * - *

- * - *

- * - *

Container properties

- *
- *
Sequence
- *
- * Elements in sequence containers are ordered in a strict linear sequence. Individual elements are - * accessed by their position in this sequence. - *
- * - *
Dynamic array
- *
- * Allows direct access to any element in the sequence, even through pointer arithmetics, and provides - * relatively fast addition/removal of elements at the end of the sequence. - *
- *
- * - * @param Type of the elements. - * - * @reference http://www.cplusplus.com/reference/vector/vector - * @author Jeongho Nam - */ - class Vector extends Array implements base.IContainer, base.IArrayContainer { - /** - * @hidden - */ - private end_; - /** - * @hidden - */ - private rend_; - /** - *

Default Constructor.

- * - *

Constructs an empty container, with no elements.

- */ - constructor(); - /** - * @inheritdoc - */ - constructor(array: Array); - /** - *

Initializer list Constructor.

- * - *

Constructs a container with a copy of each of the elements in array, in the same order.

- * - * @param array An array containing elements to be copied and contained. - */ - constructor(n: number); - /** - *

Fill Constructor.

- * - *

Constructs a container with n elements. Each element is a copy of val (if provided).

- * - * @param n Initial container size (i.e., the number of elements in the container at construction). - * @param val Value to fill the container with. Each of the n elements in the container is - * initialized to a copy of this value. - */ - constructor(n: number, val: T); - /** - *

Copy Constructor.

- * - *

Constructs a container with a copy of each of the elements in container, in the same order.

- * - * @param container Another container object of the same type (with the same class template - * arguments T), whose contents are either copied or acquired. - */ - constructor(container: Vector); - /** - *

Range Constructor.

- * - *

Constructs a container with as many elements as the range (begin, end), with each - * element emplace-constructed from its corresponding element in that range, in the same order.

- * - * @param begin Input interator of the initial position in a sequence. - * @param end Input interator of the final position in a sequence. - */ - constructor(begin: Iterator, end: Iterator); - /** - * @inheritdoc - */ - assign>(begin: InputIterator, end: InputIterator): void; - /** - * @inheritdoc - */ - assign(n: number, val: T): void; - /** - * @inheritdoc - */ - reserve(size: number): void; - /** - * @inheritdoc - */ - clear(): void; - /** - * @inheritdoc - */ - begin(): VectorIterator; - /** - * @inheritdoc - */ - end(): VectorIterator; - /** - * @inheritdoc - */ - rbegin(): VectorReverseIterator; - /** - * @inheritdoc - */ - rend(): VectorReverseIterator; - /** - * @inheritdoc - */ - size(): number; - /** - * @inheritdoc - */ - capacity(): number; - /** - * @inheritdoc - */ - empty(): boolean; - /** - * @inheritdoc - */ - at(index: number): T; - /** - * @inheritdoc - */ - set(index: number, val: T): T; - /** - * @inheritdoc - */ - front(): T; - /** - * @inheritdoc - */ - back(): T; - /** - * @inheritdoc - */ - push_back(val: T): void; - /** - *

Insert an element.

- * - *

The {@link Vector} is extended by inserting new element before the element at the specified - * position, effectively increasing the container size by one.

- * - *

This causes an automatic reallocation of the allocated storage space if -and only if- the new - * {@link size} surpasses the current {@link capacity}.

- * - *

Because {@link Vector}s use an Array as their underlying storage, inserting element in - * positions other than the {@link end end()} causes the container to relocate all the elements that were - * after position to its new position. This is generally an inefficient operation compared to the one - * performed for the same operation by other kinds of sequence containers (such as {@link List}).

- * - * @param position Position in the {@link Vector} where the new element is inserted. - * {@link iterator} is a member type, defined as a - * {@link VectorIterator random access iterator} type that points to elements. - * @param val Value to be copied to the inserted element. - * - * @return An iterator that points to the newly inserted element. - */ - insert(position: VectorIterator, val: T): VectorIterator; - /** - *

Insert elements by repeated filling.

- * - *

The {@link Vector} is extended by inserting new elements before the element at the specified - * position, effectively increasing the container size by the number of elements inserted.

- * - *

This causes an automatic reallocation of the allocated storage space if -and only if- the new - * {@link size} surpasses the current {@link capacity}.

- * - *

Because {@link Vector}s use an Array as their underlying storage, inserting elements in - * positions other than the {@link end end()} causes the container to relocate all the elements that were - * after position to their new positions. This is generally an inefficient operation compared to the - * one performed for the same operation by other kinds of sequence containers (such as {@link List}). - * - * @param position Position in the {@link Vector} where the new elements are inserted. - * {@link iterator} is a member type, defined as a - * {@link VectorIterator random access iterator} type that points to elements. - * @param n Number of elements to insert. Each element is initialized to a copy of val. - * @param val Value to be copied (or moved) to the inserted elements. - * - * @return An iterator that points to the first of the newly inserted elements. - */ - insert(position: VectorIterator, n: number, val: T): VectorIterator; - /** - *

Insert elements by range iterators.

- * - *

The {@link Vector} is extended by inserting new elements before the element at the specified - * position, effectively increasing the container size by the number of elements inserted by range - * iterators.

- * - *

This causes an automatic reallocation of the allocated storage space if -and only if- the new - * {@link size} surpasses the current {@link capacity}.

- * - *

Because {@link Vector}s use an Array as their underlying storage, inserting elements in - * positions other than the {@link end end()} causes the container to relocate all the elements that were - * after position to their new positions. This is generally an inefficient operation compared to the - * one performed for the same operation by other kinds of sequence containers (such as {@link List}). - * - * @param position Position in the {@link Vector} where the new elements are inserted. - * {@link iterator} is a member type, defined as a - * {@link VectorIterator random access iterator} type that points to elements. - * @param begin Input interator of the initial position in a sequence. - * @param end Input interator of the final position in a sequence. - * - * @return An iterator that points to the first of the newly inserted elements. - */ - insert>(position: VectorIterator, begin: InputIterator, end: InputIterator): VectorIterator; - /** - *

Insert an element.

- * - *

The {@link Vector} is extended by inserting new element before the element at the specified - * position, effectively increasing the container size by one.

- * - *

This causes an automatic reallocation of the allocated storage space if -and only if- the new - * {@link size} surpasses the current {@link capacity}.

- * - *

Because {@link Vector}s use an Array as their underlying storage, inserting element in - * positions other than the {@link end end()} causes the container to relocate all the elements that were - * after position to its new position. This is generally an inefficient operation compared to the one - * performed for the same operation by other kinds of sequence containers (such as {@link List}).

- * - * @param position Position in the {@link Vector} where the new element is inserted. - * {@link iterator} is a member type, defined as a - * {@link VectorIterator random access iterator} type that points to elements. - * @param val Value to be copied to the inserted element. - * - * @return An iterator that points to the newly inserted element. - */ - insert(position: VectorReverseIterator, val: T): VectorReverseIterator; - /** - *

Insert elements by repeated filling.

- * - *

The {@link Vector} is extended by inserting new elements before the element at the specified - * position, effectively increasing the container size by the number of elements inserted.

- * - *

This causes an automatic reallocation of the allocated storage space if -and only if- the new - * {@link size} surpasses the current {@link capacity}.

- * - *

Because {@link Vector}s use an Array as their underlying storage, inserting elements in - * positions other than the {@link end end()} causes the container to relocate all the elements that were - * after position to their new positions. This is generally an inefficient operation compared to the - * one performed for the same operation by other kinds of sequence containers (such as {@link List}). - * - * @param position Position in the {@link Vector} where the new elements are inserted. - * {@link iterator} is a member type, defined as a - * {@link VectorIterator random access iterator} type that points to elements. - * @param n Number of elements to insert. Each element is initialized to a copy of val. - * @param val Value to be copied (or moved) to the inserted elements. - * - * @return An iterator that points to the first of the newly inserted elements. - */ - insert(position: VectorReverseIterator, n: number, val: T): VectorReverseIterator; - /** - *

Insert elements by range iterators.

- * - *

The {@link Vector} is extended by inserting new elements before the element at the specified - * position, effectively increasing the container size by the number of elements inserted by range - * iterators.

- * - *

This causes an automatic reallocation of the allocated storage space if -and only if- the new - * {@link size} surpasses the current {@link capacity}.

- * - *

Because {@link Vector}s use an Array as their underlying storage, inserting elements in - * positions other than the {@link end end()} causes the container to relocate all the elements that were - * after position to their new positions. This is generally an inefficient operation compared to the - * one performed for the same operation by other kinds of sequence containers (such as {@link List}). - * - * @param position Position in the {@link Vector} where the new elements are inserted. - * {@link iterator} is a member type, defined as a - * {@link VectorIterator random access iterator} type that points to elements. - * @param begin Input interator of the initial position in a sequence. - * @param end Input interator of the final position in a sequence. - * - * @return An iterator that points to the first of the newly inserted elements. - */ - insert>(position: VectorReverseIterator, begin: InputIterator, end: InputIterator): VectorReverseIterator; - /** - * @hidden - */ - private insert_by_val(position, val); - /** - * @hidden - */ - protected _Insert_by_repeating_val(position: VectorIterator, n: number, val: T): VectorIterator; - /** - * @hidden - */ - protected _Insert_by_range>(position: VectorIterator, first: InputIterator, last: InputIterator): VectorIterator; - /** - * @inheritdoc - */ - pop_back(): void; - /** - *

Erase element.

- * - *

Removes from the {@link Vector} either a single element; position.

- * - *

This effectively reduces the container size by the number of element removed.

- * - *

Because {@link Vector}s use an Array as their underlying storage, erasing an element in - * position other than the {@link end end()} causes the container to relocate all the elements after the - * segment erased to their new positions. This is generally an inefficient operation compared to the one - * performed for the same operation by other kinds of sequence containers (such as {@link List}).

- * - * @param position Iterator pointing to a single element to be removed from the {@link Vector}. - * - * @return An iterator pointing to the new location of the element that followed the last element erased by - * the function call. This is the {@link end end()} if the operation erased the last element in the - * sequence. - */ - erase(position: VectorIterator): VectorIterator; - /** - *

Erase element.

- * - *

Removes from the Vector either a single element; position.

- * - *

This effectively reduces the container size by the number of elements removed.

- * - *

Because {@link Vector}s use an Array as their underlying storage, erasing elements in - * position other than the {@link end end()} causes the container to relocate all the elements after the - * segment erased to their new positions. This is generally an inefficient operation compared to the one - * performed for the same operation by other kinds of sequence containers (such as {@link List}).

- * - * @param begin An iterator specifying a range of beginning to erase. - * @param end An iterator specifying a range of end to erase. - * - * @return An iterator pointing to the new location of the element that followed the last element erased by - * the function call. This is the {@link rend rend()} if the operation erased the last element in the - * sequence. - */ - erase(first: VectorIterator, last: VectorIterator): VectorIterator; - /** - *

Erase element.

- * - *

Removes from the {@link Vector} either a single element; position.

- * - *

This effectively reduces the container size by the number of element removed.

- * - *

Because {@link Vector}s use an Array as their underlying storage, erasing an element in - * position other than the {@link end end()} causes the container to relocate all the elements after the - * segment erased to their new positions. This is generally an inefficient operation compared to the one - * performed for the same operation by other kinds of sequence containers (such as {@link List}).

- * - * @param position Iterator pointing to a single element to be removed from the {@link Vector}. - * - * @return An iterator pointing to the new location of the element that followed the last element erased by - * the function call. This is the {@link rend rend()} if the operation erased the last element in the - * sequence. - */ - erase(position: VectorReverseIterator): VectorReverseIterator; - /** - *

Erase element.

- * - *

Removes from the Vector either a single element; position.

- * - *

This effectively reduces the container size by the number of elements removed.

- * - *

Because {@link Vector}s use an Array as their underlying storage, erasing elements in - * position other than the {@link end end()} causes the container to relocate all the elements after the - * segment erased to their new positions. This is generally an inefficient operation compared to the one - * performed for the same operation by other kinds of sequence containers (such as {@link List}).

- * - * @param begin An iterator specifying a range of beginning to erase. - * @param end An iterator specifying a range of end to erase. - * - * @return An iterator pointing to the new location of the element that followed the last element erased by - * the function call. This is the {@link end end()} if the operation erased the last element in the - * sequence. - */ - erase(first: VectorReverseIterator, last: VectorReverseIterator): VectorReverseIterator; - /** - * @hidden - */ - protected _Erase_by_range(first: VectorIterator, last: VectorIterator): VectorIterator; - /** - *

Swap content.

- * - *

Exchanges the content of the container by the content of obj, which is another - * {@link Vector container} object with same type of elements. Sizes and container type may differ.

- * - *

After the call to this member function, the elements in this container are those which were in obj - * before the call, and the elements of obj are those which were in this. All iterators, references and - * pointers remain valid for the swapped objects.

- * - *

Notice that a non-member function exists with the same name, {@link std.swap swap}, overloading that - * algorithm with an optimization that behaves like this member function.

- * - * @param obj Another {@link Vector container} of the same type of elements (i.e., instantiated - * with the same template parameter, T) whose content is swapped with that of this - * {@link container Vector}. - */ - swap(obj: Vector): void; - /** - * @inheritdoc - */ - swap(obj: base.IContainer): void; - } -} -declare namespace std { - /** - *

An iterator of Vector.

- * - *

- * - *

- * - * @param Type of the elements. - * - * @author Jeongho Nam - */ - class VectorIterator extends Iterator implements base.IArrayIterator { - /** - * Sequence number of iterator in the source {@link Vector}. - */ - private index_; - /** - *

Construct from the source {@link Vector container}.

- * - *

Note

- *

Do not create the iterator directly, by yourself.

- *

Use {@link Vector.begin begin()}, {@link Vector.end end()} in {@link Vector container} instead.

- * - * @param source The source {@link Vector container} to reference. - * @param index Sequence number of the element in the source {@link Vector}. - */ - constructor(source: Vector, index: number); - /** - * @hidden - */ - private readonly vector; - /** - * @inheritdoc - */ - /** - * Set value of the iterator is pointing to. - * - * @param val Value to set. - */ - value: T; - /** - * Get index. - */ - readonly index: number; - /** - * @inheritdoc - */ - prev(): VectorIterator; - /** - * @inheritdoc - */ - next(): VectorIterator; - /** - * @inheritdoc - */ - advance(n: number): VectorIterator; - /** - * @inheritdoc - */ - equals(obj: VectorIterator): boolean; - /** - * @inheritdoc - */ - swap(obj: VectorIterator): void; - toString(): number; - } -} -declare namespace std { - /** - *

A reverse-iterator of Vector.

- * - *

- * - *

- * - * @param Type of the elements. - * - * @author Jeongho Nam - */ - class VectorReverseIterator extends ReverseIterator, VectorReverseIterator> implements base.IArrayIterator { - /** - * Construct from base iterator. - * - * @param base A reference of the base iterator, which iterates in the opposite direction. - */ - constructor(base: VectorIterator); - /** - * @hidden - */ - protected _Create_neighbor(base: VectorIterator): VectorReverseIterator; - /** - * @inheritdoc - */ - /** - * Set value of the iterator is pointing to. - * - * @param val Value to set. - */ - value: T; - /** - * Get index. - */ - readonly index: number; - } -} -declare namespace std { - /** - *

FIFO queue.

- * - *

{@link Queue}s are a type of container adaptor, specifically designed to operate in a FIFO context - * (first-in first-out), where elements are inserted into one end of the container and extracted from the other. - *

- * - *

{@link Queue}s are implemented as containers adaptors, which are classes that use an encapsulated object of - * a specific container class as its underlying container, providing a specific set of member functions to access - * its elements. Elements are pushed into the {@link IDeque.back back()} of the specific container and popped from - * its {@link IDeque.front front()}.

- * - *

{@link container_ The underlying container} may be one of the standard container class template or some - * other specifically designed container class. This underlying container shall support at least the following - * operations:

- * - *
    - *
  • empty
  • - *
  • size
  • - *
  • front
  • - *
  • back
  • - *
  • push_back
  • - *
  • pop_front
  • - *
- * - *

The standard container classes {@link Deque} and {@link List} fulfill these requirements. - * By default, if no container class is specified for a particular {@link Queue} class instantiation, the standard - * container {@link List} is used.

- * - *

- * - *

- * - * @param Type of elements. - * - * @reference http://www.cplusplus.com/reference/queue/queue - * @author Jeongho Nam - */ - class Queue { - /** - * The underlying object for implementing the FIFO - */ - private container_; - /** - * Default Constructor. - */ - constructor(); - /** - * Copy Constructor. - */ - constructor(container: Queue); - /** - *

Return size.

- *

Returns the number of elements in the {@link Queue}.

- * - *

This member function effectively calls member {@link IDeque.size size()} of the - * {@link container_ underlying container} object.

- * - * @return The number of elements in the {@link container_ underlying container}. - */ - size(): number; - /** - *

Test whether container is empty.

- *

returns whether the {@link Queue} is empty: i.e. whether its size is zero.

- * - *

This member function efeectively calls member {@link IDeque.empty empty()} of the - * {@link container_ underlying container} object.

- * - * @return true if the {@link container_ underlying container}'s size is 0, - * false otherwise.

- */ - empty(): boolean; - /** - *

Access next element.

- *

Returns a value of the next element in the {@link Queue}.

- * - *

The next element is the "oldest" element in the {@link Queue} and the same element that is popped out - * from the queue when {@link pop Queue.pop()} is called.

- * - *

This member function effectively calls member {@link IDeque.front front()} of the - * {@link container_ underlying container} object.

- * - * @return A value of the next element in the {@link Queue}. - */ - front(): T; - /** - *

Access last element.

- * - *

Returns a vaue of the last element in the queue. This is the "newest" element in the queue (i.e. the - * last element pushed into the queue).

- * - *

This member function effectively calls the member function {@link IDeque.back back()} of the - * {@link container_ underlying container} object.

- * - * @return A value of the last element in the {@link Queue}. - */ - back(): T; - /** - *

Insert element.

- * - *

Inserts a new element at the end of the {@link Queue}, after its current last element. - * The content of this new element is initialized to val.

- * - *

This member function effectively calls the member function {@link IDeque.push_back push_back()} of the - * {@link container_ underlying container} object.

- * - * @param val Value to which the inserted element is initialized. - */ - push(val: T): void; - /** - *

Remove next element.

- * - *

Removes the next element in the {@link Queue}, effectively reducing its size by one.

- * - *

The element removed is the "oldest" element in the {@link Queue} whose value can be retrieved by calling - * member {@link front Queue.front()}

. - * - *

This member function effectively calls the member function {@link IDeque.pop_front pop_front()} of the - * {@link container_ underlying container} object.

- */ - pop(): void; - /** - *

Swap contents.

- * - *

Exchanges the contents of the container adaptor (this) by those of obj.

- * - *

This member function calls the non-member function {@link IContainer.swap swap} (unqualified) to swap - * the {@link container_ underlying containers}.

- * - * @param obj Another {@link Queue} container adaptor of the same type (i.e., instantiated with the same - * template parameter, T). Sizes may differ.

- */ - swap(obj: Queue): void; - } -} -declare namespace std { - /** - *

Priority queue.

- * - *

{@link PriorityQueue Priority queues} are a type of container adaptors, specifically designed such that its - * first element is always the greatest of the elements it contains, according to some strict weak ordering - * criterion.

- * - *

This context is similar to a heap, where elements can be inserted at any moment, and only the - * max heap element can be retrieved (the one at the top in the {@link PriorityQueue priority queue}).

- * - *

{@link PriorityQueue Priority queues} are implemented as container adaptors, which are classes that - * use an encapsulated object of a specific container class as its {@link container_ underlying container}, - * providing a specific set of member functions to access its elements. Elements are popped from the "back" - * of the specific container, which is known as the top of the {@link PriorityQueue Priority queue}.

- * - *

The {@link container_ underlying container} may be any of the standard container class templates or some - * other specifically designed container class. The container shall be accessible through - * {@link IArrayIterator random access iterators} and support the following operations:

- * - *
    - *
  • empty()
  • - *
  • size()
  • - *
  • front()
  • - *
  • push_back()
  • - *
  • pop_back()
  • - *
- * - *

The standard container classes {@link Vector} and {@link Deque} fulfill these requirements. By default, if - * no container class is specified for a particular {@link PriorityQueue} class instantiation, the standard - * container {@link Vector} is used.

- * - *

Support of {@link IArrayIterator random access iterators} is required to keep a heap structure internally - * at all times. This is done automatically by the container adaptor by automatically calling the algorithm - * functions make_heap, push_heap and pop_heap when needed.

- * - * @param Type of the elements. - * - * @reference http://www.cplusplus.com/reference/queue/priority_queue/ - * @author Jeongho Nam - */ - class PriorityQueue { - /** - *

The underlying container for implementing the priority queue.

- * - *

Following standard definition from the C++ committee, the underlying container should be one of - * {@link Vector} or {@link Deque}, however, I've adopted {@link TreeMultiSet} instead of them. Of course, - * there are proper reasons for adapting the {@link TreeMultiSet} even violating standard advice.

- * - *

Underlying container of {@link PriorityQueue} must keep a condition; the highest (or lowest) - * element must be placed on the terminal node for fast retrieval and deletion. To keep the condition with - * {@link Vector} or {@link Deque}, lots of times will only be spent for re-arranging elements. It calls - * rearrangement functions like make_heap, push_heap and pop_head for rearrangement.

- * - *

However, the {@link TreeMultiSet} container always keeps arrangment automatically without additional - * operations and it even meets full criteria of {@link PriorityQueue}. Those are the reason why I've adopted - * {@link TreeMultiSet} as the underlying container of {@link PriorityQueue}.

- */ - private container_; - /** - * Default Constructor. - */ - constructor(); - /** - * Construct from compare. - * - * @param compare A binary predicate determines order of elements. - */ - constructor(compare: (left: T, right: T) => boolean); - /** - * Contruct from elements. - * - * @param array Elements to be contained. - */ - constructor(array: Array); - /** - * Contruct from elements with compare. - * - * @param array Elements to be contained. - * @param compare A binary predicate determines order of elements. - */ - constructor(array: Array, compare: (left: T, right: T) => boolean); - /** - * Copy Constructor. - */ - constructor(container: base.IContainer); - /** - * Copy Constructor with compare. - * - * @param container A container to be copied. - * @param compare A binary predicate determines order of elements. - */ - constructor(container: base.IContainer, compare: (left: T, right: T) => boolean); - /** - * Range Constructor. - * - * @param begin Input interator of the initial position in a sequence. - * @param end Input interator of the final position in a sequence. - */ - constructor(begin: Iterator, end: Iterator); - /** - * Range Constructor with compare. - * - * @param begin Input interator of the initial position in a sequence. - * @param end Input interator of the final position in a sequence. - * @param compare A binary predicate determines order of elements. - */ - constructor(begin: Iterator, end: Iterator, compare: (left: T, right: T) => boolean); - /** - *

Return size.

- * - *

Returns the number of elements in the {@link PriorityQueue}.

- * - *

This member function effectively calls member {@link IArray.size size} of the - * {@link container_ underlying container} object.

- * - * @return The number of elements in the underlying - */ - size(): number; - /** - *

Test whether container is empty.

- * - *

Returns whether the {@link PriorityQueue} is empty: i.e. whether its {@link size} is zero.

- * - *

This member function effectively calls member {@link IARray.empty empty} of the - * {@link container_ underlying container} object.

- */ - empty(): boolean; - /** - *

Access top element.

- * - *

Returns a constant reference to the top element in the {@link PriorityQueue}.

- * - *

The top element is the element that compares higher in the {@link PriorityQueue}, and the next that is - * removed from the container when {@link PriorityQueue.pop} is called.

- * - *

This member function effectively calls member {@link IArray.front front} of the - * {@link container_ underlying container} object.

- * - * @return A reference to the top element in the {@link PriorityQueue}. - */ - top(): T; - /** - *

Insert element.

- * - *

Inserts a new element in the {@link PriorityQueue}. The content of this new element is initialized to - * val. - * - *

This member function effectively calls the member function {@link IArray.push_back push_back} of the - * {@link container_ underlying container} object, and then reorders it to its location in the heap by calling - * the push_heap algorithm on the range that includes all the elements of the

- * - * @param val Value to which the inserted element is initialized. - */ - push(val: T): void; - /** - *

Remove top element.

- * - *

Removes the element on top of the {@link PriorityQueue}, effectively reducing its {@link size} by one. - * The element removed is the one with the highest (or lowest) value.

- * - *

The value of this element can be retrieved before being popped by calling member - * {@link PriorityQueue.top}.

- * - *

This member function effectively calls the pop_heap algorithm to keep the heap property of - * {@link PriorityQueue PriorityQueues} and then calls the member function {@link IArray.pop_back pop_back} of - * the {@link container_ underlying container} object to remove the element.

- */ - pop(): void; - /** - *

Swap contents.

- * - *

Exchanges the contents of the container adaptor by those of obj, swapping both the - * {@link container_ underlying container} value and their comparison function using the corresponding - * {@link std.swap swap} non-member functions (unqualified).

- * - *

This member function has a noexcept specifier that matches the combined noexcept of the - * {@link IArray.swap swap} operations on the {@link container_ underlying container} and the comparison - * functions.

- * - * @param obj {@link PriorityQueue} container adaptor of the same type (i.e., instantiated with the same - * template parameters, T). Sizes may differ. - */ - swap(obj: PriorityQueue): void; - } -} -declare namespace std { - /** - *

LIFO stack.

- * - *

{@link Stack}s are a type of container adaptor, specifically designed to operate in a LIFO context - * (last-in first-out), where elements are inserted and extracted only from one end of the

- * - *

{@link Stack}s are implemented as containers adaptors, which are classes that use an encapsulated object of - * a specific container class as its underlying container, providing a specific set of member functions to - * access its elements. Elements are pushed/popped from the {@link ILinearContainer.back back()} of the - * {@link ILinearContainer specific container}, which is known as the top of the {@link Stack}.

- * - *

{@link container_ The underlying container} may be any of the standard container class templates or some - * other specifically designed container class. The container shall support the following operations:

- * - *
    - *
  • empty
  • - *
  • size
  • - *
  • front
  • - *
  • back
  • - *
  • push_back
  • - *
  • pop_back
  • - *
- * - *

The standard container classes {@link Vector}, {@link Deque} and {@link List} fulfill these requirements. - * By default, if no container class is specified for a particular {@link Stack} class instantiation, the standard - * container {@link List} is used.

- * - *

- * - *

- * - * @param Type of elements. - * - * @reference http://www.cplusplus.com/reference/stack/stack - * @author Jeongho Nam - */ - class Stack { - /** - * The underlying object for implementing the LIFO - */ - private container_; - /** - * Default Constructor. - */ - constructor(); - /** - * Copy Constructor. - */ - constructor(stack: Stack); - /** - *

Return size.

- * - *

Returns the number of elements in the {@link Stack}.

- * - *

This member function effectively calls member {@link ILinearContainer.size size()} of the - * {@link container_ underlying container} object.

- * - * @return The number of elements in the {@link container_ underlying container}. - */ - size(): number; - /** - *

Test whether container is empty.

- * - *

returns whether the {@link Stack} is empty: i.e. whether its size is zero.

- * - *

This member function effectively calls member {@link ILinearContainer.empty empty()} of the - * {@link container_ underlying container} object.

- * - * @return true if the underlying container's size is 0, - * false otherwise.

- */ - empty(): boolean; - /** - *

Access next element.

- * - *

Returns a value of the top element in the {@link Stack}

. - * - *

Since {@link Stack}s are last-in first-out containers, the top element is the last element inserted into - * the {@link Stack}.

- * - *

This member function effectively calls member {@link ILinearContainer.back back()} of the - * {@link container_ underlying container} object.

- * - * @return A value of the top element in the {@link Stack}. - */ - top(): T; - /** - *

Insert element.

- * - *

Inserts a new element at the top of the {@link Stack}, above its current top element.

- * - *

This member function effectively calls the member function - * {@link ILinearContainer.push_back push_back()} of the {@link container_ underlying container} object.

- * - * @param val Value to which the inserted element is initialized. - */ - push(val: T): void; - /** - *

Remove top element.

- * - *

Removes the element on top of the {@link Stack}, effectively reducing its size by one.

- * - *

The element removed is the latest element inserted into the {@link Stack}, whose value can be retrieved - * by calling member {@link top Stack.top()}

. - * - *

This member function effectively calls the member function {@link ILinearContainer.pop_back pop_back()} - * of the {@link container_ underlying container} object.

- */ - pop(): void; - /** - *

Swap contents.

- * - *

Exchanges the contents of the container adaptor (this) by those of obj.

- * - *

This member function calls the non-member function {@link IContainer.swap swap} (unqualified) to swap - * the {@link container_ underlying containers}.

- * - * @param obj Another {@link Stack} container adaptor of the same type (i.e., instantiated with the same - * template parameter, T). Sizes may differ.

- */ - swap(obj: Stack): void; - } -} -declare namespace std.TreeSet { - type iterator = std.SetIterator; - type reverse_iterator = std.SetReverseIterator; -} -declare namespace std { - /** - *

Tree-structured set, std::set of STL.

- * - *

{@link TreeSet}s are containers that store unique elements following a specific order.

- * - *

In a {@link TreeSet}, the value of an element also identifies it (the value is itself the - * key, of type T), and each value must be unique. The value of the elements in a - * {@link TreeSet} cannot be modified once in the container (the elements are always const), but they - * can be inserted or removed from the container.

- * - *

Internally, the elements in a {@link TreeSet} are always sorted following a specific strict weak - * ordering criterion indicated by its internal comparison method (of {@link less}).

- * - *

{@link TreeSet} containers are generally slower than {@link HashSet} containers to access - * individual elements by their key, but they allow the direct iteration on subsets based on their - * order.

- * - *

{@link TreeSet}s are typically implemented as binary search trees.

- * - *

- *

- * - *

Container properties

- *
- *
Associative
- *
- * Elements in associative containers are referenced by their key and not by their absolute - * position in the container. - *
- * - *
Ordered
- *
- * The elements in the container follow a strict order at all times. All inserted elements are - * given a position in this order. - *
- * - *
Set
- *
The value of an element is also the key used to identify it.
- * - *
Unique keys
- *
No two elements in the container can have equivalent keys.
- *
- * - * @param Type of the elements. - * Each element in an {@link TreeSet} is also uniquely identified by this value. - * - * @reference http://www.cplusplus.com/reference/set/set - * @author Jeongho Nam - */ - class TreeSet extends base.UniqueSet implements base.ITreeSet { - /** - * @hidden - */ - private tree_; - /** - * Default Constructor. - */ - constructor(); - /** - * Construct from compare. - * - * @param compare A binary predicate determines order of elements. - */ - constructor(compare: (x: T, y: T) => boolean); - /** - * Contruct from elements. - * - * @param array Elements to be contained. - */ - constructor(array: Array); - /** - * Contruct from elements with compare. - * - * @param array Elements to be contained. - * @param compare A binary predicate determines order of elements. - */ - constructor(array: Array, compare: (x: T, y: T) => boolean); - /** - * Copy Constructor. - */ - constructor(container: TreeMultiSet); - /** - * Copy Constructor with compare. - * - * @param container A container to be copied. - * @param compare A binary predicate determines order of elements. - */ - constructor(container: TreeMultiSet, compare: (x: T, y: T) => boolean); - /** - * Range Constructor. - * - * @param begin Input interator of the initial position in a sequence. - * @param end Input interator of the final position in a sequence. - */ - constructor(begin: Iterator, end: Iterator); - /** - * Construct from range and compare. - * - * @param begin Input interator of the initial position in a sequence. - * @param end Input interator of the final position in a sequence. - * @param compare A binary predicate determines order of elements. - */ - constructor(begin: Iterator, end: Iterator, compare: (x: T, y: T) => boolean); - /** - * @inheritdoc - */ - clear(): void; - /** - * @inheritdoc - */ - find(val: T): SetIterator; - /** - * @inheritdoc - */ - key_comp(): (x: T, y: T) => boolean; - /** - * @inheritdoc - */ - value_comp(): (x: T, y: T) => boolean; - /** - * @inheritdoc - */ - lower_bound(val: T): SetIterator; - /** - * @inheritdoc - */ - upper_bound(val: T): SetIterator; - /** - * @inheritdoc - */ - equal_range(val: T): Pair, SetIterator>; - /** - * @hidden - */ - protected _Insert_by_val(val: T): any; - protected _Insert_by_hint(hint: SetIterator, val: T): SetIterator; - /** - * @hidden - */ - protected _Insert_by_range>(first: InputIterator, last: InputIterator): void; - /** - * @inheritdoc - */ - protected _Handle_insert(first: SetIterator, last: SetIterator): void; - /** - * @inheritdoc - */ - protected _Handle_erase(first: SetIterator, last: SetIterator): void; - /** - *

Swap content.

- * - *

Exchanges the content of the container by the content of obj, which is another - * {@link TreeSet set} of the same type. Sizes abd container type may differ.

- * - *

After the call to this member function, the elements in this container are those which were - * in obj before the call, and the elements of obj are those which were in this. All - * iterators, references and pointers remain valid for the swapped objects.

- * - *

Notice that a non-member function exists with the same name, {@link std.swap swap}, overloading that - * algorithm with an optimization that behaves like this member function.

- * - * @param obj Another {@link TreeSet set container} of the same type of elements as this (i.e., - * with the same template parameters, Key and T) whose content is swapped - * with that of this {@link TreeSet container}. - */ - swap(obj: TreeSet): void; - /** - * @inheritdoc - */ - swap(obj: base.IContainer): void; - } -} -declare namespace std.TreeMap { - type iterator = std.MapIterator; - type reverse_iterator = std.MapReverseIterator; -} -declare namespace std { - /** - *

Tree-structured map, std::map of STL.

- * - *

{@link TreeMap TreeMaps} are associative containers that store elements formed by a combination of a - * key value (Key) and a mapped value (T), following order.

- * - *

In a {@link TreeMap}, the key values are generally used to sort and uniquely identify the elements, - * while the mapped values store the content associated to this key. The types of key and - * mapped value may differ, and are grouped together in member type value_type, which is a {@link Pair} - * type combining both:

- * - *

typedef Pair value_type;

- * - *

Internally, the elements in a {@link TreeMap} are always sorted by its key following a - * strict weak ordering criterion indicated by its internal comparison method {@link less}. - * - *

{@link TreeMap} containers are generally slower than {@link HashMap HashMap} containers to access individual - * elements by their key, but they allow the direct iteration on subsets based on their order.

- * - *

{@link TreeMap}s are typically implemented as binary search trees.

- * - *

- *

- * - *

Container properties

- *
- *
Associative
- *
Elements in associative containers are referenced by their key and not by their absolute - * position in the container.
- * - *
Ordered
- *
The elements in the container follow a strict order at all times. All inserted elements are - * given a position in this order.
- * - *
Map
- *
Each element associates a key to a mapped value: - * Keys are meant to identify the elements whose main content is the mapped value.
- * - *
Unique keys
- *
No two elements in the container can have equivalent keys.
- *
- * - * @param Type of the keys. Each element in a map is uniquely identified by its key value. - * @param Type of the mapped value. Each element in a map stores some data as its mapped value. - * - * @reference http://www.cplusplus.com/reference/map/map - * @author Jeongho Nam - */ - class TreeMap extends base.UniqueMap implements base.ITreeMap { - /** - * @hidden - */ - private tree_; - /** - * Default Constructor. - */ - constructor(); - /** - * Construct from compare. - * - * @param compare A binary predicate determines order of elements. - */ - constructor(compare: (x: Key, y: Key) => boolean); - /** - * Contruct from elements. - * - * @param array Elements to be contained. - */ - constructor(array: Array>); - /** - * Contruct from elements. - * - * @param array Elements to be contained. - * @param compare A binary predicate determines order of elements. - */ - constructor(array: Array>, compare: (x: Key, y: Key) => boolean); - /** - * Contruct from tuples. - * - * @param array Tuples to be contained. - */ - constructor(array: Array<[Key, T]>); - /** - * Contruct from tuples. - * - * @param array Tuples to be contained. - * @param compare A binary predicate determines order of elements. - */ - constructor(array: Array<[Key, T]>, compare: (x: Key, y: Key) => boolean); - /** - * Copy Constructor. - * - * @param container Another map to copy. - */ - constructor(container: TreeMap); - /** - * Copy Constructor. - * - * @param container Another map to copy. - * @param compare A binary predicate determines order of elements. - */ - constructor(container: TreeMap, compare: (x: Key, y: Key) => boolean); - /** - * Range Constructor. - * - * @param begin nput interator of the initial position in a sequence. - * @param end Input interator of the final position in a sequence. - */ - constructor(begin: Iterator>, end: Iterator>); - /** - * Range Constructor. - * - * @param begin nput interator of the initial position in a sequence. - * @param end Input interator of the final position in a sequence. - * @param compare A binary predicate determines order of elements. - */ - constructor(begin: Iterator>, end: Iterator>, compare: (x: Key, y: Key) => boolean); - /** - * @inheritdoc - */ - clear(): void; - /** - * @inheritdoc - */ - find(key: Key): MapIterator; - /** - * @inheritdoc - */ - key_comp(): (x: Key, y: Key) => boolean; - /** - * @inheritdoc - */ - value_comp(): (x: Pair, y: Pair) => boolean; - /** - * @inheritdoc - */ - lower_bound(key: Key): MapIterator; - /** - * @inheritdoc - */ - upper_bound(key: Key): MapIterator; - /** - * @inheritdoc - */ - equal_range(key: Key): Pair, MapIterator>; - /** - * @hidden - */ - protected _Insert_by_pair(pair: Pair): any; - /** - * @hidden - */ - protected _Insert_by_hint(hint: MapIterator, pair: Pair): MapIterator; - /** - * @hidden - */ - protected _Insert_by_range>>(first: InputIterator, last: InputIterator): void; - /** - * @inheritdoc - */ - protected _Handle_insert(first: MapIterator, last: MapIterator): void; - /** - * @inheritdoc - */ - protected _Handle_erase(first: MapIterator, last: MapIterator): void; - /** - *

Swap content.

- * - *

Exchanges the content of the container by the content of obj, which is another - * {@link TreeMap map} of the same type. Sizes abd container type may differ.

- * - *

After the call to this member function, the elements in this container are those which were - * in obj before the call, and the elements of obj are those which were in this. All - * iterators, references and pointers remain valid for the swapped objects.

- * - *

Notice that a non-member function exists with the same name, {@link std.swap swap}, overloading that - * algorithm with an optimization that behaves like this member function.

- * - * @param obj Another {@link TreeMap map container} of the same type of elements as this (i.e., - * with the same template parameters, Key and T) whose content is swapped - * with that of this {@link TreeMap container}. - */ - swap(obj: TreeMap): void; - /** - * @inheritdoc - */ - swap(obj: base.IContainer>): void; - } -} -declare namespace std.TreeMultiSet { - type iterator = std.SetIterator; - type reverse_iterator = std.SetReverseIterator; -} -declare namespace std { - /** - *

Tree-structured multiple-key set.

- * - *

{@link TreeMultiSet TreeMultiSets} are containers that store elements following a specific order, and - * where multiple elements can have equivalent values.

- * - *

In a {@link TreeMultiSet}, the value of an element also identifies it (the value is itself - * the key, of type T). The value of the elements in a {@link TreeMultiSet} cannot - * be modified once in the container (the elements are always const), but they can be inserted or removed - * from the container.

- * - *

Internally, the elements in a {@link TreeMultiSet TreeMultiSets} are always sorted following a strict - * weak ordering criterion indicated by its internal comparison method (of {@link IComparable.less less}).

- * - *

{@link TreeMultiSet} containers are generally slower than {@link HashMultiSet} containers - * to access individual elements by their key, but they allow the direct iteration on subsets based on - * their order.

- * - *

{@link TreeMultiSet TreeMultiSets} are typically implemented as binary search trees.

- * - *

- *

- * - *

Container properties

- *
- *
Associative
- *
- * Elements in associative containers are referenced by their key and not by their absolute - * position in the container. - *
- * - *
Ordered
- *
- * The elements in the container follow a strict order at all times. All inserted elements are - * given a position in this order. - *
- * - *
Set
- *
The value of an element is also the key used to identify it.
- * - *
Multiple equivalent keys
- *
Multiple elements in the container can have equivalent keys.
- *
- * - * @param Type of the elements. Each element in a {@link TreeMultiSet} container is also identified - * by this value (each value is itself also the element's key). - * - * @reference http://www.cplusplus.com/reference/set/multiset - * @author Jeongho Nam - */ - class TreeMultiSet extends base.MultiSet implements base.ITreeSet { - /** - * @hidden - */ - private tree_; - /** - * Default Constructor. - */ - constructor(); - /** - * Construct from compare. - * - * @param compare A binary predicate determines order of elements. - */ - constructor(compare: (x: T, y: T) => boolean); - /** - * Contruct from elements. - * - * @param array Elements to be contained. - */ - constructor(array: Array); - /** - * Contruct from elements with compare. - * - * @param array Elements to be contained. - * @param compare A binary predicate determines order of elements. - */ - constructor(array: Array, compare: (x: T, y: T) => boolean); - /** - * Copy Constructor. - */ - constructor(container: TreeMultiSet); - /** - * Copy Constructor with compare. - * - * @param container A container to be copied. - * @param compare A binary predicate determines order of elements. - */ - constructor(container: TreeMultiSet, compare: (x: T, y: T) => boolean); - /** - * Range Constructor. - * - * @param begin Input interator of the initial position in a sequence. - * @param end Input interator of the final position in a sequence. - */ - constructor(begin: Iterator, end: Iterator); - /** - * Construct from range and compare. - * - * @param begin Input interator of the initial position in a sequence. - * @param end Input interator of the final position in a sequence. - * @param compare A binary predicate determines order of elements. - */ - constructor(begin: Iterator, end: Iterator, compare: (x: T, y: T) => boolean); - /** - * @inheritdoc - */ - clear(): void; - /** - * @inheritdoc - */ - find(val: T): SetIterator; - /** - * @inheritdoc - */ - count(val: T): number; - /** - * @inheritdoc - */ - key_comp(): (x: T, y: T) => boolean; - /** - * @inheritdoc - */ - value_comp(): (x: T, y: T) => boolean; - /** - * @inheritdoc - */ - lower_bound(val: T): SetIterator; - /** - * @inheritdoc - */ - upper_bound(val: T): SetIterator; - /** - * @inheritdoc - */ - equal_range(val: T): Pair, SetIterator>; - /** - * @hidden - */ - protected _Insert_by_val(val: T): any; - /** - * @hidden - */ - protected _Insert_by_hint(hint: SetIterator, val: T): SetIterator; - /** - * @hidden - */ - protected _Insert_by_range>(first: InputIterator, last: InputIterator): void; - /** - * @inheritdoc - */ - protected _Handle_insert(first: SetIterator, last: SetIterator): void; - /** - * @inheritdoc - */ - protected _Handle_erase(first: SetIterator, last: SetIterator): void; - /** - *

Swap content.

- * - *

Exchanges the content of the container by the content of obj, which is another - * {@link TreeMultiSet set} of the same type. Sizes abd container type may differ.

- * - *

After the call to this member function, the elements in this container are those which were - * in obj before the call, and the elements of obj are those which were in this. All - * iterators, references and pointers remain valid for the swapped objects.

- * - *

Notice that a non-member function exists with the same name, {@link std.swap swap}, overloading that - * algorithm with an optimization that behaves like this member function.

- * - * @param obj Another {@link TreeMultiSet set container} of the same type of elements as this (i.e., - * with the same template parameters, Key and T) whose content is swapped - * with that of this {@link TreeMultiSet container}. - */ - swap(obj: TreeMultiSet): void; - /** - * @inheritdoc - */ - swap(obj: base.IContainer): void; - } -} -declare namespace std.TreeMultiMap { - type iterator = std.MapIterator; - type reverse_iterator = std.MapReverseIterator; -} -declare namespace std { - /** - *

Tree-structured multiple-key map.

- * - *

{@link TreeMultiMap TreeMultiMaps} are associative containers that store elements formed by a combination of - * a key value and a mapped value, following a specific order, and where multiple elements can - * have equivalent keys.

- * - *

In a {@link TreeMultiMap}, the key values are generally used to sort and uniquely identify - * the elements, while the mapped values store the content associated to this key. The types of - * key and mapped value may differ, and are grouped together in member type - * value_type, which is a {@link Pair} type combining both:

- * - *

typedef Pair value_type;

- * - *

Internally, the elements in a {@link TreeMultiMap}are always sorted by its key following a - * strict weak ordering criterion indicated by its internal comparison method (of {@link less}).

- * - *

{@link TreeMultiMap}containers are generally slower than {@link HashMap} containers - * to access individual elements by their key, but they allow the direct iteration on subsets based - * on their order.

- * - *

{@link TreeMultiMap TreeMultiMaps} are typically implemented as binary search trees.

- * - *

< - * img src="http://samchon.github.io/typescript-stl/images/design/class_diagram/map_containers.png" style="max-width: 100%" />

- * - *

Container properties

- *
- *
Associative
- *
- * Elements in associative containers are referenced by their key and not by their absolute - * position in the container. - *
- * - *
Ordered
- *
- * The elements in the container follow a strict order at all times. All inserted elements are - * given a position in this order. - *
- * - *
Map
- *
- * Each element associates a key to a mapped value: - * Keys are meant to identify the elements whose main content is the mapped value. - *
- * - *
Multiple equivalent keys
- *
Multiple elements in the container can have equivalent keys.
- *
- * - * @param Type of the keys. Each element in a map is uniquely identified by its key value. - * @param Type of the mapped value. Each element in a map stores some data as its mapped value. - * - * @reference http://www.cplusplus.com/reference/map/multimap - * @author Jeongho Nam - */ - class TreeMultiMap extends base.MultiMap implements base.ITreeMap { - /** - * @hidden - */ - private tree_; - /** - * Default Constructor. - */ - constructor(); - /** - * Construct from compare. - * - * @param compare A binary predicate determines order of elements. - */ - constructor(compare: (x: Key, y: Key) => boolean); - /** - * Contruct from elements. - * - * @param array Elements to be contained. - */ - constructor(array: Array>); - /** - * Contruct from elements. - * - * @param array Elements to be contained. - * @param compare A binary predicate determines order of elements. - */ - constructor(array: Array>, compare: (x: Key, y: Key) => boolean); - /** - * Contruct from tuples. - * - * @param array Tuples to be contained. - */ - constructor(array: Array<[Key, T]>); - /** - * Contruct from tuples. - * - * @param array Tuples to be contained. - * @param compare A binary predicate determines order of elements. - */ - constructor(array: Array<[Key, T]>, compare: (x: Key, y: Key) => boolean); - /** - * Copy Constructor. - * - * @param container Another map to copy. - */ - constructor(container: TreeMultiMap); - /** - * Copy Constructor. - * - * @param container Another map to copy. - * @param compare A binary predicate determines order of elements. - */ - constructor(container: TreeMultiMap, compare: (x: Key, y: Key) => boolean); - /** - * Range Constructor. - * - * @param begin nput interator of the initial position in a sequence. - * @param end Input interator of the final position in a sequence. - */ - constructor(begin: Iterator>, end: Iterator>); - /** - * Range Constructor. - * - * @param begin nput interator of the initial position in a sequence. - * @param end Input interator of the final position in a sequence. - * @param compare A binary predicate determines order of elements. - */ - constructor(begin: Iterator>, end: Iterator>, compare: (x: Key, y: Key) => boolean); - /** - * @inheritdoc - */ - clear(): void; - /** - * @inheritdoc - */ - find(key: Key): MapIterator; - /** - * @inheritdoc - */ - count(key: Key): number; - /** - * @inheritdoc - */ - key_comp(): (x: Key, y: Key) => boolean; - /** - * @inheritdoc - */ - value_comp(): (x: Pair, y: Pair) => boolean; - /** - * @inheritdoc - */ - lower_bound(key: Key): MapIterator; - /** - * @inheritdoc - */ - upper_bound(key: Key): MapIterator; - /** - * @inheritdoc - */ - equal_range(key: Key): Pair, MapIterator>; - /** - * @hidden - */ - protected _Insert_by_pair(pair: Pair): any; - /** - * @hidden - */ - protected _Insert_by_hint(hint: MapIterator, pair: Pair): MapIterator; - /** - * @hidden - */ - protected _Insert_by_range>>(first: InputIterator, last: InputIterator): void; - /** - * @inheritdoc - */ - protected _Handle_insert(first: MapIterator, last: MapIterator): void; - /** - * @inheritdoc - */ - protected _Handle_erase(first: MapIterator, last: MapIterator): void; - /** - *

Swap content.

- * - *

Exchanges the content of the container by the content of obj, which is another - * {@link TreeMapMulti map} of the same type. Sizes abd container type may differ.

- * - *

After the call to this member function, the elements in this container are those which were - * in obj before the call, and the elements of obj are those which were in this. All - * iterators, references and pointers remain valid for the swapped objects.

- * - *

Notice that a non-member function exists with the same name, {@link std.swap swap}, overloading that - * algorithm with an optimization that behaves like this member function.

- * - * @param obj Another {@link TreeMapMulti map container} of the same type of elements as this (i.e., - * with the same template parameters, Key and T) whose content is swapped - * with that of this {@link TreeMapMulti container}. - */ - swap(obj: TreeMultiMap): void; - /** - * @inheritdoc - */ - swap(obj: base.IContainer>): void; - } -} -declare namespace std { - /** - *

System error exception.

- * - *

This class defines the type of objects thrown as exceptions to report conditions originating during - * runtime from the operating system or other low-level application program interfaces which have an - * associated {@link ErrorCode}.

- * - *

The class inherits from {@link RuntimeError}, to which it adds an {@link ErrorCode} as - * member code (and defines a specialized what member).

- * - *

- *

- * - * @reference http://www.cplusplus.com/reference/system_error/system_error - * @author Jeongho Nam - */ - class SystemError extends RuntimeError { - /** - * @hidden - */ - protected code_: ErrorCode; - /** - * Construct from an error code. - * - * @param code An {@link ErrorCode} object. - */ - constructor(code: ErrorCode); - /** - * Construct from an error code and message. - * - * @param code An {@link ErrorCode} object. - * @param message A message incorporated in the string returned by member {@link what what()}. - */ - constructor(code: ErrorCode, message: string); - /** - * Construct from a numeric value and error category. - * - * @param val A numerical value identifying an error code. - * @param category A reference to an {@link ErrorCode} object. - */ - constructor(val: number, category: ErrorCategory); - /** - * Construct from a numeric value, error category and message. - * - * @param val A numerical value identifying an error code. - * @param category A reference to an {@link ErrorCode} object. - * @param message A message incorporated in the string returned by member {@link what what()}. - */ - constructor(val: number, category: ErrorCategory, message: string); - /** - *

Get error code.

- * - *

Returns the {@link ErrorCode} object associated with the exception.

- * - *

This value is either the {@link ErrorCode} passed to the construction or its equivalent - * (if constructed with a value and a {@link category}.

- * - * @return The {@link ErrorCode} associated with the object. - */ - code(): ErrorCode; - } -} -declare namespace std { - /** - *

Error category.

- * - *

This type serves as a base class for specific category types.

- * - *

Category types are used to identify the source of an error. They also define the relation between - * {@link ErrorCode} and {@link ErrorCondition}objects of its category, as well as the message set for {@link ErrorCode} - * objects. - * - *

Objects of these types have no distinct values and are not-copyable and not-assignable, and thus can only be - * passed by reference. As such, only one object of each of these types shall exist, each uniquely identifying its own - * category: all error codes and conditions of a same category shall return a reference to same object.

- * - *

- *

- * - * @reference http://www.cplusplus.com/reference/system_error/error_category - * @author Jeongho Nam - */ - abstract class ErrorCategory { - /** - * Default Constructor. - */ - constructor(); - /** - *

Return category name.

- * - *

In derived classes, the function returns a string naming the category.

- * - *

In {@link ErrorCategory}, it is a pure virtual member function.

- * - *
    - *
  • In the {@link GenericCategory} object, it returns "generic".
  • - *
  • In the {@link SystemCategory} object, it returns "system".
  • - *
  • In the {@link IOStreamCategory} object, it returns "iostream".
  • - *
- * - * @return The category name. - */ - abstract name(): string; - /** - *

Error message.

- * - *

In derived classes, the function returns a string object with a message describing the error condition - * denoted by val.

- * - *

In {@link ErrorCategory}, it is a pure virtual member function.

- * - *

This function is called both by {@link ErrorCode.message ErrorCode.message()} and - * {@link ErrorCondition.message ErrorCondition.message()} to obtain the corresponding message in the - * {@link category}. Therefore, numerical values used by custom error codes and - * {@link ErrorCondition error conditions} should only match for a category if they describe the same error.

- * - * @param val A numerical value identifying an error condition. - * If the {@link ErrorCategory} object is the {@link GenericCategory}, this argument is equivalent to an - * {@link errno} value. - * - * @return A string object with the message. - */ - abstract message(val: number): string; - /** - *

Default error condition.

- * - *

Returns the default {@link ErrorCondition}object of this category that is associated with the - * {@link ErrorCode} identified by a value of val.

- * - *

Its definition in the base class {@link ErrorCategory} returns the same as constructing an - * {@link ErrorCondition} object with: - * - *

new ErrorCondition(val, *this);

- * - *

As a virtual member function, this behavior can be overriden in derived classes.

- * - *

This function is called by the default definition of member {@link equivalent equivalent()}, which is used to - * compare {@link ErrorCondition error conditions} with error codes.

- * - * @param val A numerical value identifying an error condition. - * - * @return The default {@link ErrorCondition}object associated with condition value val for this category. - */ - default_error_condition(val: number): ErrorCondition; - /** - *

Check error code equivalence.

- * - *

Checks whether, for the category, an {@link ErrorCode error code} is equivalent to an - * {@link ErrorCondition error condition.

- * - *

This function is called by the overloads of comparison operators when an {@link ErrorCondition} object is - * compared to an {@link ErrorCode} object to check for equality or inequality. If either one of those objects' - * {@link ErrorCategory categories} considers the other equivalent using this function, they are considered - * equivalent by the operator.

- * - *

As a virtual member function, this behavior can be overridden in derived classes to define a different - * correspondence mechanism for each {@link ErrorCategory} type.

- * - * @param val_code A numerical value identifying an error code. - * @param cond An object of an {@link ErrorCondition} type. - * - * @return true if the arguments are considered equivalent. false otherwise. - */ - equivalent(val_code: number, cond: ErrorCondition): boolean; - /** - *

Check error code equivalence.

- * - *

Checks whether, for the category, an {@link ErrorCode error code} is equivalent to an - * {@link ErrorCondition error condition.

- * - *

This function is called by the overloads of comparison operators when an {@link ErrorCondition} object is - * compared to an {@link ErrorCode} object to check for equality or inequality. If either one of those objects' - * {@link ErrorCategory categories} considers the other equivalent using this function, they are considered - * equivalent by the operator.

- * - *

As a virtual member function, this behavior can be overridden in derived classes to define a different - * correspondence mechanism for each {@link ErrorCategory} type.

- * - * @param code An object of an {@link ErrorCode} type. - * @param val_cond A numerical value identifying an error code. - * - * @return true if the arguments are considered equivalent. false otherwise. - */ - equivalent(code: ErrorCode, val_cond: number): boolean; - } -} -declare namespace std { - /** - *

Error condition.

- * - *

Objects of this type hold a condition {@link value} associated with a {@link category}.

- * - *

Objects of this type describe errors in a generic way so that they may be portable across different - * systems. This is in contrast with {@link ErrorCode} objects, that may contain system-specific - * information.

- * - *

Because {@link ErrorCondition}objects can be compared with error_code objects directly by using - * relational operators, {@link ErrorCondition}objects are generally used to check whether - * a particular {@link ErrorCode} obtained from the system matches a specific error condition no matter - * the system.

- * - *

The {@link ErrorCategory categories} associated with the {@link ErrorCondition} and the - * {@link ErrorCode} define the equivalences between them.

- * - *

- *

- * - * @reference http://www.cplusplus.com/reference/system_error/error_condition - * @author Jeongho Nam - */ - class ErrorCondition extends base.ErrorInstance { - /** - * Default Constructor. - */ - constructor(); - /** - * Construct from a numeric value and error category. - * - * @param val A numerical value identifying an error condition. - * @param category A reference to an {@link ErrorCategory} object. - */ - constructor(val: number, category: ErrorCategory); - } -} -declare namespace std { - /** - *

Error code.

- * - *

Objects of this type hold an error code {@link value} associated with a {@link category}.

- * - *

The operating system and other low-level applications and libraries generate numerical error codes to - * represent possible results. These numerical values may carry essential information for a specific platform, - * but be non-portable from one platform to another.

- * - *

Objects of this class associate such numerical codes to {@link ErrorCategory error categories}, so that they - * can be interpreted when needed as more abstract (and portable) {@link ErrorCondition error conditions}.

- * - *

- *

- * - * @reference http://www.cplusplus.com/reference/system_error/error_code - * @author Jeongho Nam - */ - class ErrorCode extends base.ErrorInstance { - /** - * Default Constructor. - */ - constructor(); - /** - * Construct from a numeric value and error category. - * - * @param val A numerical value identifying an error code. - * @param category A reference to an {@link ErrorCategory} object. - */ - constructor(val: number, category: ErrorCategory); - } -} -declare namespace std { - /** - *

Running on Node.

- * - *

Test whether the JavaScript is running on Node.

- * - * @references http://stackoverflow.com/questions/17575790/environment-detection-node-js-or-browser - */ - function is_node(): boolean; - /** - *

Pair of values.

- * - *

This class couples together a pair of values, which may be of different types (T1 and - * T2). The individual values can be accessed through its public members {@link first} and - * {@link second}.

- * - * @param Type of member {@link first}. - * @param Type of member {@link second}. - * - * @reference http://www.cplusplus.com/reference/utility/pair - * @author Jeongho Nam - */ - class Pair implements IComparable> { - /** - *

A first value in the Pair.

- */ - first: T1; - /** - *

A second value in the Pair.

- */ - second: T2; - /** - *

Construct from pair values.

- * - * @param first The first value of the Pair - * @param second The second value of the Pair - */ - constructor(first: T1, second: T2); - /** - *

Whether a Pair is equal with the Pair.

- *

Compare each first and second value of two Pair(s) and returns whether they are equal or not.

- * - *

If stored key and value in a Pair are not number or string but an object like a class or struct, - * the comparison will be executed by a member method (SomeObject)::equal_to(). If the object does not have - * the member method equal_to(), only address of pointer will be compared.

- * - * @param obj A Map to compare - * @return Indicates whether equal or not. - */ - equals(pair: Pair): boolean; - /** - * @inheritdoc - */ - less(pair: Pair): boolean; - } - /** - *

Construct {@link Pair} object.

- * - *

Constructs a {@link Pair} object with its {@link Pair.first first} element set to x and its - * {@link Pair.second second} element set to y.

- * - *

The template types can be implicitly deduced from the arguments passed to {@link make_pair}.

- * - *

{@link Pair} objects can be constructed from other {@link Pair} objects containing different types, if the - * respective types are implicitly convertible.

- * - * @param x Value for member {@link Pair.first first}. - * @param y Value for member {@link Pair.second second}. - * - * @return A {@link Pair} object whose elements {@link Pair.first first} and {@link Pair.second second} are set to - * x and y respectivelly. - */ - function make_pair(x: T1, y: T2): Pair; -} -declare namespace std { - /** - * Type definition of {@link Vector} and it's the original name used in C++. - */ - export import vector = Vector; - /** - * Type definition of {@link List} and it's the original name used in C++. - */ - export import list = List; - /** - * Type definition of {@link Deque} and it's the original name used in C++. - */ - export import deque = Deque; - /** - * Type definition of {@link Stack} and it's the original name used in C++. - */ - type stack = Stack; - /** - * Type definition of {@link Queue} and it's the original name used in C++. - */ - type queue = Queue; - /** - * Type definition of {@link PriorityQueue} and it's the original name used in C++. - */ - type priority_queue = PriorityQueue; - var stack: typeof Stack; - var queue: typeof Queue; - var priority_queue: typeof PriorityQueue; - /** - * Type definition of {@link TreeSet} and it's the original name used in C++. - */ - export import set = TreeSet; - /** - * Type definition of {@link TreeMultiSet} and it's the original name used in C++. - */ - export import multiset = TreeMultiSet; - /** - * Type definition of {@link HashSet} and it's the original name used in C++. - */ - export import unordered_set = HashSet; - /** - * Type definition of {@link HashMultiSet} and it's the original name used in C++. - */ - export import unordered_multiset = HashMultiSet; - /** - * Type definition of {@link TreeMap} and it's the original name used in C++. - */ - export import map = TreeMap; - /** - * Type definition of {@link TreeMultiMap} and it's the original name used in C++. - */ - export import multimap = TreeMultiMap; - /** - * Type definition of {@link HashMap} and it's the original name used in C++. - */ - export import unordered_map = HashMap; - /** - * Type definition of {@link HashMultiMap} and it's the original name used in C++. - */ - export import unordered_multimap = HashMultiMap; - type exception = Exception; - type logic_error = LogicError; - type domain_error = DomainError; - type invalid_argument = InvalidArgument; - type length_error = LengthError; - type out_of_range = OutOfRange; - type runtime_error = RuntimeError; - type overflow_error = OverflowError; - type underflow_error = UnderflowError; - type range_error = RangeError; - type system_error = SystemError; - type error_category = ErrorCategory; - type error_condition = ErrorCondition; - type error_code = ErrorCode; - var exception: typeof Exception; - var logic_error: typeof LogicError; - var domain_error: typeof DomainError; - var invalid_argument: typeof InvalidArgument; - var length_error: typeof LengthError; - var out_of_range: typeof OutOfRange; - var runtime_error: typeof RuntimeError; - var overflow_error: typeof OverflowError; - var underflow_error: typeof UnderflowError; - var range_error: typeof RangeError; - var system_error: typeof SystemError; - var error_category: typeof ErrorCategory; - var error_condition: typeof ErrorCondition; - var error_code: typeof ErrorCode; -} +} \ No newline at end of file

This namespace declares an unspecified number of objects: _1, _2, _3, ..., which are - * used to specify placeholders in calls to function {@link std.bind}.