//================================================================ /** * @packageDocumentation * @module std.internal */ //================================================================ import { ListContainer } from "../linear/ListContainer"; import { ListIterator } from "../../iterator/ListIterator"; import { ReverseIterator as _ReverseIterator } from "../../iterator/ReverseIterator"; import { SetContainer } from "../../../base/container/SetContainer"; /** * Doubly Linked List storing set elements. * * @template Key Key type * @template Unique Whether duplicated key is blocked or not * @template Source Source container type * * @author Jeongho Nam - https://github.com/samchon */ export class SetElementList< Key, Unique extends boolean, Source extends SetContainer< Key, Unique, Source, SetElementList.Iterator, SetElementList.ReverseIterator >, > extends ListContainer< Key, Source, SetElementList.Iterator, SetElementList.ReverseIterator > { private associative_: Source; /* --------------------------------------------------------- CONSTRUCTORS --------------------------------------------------------- */ public constructor(associative: Source) { super(); this.associative_ = associative; } protected _Create_iterator( prev: SetElementList.Iterator, next: SetElementList.Iterator, val: Key, ): SetElementList.Iterator { return SetElementList.Iterator.create(this, prev, next, val); } /** * @internal */ public static _Swap_associative< Key, Unique extends boolean, Source extends SetContainer< Key, Unique, Source, SetElementList.Iterator, SetElementList.ReverseIterator >, >( x: SetElementList, y: SetElementList, ): void { [x.associative_, y.associative_] = [y.associative_, x.associative_]; } /* --------------------------------------------------------- ACCESSORS --------------------------------------------------------- */ public associative(): Source { return this.associative_; } } /** * */ export namespace SetElementList { /** * Iterator of set container storing elements in a list. * * @template Key Key type * @template Unique Whether duplicated key is blocked or not * @template Source Source container type * * @author Jeongho Nam - https://github.com/samchon */ export class Iterator< Key, Unique extends boolean, Source extends SetContainer< Key, Unique, Source, Iterator, ReverseIterator >, > extends ListIterator< Key, Source, Iterator, ReverseIterator, Key > implements SetContainer.Iterator< Key, Unique, Source, Iterator, ReverseIterator > { private source_: SetElementList; /* --------------------------------------------------------- CONSTRUCTORS --------------------------------------------------------- */ private constructor( list: SetElementList, prev: Iterator, next: Iterator, val: Key, ) { super(prev, next, val); this.source_ = list; } /** * @internal */ public static create< Key, Unique extends boolean, Source extends SetContainer< Key, Unique, Source, Iterator, ReverseIterator >, >( list: SetElementList, prev: Iterator, next: Iterator, val: Key, ) { return new Iterator(list, prev, next, val); } /** * @inheritDoc */ public reverse(): ReverseIterator { return new ReverseIterator(this); } /* --------------------------------------------------------- ACCESSORS --------------------------------------------------------- */ /** * @inheritDoc */ public source(): Source { return this.source_.associative(); } } /** * Reverser iterator of set container storing elements in a list. * * @template Key Key type * @template Unique Whether duplicated key is blocked or not * @template Source Source container type * * @author Jeongho Nam - https://github.com/samchon */ export class ReverseIterator< Key, Unique extends boolean, Source extends SetContainer< Key, Unique, Source, Iterator, ReverseIterator >, > extends _ReverseIterator< Key, Source, Iterator, ReverseIterator, Key > implements SetContainer.ReverseIterator< Key, Unique, Source, Iterator, ReverseIterator > { protected _Create_neighbor( base: Iterator, ): ReverseIterator { return new ReverseIterator(base); } } }