import { IDisposable, disposeSafe, defaultOf, MutableArray, toIterator, IEnumerator, getEnumerator, structuralHash, equals as equals_1, IEqualityComparer, compare, IComparer, Exception } from "./Util.ts"; import { class_type, TypeInfo } from "./Reflection.ts"; import { SR_Arg_KeyNotFound } from "./Global.ts"; import { int32 } from "./Int32.ts"; import { toArray, empty, singleton, append, enumerateWhile, delay } from "./Seq.ts"; import { setItem, initialize, copyTo, fill, item as item_1 } from "./Array.ts"; import { max } from "./Double.ts"; import { FSharpRef } from "./Types.ts"; import { ArgumentOutOfRangeException_$ctor_Z721C83C5 } from "./System.ts"; export class KeyNotFoundException extends Exception { constructor(message: string) { super(message); } } export function KeyNotFoundException_$reflection(): TypeInfo { return class_type("System.Collections.Generic.KeyNotFoundException", undefined, KeyNotFoundException, class_type("System.Exception")); } export function KeyNotFoundException_$ctor_Z721C83C5(message: string): KeyNotFoundException { return new KeyNotFoundException(message); } export function KeyNotFoundException_$ctor(): KeyNotFoundException { return KeyNotFoundException_$ctor_Z721C83C5(SR_Arg_KeyNotFound); } export class Comparer$1 implements IComparer { readonly comparison: ((arg0: T, arg1: T) => int32); constructor(comparison: ((arg0: T, arg1: T) => int32)) { this.comparison = comparison; } Compare(x: T, y: T): int32 { const _: Comparer$1 = this; return ((x == null) ? ((y == null) ? 0 : -1) : ((y == null) ? 1 : _.comparison(x, y))) | 0; } } export function Comparer$1_$reflection(gen0: TypeInfo): TypeInfo { return class_type("System.Collections.Generic.Comparer`1", [gen0], Comparer$1); } export function Comparer$1_$ctor_47C913C(comparison: ((arg0: T, arg1: T) => int32)): Comparer$1 { return new Comparer$1(comparison); } export function Comparer$1_get_Default(): Comparer$1 { return Comparer$1_$ctor_47C913C((e: T, e_1: T): int32 => (compare(e, e_1) | 0)); } export function Comparer$1_Create_47C913C(comparison: ((arg0: T, arg1: T) => int32)): Comparer$1 { return Comparer$1_$ctor_47C913C(comparison); } export function Comparer$1__Compare_5BDDA0(_: Comparer$1, x: T, y: T): int32 { return _.comparison(x, y) | 0; } export class EqualityComparer$1 implements IEqualityComparer { readonly getHashCode: ((arg0: T) => int32); readonly equals: ((arg0: T, arg1: T) => boolean); constructor(equals: ((arg0: T, arg1: T) => boolean), getHashCode: ((arg0: T) => int32)) { this.equals = equals; this.getHashCode = getHashCode; } Equals(x: T, y: T): boolean { const _: EqualityComparer$1 = this; return (x == null) ? (y == null) : ((y == null) ? false : _.equals(x, y)); } GetHashCode(x: T): int32 { const _: EqualityComparer$1 = this; return _.getHashCode(x) | 0; } } export function EqualityComparer$1_$reflection(gen0: TypeInfo): TypeInfo { return class_type("System.Collections.Generic.EqualityComparer`1", [gen0], EqualityComparer$1); } export function EqualityComparer$1_$ctor_Z6EE254AB(equals: ((arg0: T, arg1: T) => boolean), getHashCode: ((arg0: T) => int32)): EqualityComparer$1 { return new EqualityComparer$1(equals, getHashCode); } export function EqualityComparer$1_get_Default(): EqualityComparer$1 { return EqualityComparer$1_$ctor_Z6EE254AB(equals_1, (obj: T): int32 => (structuralHash(obj) | 0)); } export function EqualityComparer$1_Create_Z6EE254AB(equals: ((arg0: T, arg1: T) => boolean), getHashCode: ((arg0: T) => int32)): EqualityComparer$1 { return EqualityComparer$1_$ctor_Z6EE254AB(equals, getHashCode); } export function EqualityComparer$1__Equals_5BDDA0(_: EqualityComparer$1, x: T, y: T): boolean { return _.equals(x, y); } export function EqualityComparer$1__GetHashCode_2B595(_: EqualityComparer$1, x: T): int32 { return _.getHashCode(x) | 0; } export class Stack$1 implements Iterable { contents: MutableArray; count: int32; constructor(initialContents: MutableArray, initialCount: int32) { this.contents = initialContents; this.count = (initialCount | 0); } GetEnumerator(): IEnumerator { const _: Stack$1 = this; return getEnumerator(delay((): Iterable => { let index: int32 = _.count - 1; return enumerateWhile((): boolean => (index >= 0), delay((): Iterable => append(singleton(item_1(index, _.contents)), delay((): Iterable => { index = ((index - 1) | 0); return empty(); })))); })); } [Symbol.iterator](): Iterator { return toIterator(getEnumerator(this)); } "System.Collections.IEnumerable.GetEnumerator"(): IEnumerator { const this$: Stack$1 = this; return getEnumerator(this$); } } export function Stack$1_$reflection(gen0: TypeInfo): TypeInfo { return class_type("System.Collections.Generic.Stack`1", [gen0], Stack$1); } function Stack$1_$ctor_Z3B4C077E(initialContents: MutableArray, initialCount: int32): Stack$1 { return new Stack$1(initialContents, initialCount); } export function Stack$1_$ctor_Z524259A4(initialCapacity: int32): Stack$1 { return Stack$1_$ctor_Z3B4C077E(fill(new Array(initialCapacity), 0, initialCapacity, null), 0); } export function Stack$1_$ctor(): Stack$1 { return Stack$1_$ctor_Z524259A4(4); } export function Stack$1_$ctor_BB573A(xs: Iterable): Stack$1 { const arr: MutableArray = Array.from(xs); return Stack$1_$ctor_Z3B4C077E(arr, arr.length); } export function Stack$1__Ensure_Z524259A4(_: Stack$1, newSize: int32): void { const oldSize: int32 = _.contents.length | 0; if (newSize > oldSize) { const old: MutableArray = _.contents; _.contents = fill(new Array(max(newSize, oldSize * 2)), 0, max(newSize, oldSize * 2), null); copyTo(old, 0, _.contents, 0, _.count); } } export function Stack$1__get_Count(_: Stack$1): int32 { return _.count | 0; } export function Stack$1__Pop(_: Stack$1): T { _.count = ((_.count - 1) | 0); return item_1(_.count, _.contents); } export function Stack$1__Peek(_: Stack$1): T { return item_1(_.count - 1, _.contents); } export function Stack$1__Contains_2B595(_: Stack$1, x: T): boolean { let found = false; let i = 0; while ((i < _.count) && !found) { if (equals_1(x, item_1(i, _.contents))) { found = true; } else { i = ((i + 1) | 0); } } return found; } export function Stack$1__TryPeek_1F3DB691(this$: Stack$1, result: FSharpRef): boolean { if (this$.count > 0) { result.contents = Stack$1__Peek(this$); return true; } else { return false; } } export function Stack$1__TryPop_1F3DB691(this$: Stack$1, result: FSharpRef): boolean { if (this$.count > 0) { result.contents = Stack$1__Pop(this$); return true; } else { return false; } } export function Stack$1__Push_2B595(this$: Stack$1, x: T): void { Stack$1__Ensure_Z524259A4(this$, this$.count + 1); this$.contents[this$.count] = x; this$.count = ((this$.count + 1) | 0); } export function Stack$1__Clear(_: Stack$1): void { _.count = 0; fill(_.contents, 0, _.contents.length, defaultOf()); } export function Stack$1__TrimExcess(this$: Stack$1): void { if ((this$.count / this$.contents.length) > 0.9) { Stack$1__Ensure_Z524259A4(this$, this$.count); } } export function Stack$1__ToArray(_: Stack$1): MutableArray { return initialize(_.count, (i: int32): T => item_1((_.count - 1) - i, _.contents)); } export class Queue$1 implements Iterable { contents: MutableArray; count: int32; head: int32; tail: int32; constructor(initialContents: MutableArray, initialCount: int32) { this.contents = initialContents; this.count = (initialCount | 0); this.head = 0; this.tail = (((initialCount === this.contents.length) ? 0 : initialCount) | 0); } GetEnumerator(): IEnumerator { const _: Queue$1 = this; return getEnumerator(Queue$1__toSeq(_)); } [Symbol.iterator](): Iterator { return toIterator(getEnumerator(this)); } "System.Collections.IEnumerable.GetEnumerator"(): IEnumerator { const this$: Queue$1 = this; return getEnumerator(this$); } } export function Queue$1_$reflection(gen0: TypeInfo): TypeInfo { return class_type("System.Collections.Generic.Queue`1", [gen0], Queue$1); } function Queue$1_$ctor_Z3B4C077E(initialContents: MutableArray, initialCount: int32): Queue$1 { return new Queue$1(initialContents, initialCount); } export function Queue$1_$ctor_Z524259A4(initialCapacity: int32): Queue$1 { if (initialCapacity < 0) { throw ArgumentOutOfRangeException_$ctor_Z721C83C5("capacity is less than 0"); } return Queue$1_$ctor_Z3B4C077E(fill(new Array(initialCapacity), 0, initialCapacity, null), 0); } export function Queue$1_$ctor(): Queue$1 { return Queue$1_$ctor_Z524259A4(4); } export function Queue$1_$ctor_BB573A(xs: Iterable): Queue$1 { const arr: MutableArray = Array.from(xs); return Queue$1_$ctor_Z3B4C077E(arr, arr.length); } export function Queue$1__get_Count(_: Queue$1): int32 { return _.count | 0; } export function Queue$1__Enqueue_2B595(_: Queue$1, value: T): void { if (_.count === Queue$1__size(_)) { Queue$1__ensure_Z524259A4(_, _.count + 1); } _.contents[_.tail] = value; _.tail = (((_.tail + 1) % Queue$1__size(_)) | 0); _.count = ((_.count + 1) | 0); } export function Queue$1__Dequeue(_: Queue$1): T { if (_.count === 0) { throw new Exception("Queue is empty"); } const value: T = item_1(_.head, _.contents); _.head = (((_.head + 1) % Queue$1__size(_)) | 0); _.count = ((_.count - 1) | 0); return value; } export function Queue$1__Peek(_: Queue$1): T { if (_.count === 0) { throw new Exception("Queue is empty"); } return item_1(_.head, _.contents); } export function Queue$1__TryDequeue_1F3DB691(this$: Queue$1, result: FSharpRef): boolean { if (this$.count === 0) { return false; } else { result.contents = Queue$1__Dequeue(this$); return true; } } export function Queue$1__TryPeek_1F3DB691(this$: Queue$1, result: FSharpRef): boolean { if (this$.count === 0) { return false; } else { result.contents = Queue$1__Peek(this$); return true; } } export function Queue$1__Contains_2B595(_: Queue$1, x: T): boolean { let found = false; let i = 0; while ((i < _.count) && !found) { if (equals_1(x, item_1(Queue$1__toIndex_Z524259A4(_, i), _.contents))) { found = true; } else { i = ((i + 1) | 0); } } return found; } export function Queue$1__Clear(_: Queue$1): void { _.count = 0; _.head = 0; _.tail = 0; fill(_.contents, 0, Queue$1__size(_), defaultOf()); } export function Queue$1__TrimExcess(_: Queue$1): void { if ((_.count / _.contents.length) > 0.9) { Queue$1__ensure_Z524259A4(_, _.count); } } export function Queue$1__ToArray(_: Queue$1): MutableArray { return toArray(Queue$1__toSeq(_)); } export function Queue$1__CopyTo_Z3B4C077E(_: Queue$1, target: MutableArray, start: int32): void { let i: int32 = start; const enumerator: IEnumerator = getEnumerator(Queue$1__toSeq(_)); try { while (enumerator["System.Collections.IEnumerator.MoveNext"]()) { const item: T = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"](); setItem(target, i, item); i = ((i + 1) | 0); } } finally { disposeSafe(enumerator as IDisposable); } } export function Queue$1__size(this$: Queue$1): int32 { return this$.contents.length | 0; } export function Queue$1__toIndex_Z524259A4(this$: Queue$1, i: int32): int32 { return ((this$.head + i) % Queue$1__size(this$)) | 0; } export function Queue$1__ensure_Z524259A4(this$: Queue$1, requiredSize: int32): void { const newBuffer: MutableArray = fill(new Array(requiredSize), 0, requiredSize, null); if (this$.head < this$.tail) { copyTo(this$.contents, this$.head, newBuffer, 0, this$.count); } else { copyTo(this$.contents, this$.head, newBuffer, 0, Queue$1__size(this$) - this$.head); copyTo(this$.contents, 0, newBuffer, Queue$1__size(this$) - this$.head, this$.tail); } this$.head = 0; this$.contents = newBuffer; this$.tail = (((this$.count === Queue$1__size(this$)) ? 0 : this$.count) | 0); } export function Queue$1__toSeq(this$: Queue$1): Iterable { return delay((): Iterable => { let i = 0; return enumerateWhile((): boolean => (i < this$.count), delay((): Iterable => append(singleton(item_1(Queue$1__toIndex_Z524259A4(this$, i), this$.contents)), delay((): Iterable => { i = ((i + 1) | 0); return empty(); })))); }); }