import { record_type, bool_type, list_type, option_type, class_type, TypeInfo } from "./Reflection.ts"; import { some, value as value_1, Option } from "./Option.ts"; import { int32 } from "./Int32.ts"; import { structuralHash, IMap, compare, toIterator, equals, IDisposable, disposeSafe, getEnumerator, isArrayLike, IEnumerator, MutableArray, IComparer, Exception } from "./Util.ts"; import { KeyNotFoundException_$ctor } from "./System.Collections.Generic.ts"; import { singleton, ofArrayWithTail, head, tail, isEmpty as isEmpty_1, fold as fold_1, empty as empty_1, FSharpList, cons } from "./List.ts"; import { map as map_2, item, fill, setItem } from "./Array.ts"; import { FSharpRef, Record } from "./Types.ts"; import { tryPick as tryPick_1, pick as pick_1, iterate as iterate_1, compareWith, map as map_1, unfold } from "./Seq.ts"; import { format, join } from "./String.ts"; import { NotSupportedException_$ctor_Z721C83C5 } from "./System.ts"; export class MapTreeLeaf$2 { readonly v: Value; readonly k: Key; constructor(k: Key, v: Value) { this.k = k; this.v = v; } } export function MapTreeLeaf$2_$reflection(gen0: TypeInfo, gen1: TypeInfo): TypeInfo { return class_type("Map.MapTreeLeaf`2", [gen0, gen1], MapTreeLeaf$2); } export function MapTreeLeaf$2_$ctor_5BDDA1(k: Key, v: Value): MapTreeLeaf$2 { return new MapTreeLeaf$2(k, v); } export function MapTreeLeaf$2__get_Key(_: MapTreeLeaf$2): Key { return _.k; } export function MapTreeLeaf$2__get_Value(_: MapTreeLeaf$2): Value { return _.v; } export class MapTreeNode$2 extends MapTreeLeaf$2 { readonly right: Option>; readonly left: Option>; readonly h: int32; constructor(k: Key, v: Value, left: Option>, right: Option>, h: int32) { super(k, v); this.left = left; this.right = right; this.h = (h | 0); } } export function MapTreeNode$2_$reflection(gen0: TypeInfo, gen1: TypeInfo): TypeInfo { return class_type("Map.MapTreeNode`2", [gen0, gen1], MapTreeNode$2, MapTreeLeaf$2_$reflection(gen0, gen1)); } export function MapTreeNode$2_$ctor_Z39DE9543(k: Key, v: Value, left: Option>, right: Option>, h: int32): MapTreeNode$2 { return new MapTreeNode$2(k, v, left, right, h); } export function MapTreeNode$2__get_Left(_: MapTreeNode$2): Option> { return _.left; } export function MapTreeNode$2__get_Right(_: MapTreeNode$2): Option> { return _.right; } export function MapTreeNode$2__get_Height(_: MapTreeNode$2): int32 { return _.h | 0; } export function MapTreeModule_empty(): Option> { return undefined; } export function MapTreeModule_sizeAux(acc_mut: int32, m_mut: Option>): int32 { MapTreeModule_sizeAux: while (true) { const acc: int32 = acc_mut, m: Option> = m_mut; if (m != null) { const m2: MapTreeLeaf$2 = value_1(m); if (m2 instanceof MapTreeNode$2) { const mn = m2 as MapTreeNode$2; acc_mut = MapTreeModule_sizeAux(acc + 1, MapTreeNode$2__get_Left(mn)); m_mut = MapTreeNode$2__get_Right(mn); continue MapTreeModule_sizeAux; } else { return (acc + 1) | 0; } } else { return acc | 0; } break; } } export function MapTreeModule_size<$a, $b>(x: Option>): int32 { return MapTreeModule_sizeAux<$a, $b>(0, x) | 0; } export function MapTreeModule_mk(l: Option>, k: Key, v: Value, r: Option>): Option> { let mn: MapTreeNode$2 = (undefined as any), mn_1: MapTreeNode$2 = (undefined as any); let hl: int32; const m: Option> = l; if (m != null) { const m2: MapTreeLeaf$2 = value_1(m); hl = ((m2 instanceof MapTreeNode$2) ? ((mn = (m2 as MapTreeNode$2), MapTreeNode$2__get_Height(mn))) : 1); } else { hl = 0; } let hr: int32; const m_1: Option> = r; if (m_1 != null) { const m2_1: MapTreeLeaf$2 = value_1(m_1); hr = ((m2_1 instanceof MapTreeNode$2) ? ((mn_1 = (m2_1 as MapTreeNode$2), MapTreeNode$2__get_Height(mn_1))) : 1); } else { hr = 0; } const m_2: int32 = ((hl < hr) ? hr : hl) | 0; if (m_2 === 0) { return MapTreeLeaf$2_$ctor_5BDDA1(k, v); } else { return MapTreeNode$2_$ctor_Z39DE9543(k, v, l, r, m_2 + 1); } } export function MapTreeModule_rebalance(t1: Option>, k: Key, v: Value, t2: Option>): Option> { let mn: MapTreeNode$2 = (undefined as any), mn_1: MapTreeNode$2 = (undefined as any), m_2: Option> = (undefined as any), m2_2: MapTreeLeaf$2 = (undefined as any), mn_2: MapTreeNode$2 = (undefined as any), m_3: Option> = (undefined as any), m2_3: MapTreeLeaf$2 = (undefined as any), mn_3: MapTreeNode$2 = (undefined as any); let t1h: int32; const m: Option> = t1; if (m != null) { const m2: MapTreeLeaf$2 = value_1(m); t1h = ((m2 instanceof MapTreeNode$2) ? ((mn = (m2 as MapTreeNode$2), MapTreeNode$2__get_Height(mn))) : 1); } else { t1h = 0; } let t2h: int32; const m_1: Option> = t2; if (m_1 != null) { const m2_1: MapTreeLeaf$2 = value_1(m_1); t2h = ((m2_1 instanceof MapTreeNode$2) ? ((mn_1 = (m2_1 as MapTreeNode$2), MapTreeNode$2__get_Height(mn_1))) : 1); } else { t2h = 0; } if (t2h > (t1h + 2)) { const matchValue: MapTreeLeaf$2 = value_1(t2); if (matchValue instanceof MapTreeNode$2) { const t2$0027 = matchValue as MapTreeNode$2; if (((m_2 = MapTreeNode$2__get_Left(t2$0027), (m_2 != null) ? ((m2_2 = value_1(m_2), (m2_2 instanceof MapTreeNode$2) ? ((mn_2 = (m2_2 as MapTreeNode$2), MapTreeNode$2__get_Height(mn_2))) : 1)) : 0)) > (t1h + 1)) { const matchValue_1: MapTreeLeaf$2 = value_1(MapTreeNode$2__get_Left(t2$0027)); if (matchValue_1 instanceof MapTreeNode$2) { const t2l = matchValue_1 as MapTreeNode$2; return MapTreeModule_mk(MapTreeModule_mk(t1, k, v, MapTreeNode$2__get_Left(t2l)), MapTreeLeaf$2__get_Key(t2l), MapTreeLeaf$2__get_Value(t2l), MapTreeModule_mk(MapTreeNode$2__get_Right(t2l), MapTreeLeaf$2__get_Key(t2$0027), MapTreeLeaf$2__get_Value(t2$0027), MapTreeNode$2__get_Right(t2$0027))); } else { throw new Exception("internal error: Map.rebalance"); } } else { return MapTreeModule_mk(MapTreeModule_mk(t1, k, v, MapTreeNode$2__get_Left(t2$0027)), MapTreeLeaf$2__get_Key(t2$0027), MapTreeLeaf$2__get_Value(t2$0027), MapTreeNode$2__get_Right(t2$0027)); } } else { throw new Exception("internal error: Map.rebalance"); } } else if (t1h > (t2h + 2)) { const matchValue_2: MapTreeLeaf$2 = value_1(t1); if (matchValue_2 instanceof MapTreeNode$2) { const t1$0027 = matchValue_2 as MapTreeNode$2; if (((m_3 = MapTreeNode$2__get_Right(t1$0027), (m_3 != null) ? ((m2_3 = value_1(m_3), (m2_3 instanceof MapTreeNode$2) ? ((mn_3 = (m2_3 as MapTreeNode$2), MapTreeNode$2__get_Height(mn_3))) : 1)) : 0)) > (t2h + 1)) { const matchValue_3: MapTreeLeaf$2 = value_1(MapTreeNode$2__get_Right(t1$0027)); if (matchValue_3 instanceof MapTreeNode$2) { const t1r = matchValue_3 as MapTreeNode$2; return MapTreeModule_mk(MapTreeModule_mk(MapTreeNode$2__get_Left(t1$0027), MapTreeLeaf$2__get_Key(t1$0027), MapTreeLeaf$2__get_Value(t1$0027), MapTreeNode$2__get_Left(t1r)), MapTreeLeaf$2__get_Key(t1r), MapTreeLeaf$2__get_Value(t1r), MapTreeModule_mk(MapTreeNode$2__get_Right(t1r), k, v, t2)); } else { throw new Exception("internal error: Map.rebalance"); } } else { return MapTreeModule_mk(MapTreeNode$2__get_Left(t1$0027), MapTreeLeaf$2__get_Key(t1$0027), MapTreeLeaf$2__get_Value(t1$0027), MapTreeModule_mk(MapTreeNode$2__get_Right(t1$0027), k, v, t2)); } } else { throw new Exception("internal error: Map.rebalance"); } } else { return MapTreeModule_mk(t1, k, v, t2); } } export function MapTreeModule_add(comparer: IComparer, k: Key, v: Value, m: Option>): Option> { if (m != null) { const m2: MapTreeLeaf$2 = value_1(m); const c: int32 = comparer.Compare(k, MapTreeLeaf$2__get_Key(m2)) | 0; if (m2 instanceof MapTreeNode$2) { const mn = m2 as MapTreeNode$2; if (c < 0) { return MapTreeModule_rebalance(MapTreeModule_add(comparer, k, v, MapTreeNode$2__get_Left(mn)), MapTreeLeaf$2__get_Key(mn), MapTreeLeaf$2__get_Value(mn), MapTreeNode$2__get_Right(mn)); } else if (c === 0) { return MapTreeNode$2_$ctor_Z39DE9543(k, v, MapTreeNode$2__get_Left(mn), MapTreeNode$2__get_Right(mn), MapTreeNode$2__get_Height(mn)); } else { return MapTreeModule_rebalance(MapTreeNode$2__get_Left(mn), MapTreeLeaf$2__get_Key(mn), MapTreeLeaf$2__get_Value(mn), MapTreeModule_add(comparer, k, v, MapTreeNode$2__get_Right(mn))); } } else if (c < 0) { return MapTreeNode$2_$ctor_Z39DE9543(k, v, MapTreeModule_empty(), m, 2); } else if (c === 0) { return MapTreeLeaf$2_$ctor_5BDDA1(k, v); } else { return MapTreeNode$2_$ctor_Z39DE9543(k, v, m, MapTreeModule_empty(), 2); } } else { return MapTreeLeaf$2_$ctor_5BDDA1(k, v); } } export function MapTreeModule_tryFind(comparer_mut: IComparer, k_mut: Key, m_mut: Option>): Option { MapTreeModule_tryFind: while (true) { const comparer: IComparer = comparer_mut, k: Key = k_mut, m: Option> = m_mut; if (m != null) { const m2: MapTreeLeaf$2 = value_1(m); const c: int32 = comparer.Compare(k, MapTreeLeaf$2__get_Key(m2)) | 0; if (c === 0) { return some(MapTreeLeaf$2__get_Value(m2)); } else if (m2 instanceof MapTreeNode$2) { const mn = m2 as MapTreeNode$2; comparer_mut = comparer; k_mut = k; m_mut = ((c < 0) ? MapTreeNode$2__get_Left(mn) : MapTreeNode$2__get_Right(mn)); continue MapTreeModule_tryFind; } else { return undefined; } } else { return undefined; } break; } } export function MapTreeModule_find(comparer: IComparer, k: Key, m: Option>): Value { const matchValue: Option = MapTreeModule_tryFind(comparer, k, m); if (matchValue == null) { throw KeyNotFoundException_$ctor(); } else { return value_1(matchValue); } } export function MapTreeModule_partition1(comparer: IComparer, f: any, k: Key, v: $a, acc1: Option>, acc2: Option>): [Option>, Option>] { if (f(k, v)) { return [MapTreeModule_add(comparer, k, v, acc1), acc2] as [Option>, Option>]; } else { return [acc1, MapTreeModule_add(comparer, k, v, acc2)] as [Option>, Option>]; } } export function MapTreeModule_partitionAux(comparer_mut: IComparer, f_mut: any, m_mut: Option>, acc__mut: Option>, acc__1_mut: Option>): [Option>, Option>] { MapTreeModule_partitionAux: while (true) { const comparer: IComparer = comparer_mut, f: any = f_mut, m: Option> = m_mut, acc_: Option> = acc__mut, acc__1: Option> = acc__1_mut; const acc = [acc_, acc__1] as [Option>, Option>]; if (m != null) { const m2: MapTreeLeaf$2 = value_1(m); if (m2 instanceof MapTreeNode$2) { const mn = m2 as MapTreeNode$2; const acc_1: [Option>, Option>] = MapTreeModule_partitionAux(comparer, f, MapTreeNode$2__get_Right(mn), acc[0], acc[1]); const acc_4: [Option>, Option>] = MapTreeModule_partition1(comparer, f, MapTreeLeaf$2__get_Key(mn), MapTreeLeaf$2__get_Value(mn), acc_1[0], acc_1[1]); comparer_mut = comparer; f_mut = f; m_mut = MapTreeNode$2__get_Left(mn); acc__mut = acc_4[0]; acc__1_mut = acc_4[1]; continue MapTreeModule_partitionAux; } else { return MapTreeModule_partition1(comparer, f, MapTreeLeaf$2__get_Key(m2), MapTreeLeaf$2__get_Value(m2), acc[0], acc[1]); } } else { return acc; } break; } } export function MapTreeModule_partition(comparer: IComparer, f: ((arg0: Key, arg1: $a) => boolean), m: Option>): [Option>, Option>] { return MapTreeModule_partitionAux(comparer, f, m, MapTreeModule_empty(), MapTreeModule_empty()); } export function MapTreeModule_filter1(comparer: IComparer, f: any, k: Key, v: $a, acc: Option>): Option> { if (f(k, v)) { return MapTreeModule_add(comparer, k, v, acc); } else { return acc; } } export function MapTreeModule_filterAux(comparer_mut: IComparer, f_mut: any, m_mut: Option>, acc_mut: Option>): Option> { MapTreeModule_filterAux: while (true) { const comparer: IComparer = comparer_mut, f: any = f_mut, m: Option> = m_mut, acc: Option> = acc_mut; if (m != null) { const m2: MapTreeLeaf$2 = value_1(m); if (m2 instanceof MapTreeNode$2) { const mn = m2 as MapTreeNode$2; const acc_1: Option> = MapTreeModule_filterAux(comparer, f, MapTreeNode$2__get_Left(mn), acc); const acc_2: Option> = MapTreeModule_filter1(comparer, f, MapTreeLeaf$2__get_Key(mn), MapTreeLeaf$2__get_Value(mn), acc_1); comparer_mut = comparer; f_mut = f; m_mut = MapTreeNode$2__get_Right(mn); acc_mut = acc_2; continue MapTreeModule_filterAux; } else { return MapTreeModule_filter1(comparer, f, MapTreeLeaf$2__get_Key(m2), MapTreeLeaf$2__get_Value(m2), acc); } } else { return acc; } break; } } export function MapTreeModule_filter(comparer: IComparer, f: ((arg0: Key, arg1: $a) => boolean), m: Option>): Option> { return MapTreeModule_filterAux(comparer, f, m, MapTreeModule_empty()); } export function MapTreeModule_spliceOutSuccessor(m: Option>): [Key, Value, Option>] { if (m != null) { const m2: MapTreeLeaf$2 = value_1(m); if (m2 instanceof MapTreeNode$2) { const mn = m2 as MapTreeNode$2; if (MapTreeNode$2__get_Left(mn) == null) { return [MapTreeLeaf$2__get_Key(mn), MapTreeLeaf$2__get_Value(mn), MapTreeNode$2__get_Right(mn)] as [Key, Value, Option>]; } else { const patternInput: [Key, Value, Option>] = MapTreeModule_spliceOutSuccessor(MapTreeNode$2__get_Left(mn)); return [patternInput[0], patternInput[1], MapTreeModule_mk(patternInput[2], MapTreeLeaf$2__get_Key(mn), MapTreeLeaf$2__get_Value(mn), MapTreeNode$2__get_Right(mn))] as [Key, Value, Option>]; } } else { return [MapTreeLeaf$2__get_Key(m2), MapTreeLeaf$2__get_Value(m2), MapTreeModule_empty()] as [Key, Value, Option>]; } } else { throw new Exception("internal error: Map.spliceOutSuccessor"); } } export function MapTreeModule_remove(comparer: IComparer, k: Key, m: Option>): Option> { if (m != null) { const m2: MapTreeLeaf$2 = value_1(m); const c: int32 = comparer.Compare(k, MapTreeLeaf$2__get_Key(m2)) | 0; if (m2 instanceof MapTreeNode$2) { const mn = m2 as MapTreeNode$2; if (c < 0) { return MapTreeModule_rebalance(MapTreeModule_remove(comparer, k, MapTreeNode$2__get_Left(mn)), MapTreeLeaf$2__get_Key(mn), MapTreeLeaf$2__get_Value(mn), MapTreeNode$2__get_Right(mn)); } else if (c === 0) { if (MapTreeNode$2__get_Left(mn) == null) { return MapTreeNode$2__get_Right(mn); } else if (MapTreeNode$2__get_Right(mn) == null) { return MapTreeNode$2__get_Left(mn); } else { const patternInput: [Key, Value, Option>] = MapTreeModule_spliceOutSuccessor(MapTreeNode$2__get_Right(mn)); return MapTreeModule_mk(MapTreeNode$2__get_Left(mn), patternInput[0], patternInput[1], patternInput[2]); } } else { return MapTreeModule_rebalance(MapTreeNode$2__get_Left(mn), MapTreeLeaf$2__get_Key(mn), MapTreeLeaf$2__get_Value(mn), MapTreeModule_remove(comparer, k, MapTreeNode$2__get_Right(mn))); } } else if (c === 0) { return MapTreeModule_empty(); } else { return m; } } else { return MapTreeModule_empty(); } } export function MapTreeModule_change(comparer: IComparer, k: Key, u: ((arg0: Option) => Option), m: Option>): Option> { if (m != null) { const m2: MapTreeLeaf$2 = value_1(m); if (m2 instanceof MapTreeNode$2) { const mn = m2 as MapTreeNode$2; const c: int32 = comparer.Compare(k, MapTreeLeaf$2__get_Key(mn)) | 0; if (c < 0) { return MapTreeModule_rebalance(MapTreeModule_change(comparer, k, u, MapTreeNode$2__get_Left(mn)), MapTreeLeaf$2__get_Key(mn), MapTreeLeaf$2__get_Value(mn), MapTreeNode$2__get_Right(mn)); } else if (c === 0) { const matchValue_1: Option = u(some(MapTreeLeaf$2__get_Value(mn))); if (matchValue_1 != null) { return MapTreeNode$2_$ctor_Z39DE9543(k, value_1(matchValue_1), MapTreeNode$2__get_Left(mn), MapTreeNode$2__get_Right(mn), MapTreeNode$2__get_Height(mn)); } else if (MapTreeNode$2__get_Left(mn) == null) { return MapTreeNode$2__get_Right(mn); } else if (MapTreeNode$2__get_Right(mn) == null) { return MapTreeNode$2__get_Left(mn); } else { const patternInput: [Key, Value, Option>] = MapTreeModule_spliceOutSuccessor(MapTreeNode$2__get_Right(mn)); return MapTreeModule_mk(MapTreeNode$2__get_Left(mn), patternInput[0], patternInput[1], patternInput[2]); } } else { return MapTreeModule_rebalance(MapTreeNode$2__get_Left(mn), MapTreeLeaf$2__get_Key(mn), MapTreeLeaf$2__get_Value(mn), MapTreeModule_change(comparer, k, u, MapTreeNode$2__get_Right(mn))); } } else { const c_1: int32 = comparer.Compare(k, MapTreeLeaf$2__get_Key(m2)) | 0; if (c_1 < 0) { const matchValue_2: Option = u(undefined); if (matchValue_2 != null) { return MapTreeNode$2_$ctor_Z39DE9543(k, value_1(matchValue_2), MapTreeModule_empty(), m, 2); } else { return m; } } else if (c_1 === 0) { const matchValue_3: Option = u(some(MapTreeLeaf$2__get_Value(m2))); if (matchValue_3 != null) { return MapTreeLeaf$2_$ctor_5BDDA1(k, value_1(matchValue_3)); } else { return MapTreeModule_empty(); } } else { const matchValue_4: Option = u(undefined); if (matchValue_4 != null) { return MapTreeNode$2_$ctor_Z39DE9543(k, value_1(matchValue_4), m, MapTreeModule_empty(), 2); } else { return m; } } } } else { const matchValue: Option = u(undefined); if (matchValue != null) { return MapTreeLeaf$2_$ctor_5BDDA1(k, value_1(matchValue)); } else { return m; } } } export function MapTreeModule_mem(comparer_mut: IComparer, k_mut: Key, m_mut: Option>): boolean { MapTreeModule_mem: while (true) { const comparer: IComparer = comparer_mut, k: Key = k_mut, m: Option> = m_mut; if (m != null) { const m2: MapTreeLeaf$2 = value_1(m); const c: int32 = comparer.Compare(k, MapTreeLeaf$2__get_Key(m2)) | 0; if (m2 instanceof MapTreeNode$2) { const mn = m2 as MapTreeNode$2; if (c < 0) { comparer_mut = comparer; k_mut = k; m_mut = MapTreeNode$2__get_Left(mn); continue MapTreeModule_mem; } else if (c === 0) { return true; } else { comparer_mut = comparer; k_mut = k; m_mut = MapTreeNode$2__get_Right(mn); continue MapTreeModule_mem; } } else { return c === 0; } } else { return false; } break; } } export function MapTreeModule_iterOpt(f_mut: any, m_mut: Option>): void { MapTreeModule_iterOpt: while (true) { const f: any = f_mut, m: Option> = m_mut; if (m != null) { const m2: MapTreeLeaf$2 = value_1(m); if (m2 instanceof MapTreeNode$2) { const mn = m2 as MapTreeNode$2; MapTreeModule_iterOpt(f, MapTreeNode$2__get_Left(mn)); f(MapTreeLeaf$2__get_Key(mn), MapTreeLeaf$2__get_Value(mn)); f_mut = f; m_mut = MapTreeNode$2__get_Right(mn); continue MapTreeModule_iterOpt; } else { f(MapTreeLeaf$2__get_Key(m2), MapTreeLeaf$2__get_Value(m2)); } } break; } } export function MapTreeModule_iter<$a, $b>(f: ((arg0: $a, arg1: $b) => void), m: Option>): void { MapTreeModule_iterOpt<$a, $b>(f, m); } export function MapTreeModule_tryPickOpt(f_mut: any, m_mut: Option>): Option<$a> { MapTreeModule_tryPickOpt: while (true) { const f: any = f_mut, m: Option> = m_mut; if (m != null) { const m2: MapTreeLeaf$2 = value_1(m); if (m2 instanceof MapTreeNode$2) { const mn = m2 as MapTreeNode$2; const matchValue: Option<$a> = MapTreeModule_tryPickOpt(f, MapTreeNode$2__get_Left(mn)); if (matchValue == null) { const matchValue_1: Option<$a> = f(MapTreeLeaf$2__get_Key(mn), MapTreeLeaf$2__get_Value(mn)); if (matchValue_1 == null) { f_mut = f; m_mut = MapTreeNode$2__get_Right(mn); continue MapTreeModule_tryPickOpt; } else { return matchValue_1; } } else { return matchValue; } } else { return f(MapTreeLeaf$2__get_Key(m2), MapTreeLeaf$2__get_Value(m2)); } } else { return undefined; } break; } } export function MapTreeModule_tryPick<$a, $b, $c>(f: ((arg0: $a, arg1: $b) => Option<$c>), m: Option>): Option<$c> { return MapTreeModule_tryPickOpt<$a, $b, $c>(f, m); } export function MapTreeModule_existsOpt(f_mut: any, m_mut: Option>): boolean { MapTreeModule_existsOpt: while (true) { const f: any = f_mut, m: Option> = m_mut; if (m != null) { const m2: MapTreeLeaf$2 = value_1(m); if (m2 instanceof MapTreeNode$2) { const mn = m2 as MapTreeNode$2; if (MapTreeModule_existsOpt(f, MapTreeNode$2__get_Left(mn)) ? true : f(MapTreeLeaf$2__get_Key(mn), MapTreeLeaf$2__get_Value(mn))) { return true; } else { f_mut = f; m_mut = MapTreeNode$2__get_Right(mn); continue MapTreeModule_existsOpt; } } else { return f(MapTreeLeaf$2__get_Key(m2), MapTreeLeaf$2__get_Value(m2)); } } else { return false; } break; } } export function MapTreeModule_exists<$a, $b>(f: ((arg0: $a, arg1: $b) => boolean), m: Option>): boolean { return MapTreeModule_existsOpt<$a, $b>(f, m); } export function MapTreeModule_forallOpt(f_mut: any, m_mut: Option>): boolean { MapTreeModule_forallOpt: while (true) { const f: any = f_mut, m: Option> = m_mut; if (m != null) { const m2: MapTreeLeaf$2 = value_1(m); if (m2 instanceof MapTreeNode$2) { const mn = m2 as MapTreeNode$2; if (MapTreeModule_forallOpt(f, MapTreeNode$2__get_Left(mn)) && f(MapTreeLeaf$2__get_Key(mn), MapTreeLeaf$2__get_Value(mn))) { f_mut = f; m_mut = MapTreeNode$2__get_Right(mn); continue MapTreeModule_forallOpt; } else { return false; } } else { return f(MapTreeLeaf$2__get_Key(m2), MapTreeLeaf$2__get_Value(m2)); } } else { return true; } break; } } export function MapTreeModule_forall<$a, $b>(f: ((arg0: $a, arg1: $b) => boolean), m: Option>): boolean { return MapTreeModule_forallOpt<$a, $b>(f, m); } export function MapTreeModule_map(f: ((arg0: Value) => Result), m: Option>): Option> { if (m != null) { const m2: MapTreeLeaf$2 = value_1(m); if (m2 instanceof MapTreeNode$2) { const mn = m2 as MapTreeNode$2; const l2: Option> = MapTreeModule_map(f, MapTreeNode$2__get_Left(mn)); const v2: Result = f(MapTreeLeaf$2__get_Value(mn)); const r2: Option> = MapTreeModule_map(f, MapTreeNode$2__get_Right(mn)); return MapTreeNode$2_$ctor_Z39DE9543(MapTreeLeaf$2__get_Key(mn), v2, l2, r2, MapTreeNode$2__get_Height(mn)); } else { return MapTreeLeaf$2_$ctor_5BDDA1(MapTreeLeaf$2__get_Key(m2), f(MapTreeLeaf$2__get_Value(m2))); } } else { return MapTreeModule_empty(); } } export function MapTreeModule_mapiOpt(f: any, m: Option>): Option> { if (m != null) { const m2: MapTreeLeaf$2 = value_1(m); if (m2 instanceof MapTreeNode$2) { const mn = m2 as MapTreeNode$2; const l2: Option> = MapTreeModule_mapiOpt(f, MapTreeNode$2__get_Left(mn)); const v2: Result = f(MapTreeLeaf$2__get_Key(mn), MapTreeLeaf$2__get_Value(mn)); const r2: Option> = MapTreeModule_mapiOpt(f, MapTreeNode$2__get_Right(mn)); return MapTreeNode$2_$ctor_Z39DE9543(MapTreeLeaf$2__get_Key(mn), v2, l2, r2, MapTreeNode$2__get_Height(mn)); } else { return MapTreeLeaf$2_$ctor_5BDDA1(MapTreeLeaf$2__get_Key(m2), f(MapTreeLeaf$2__get_Key(m2), MapTreeLeaf$2__get_Value(m2))); } } else { return MapTreeModule_empty(); } } export function MapTreeModule_mapi<$a, $b, $c>(f: ((arg0: $a, arg1: $b) => $c), m: Option>): Option> { return MapTreeModule_mapiOpt<$a, $b, $c>(f, m); } export function MapTreeModule_foldBackOpt(f_mut: any, m_mut: Option>, x_mut: $a): $a { MapTreeModule_foldBackOpt: while (true) { const f: any = f_mut, m: Option> = m_mut, x: $a = x_mut; if (m != null) { const m2: MapTreeLeaf$2 = value_1(m); if (m2 instanceof MapTreeNode$2) { const mn = m2 as MapTreeNode$2; const x_1: $a = MapTreeModule_foldBackOpt(f, MapTreeNode$2__get_Right(mn), x); const x_2: $a = f(MapTreeLeaf$2__get_Key(mn), MapTreeLeaf$2__get_Value(mn), x_1); f_mut = f; m_mut = MapTreeNode$2__get_Left(mn); x_mut = x_2; continue MapTreeModule_foldBackOpt; } else { return f(MapTreeLeaf$2__get_Key(m2), MapTreeLeaf$2__get_Value(m2), x); } } else { return x; } break; } } export function MapTreeModule_foldBack<$a, $b, $c>(f: ((arg0: $a, arg1: $b, arg2: $c) => $c), m: Option>, x: $c): $c { return MapTreeModule_foldBackOpt<$a, $b, $c>(f, m, x); } export function MapTreeModule_foldOpt<$a, Key, Value>(f_mut: any, x_mut: $a, m_mut: Option>): $a { MapTreeModule_foldOpt: while (true) { const f: any = f_mut, x: $a = x_mut, m: Option> = m_mut; if (m != null) { const m2: MapTreeLeaf$2 = value_1(m); if (m2 instanceof MapTreeNode$2) { const mn = m2 as MapTreeNode$2; f_mut = f; x_mut = f(MapTreeModule_foldOpt<$a, Key, Value>(f, x, MapTreeNode$2__get_Left(mn)), MapTreeLeaf$2__get_Key(mn), MapTreeLeaf$2__get_Value(mn)); m_mut = MapTreeNode$2__get_Right(mn); continue MapTreeModule_foldOpt; } else { return f(x, MapTreeLeaf$2__get_Key(m2), MapTreeLeaf$2__get_Value(m2)); } } else { return x; } break; } } export function MapTreeModule_fold<$a, $b, $c>(f: ((arg0: $a, arg1: $b, arg2: $c) => $a), x: $a, m: Option>): $a { return MapTreeModule_foldOpt<$a, $b, $c>(f, x, m); } export function MapTreeModule_foldSectionOpt(comparer: IComparer, lo: Key, hi: Key, f: any, m: Option>, x: a): a { const foldFromTo = (f_1_mut: any, m_1_mut: Option>, x_1_mut: a): a => { foldFromTo: while (true) { const f_1: any = f_1_mut, m_1: Option> = m_1_mut, x_1: a = x_1_mut; if (m_1 != null) { const m2: MapTreeLeaf$2 = value_1(m_1); if (m2 instanceof MapTreeNode$2) { const mn = m2 as MapTreeNode$2; const cLoKey: int32 = comparer.Compare(lo, MapTreeLeaf$2__get_Key(mn)) | 0; const cKeyHi: int32 = comparer.Compare(MapTreeLeaf$2__get_Key(mn), hi) | 0; const x_2: a = (cLoKey < 0) ? foldFromTo(f_1, MapTreeNode$2__get_Left(mn), x_1) : x_1; const x_3: a = ((cLoKey <= 0) && (cKeyHi <= 0)) ? f_1(MapTreeLeaf$2__get_Key(mn), MapTreeLeaf$2__get_Value(mn), x_2) : x_2; if (cKeyHi < 0) { f_1_mut = f_1; m_1_mut = MapTreeNode$2__get_Right(mn); x_1_mut = x_3; continue foldFromTo; } else { return x_3; } } else if ((comparer.Compare(lo, MapTreeLeaf$2__get_Key(m2)) <= 0) && (comparer.Compare(MapTreeLeaf$2__get_Key(m2), hi) <= 0)) { return f_1(MapTreeLeaf$2__get_Key(m2), MapTreeLeaf$2__get_Value(m2), x_1); } else { return x_1; } } else { return x_1; } break; } }; if (comparer.Compare(lo, hi) === 1) { return x; } else { return foldFromTo(f, m, x); } } export function MapTreeModule_foldSection<$a, $b, $c>(comparer: IComparer<$a>, lo: $a, hi: $a, f: ((arg0: $a, arg1: $b, arg2: $c) => $c), m: Option>, x: $c): $c { return MapTreeModule_foldSectionOpt<$a, $b, $c>(comparer, lo, hi, f, m, x); } export function MapTreeModule_toList(m: Option>): FSharpList<[Key, Value]> { const loop = (m_1_mut: Option>, acc_mut: FSharpList<[Key, Value]>): FSharpList<[Key, Value]> => { loop: while (true) { const m_1: Option> = m_1_mut, acc: FSharpList<[Key, Value]> = acc_mut; if (m_1 != null) { const m2: MapTreeLeaf$2 = value_1(m_1); if (m2 instanceof MapTreeNode$2) { const mn = m2 as MapTreeNode$2; m_1_mut = MapTreeNode$2__get_Left(mn); acc_mut = cons([MapTreeLeaf$2__get_Key(mn), MapTreeLeaf$2__get_Value(mn)] as [Key, Value], loop(MapTreeNode$2__get_Right(mn), acc)); continue loop; } else { return cons([MapTreeLeaf$2__get_Key(m2), MapTreeLeaf$2__get_Value(m2)] as [Key, Value], acc); } } else { return acc; } break; } }; return loop(m, empty_1<[Key, Value]>()); } export function MapTreeModule_copyToArray<$a, $b>(m: Option>, arr: MutableArray<[$a, $b]>, i: int32): void { let j: int32 = i; MapTreeModule_iter<$a, $b>((x: $a, y: $b): void => { setItem(arr, j, [x, y] as [$a, $b]); j = ((j + 1) | 0); }, m); } export function MapTreeModule_toArray<$a, $b>(m: Option>): MutableArray<[$a, $b]> { const n: int32 = MapTreeModule_size<$a, $b>(m) | 0; const res: MutableArray<[$a, $b]> = fill(new Array(n), 0, n, [null, null] as [any, any]); MapTreeModule_copyToArray<$a, $b>(m, res, 0); return res; } export function MapTreeModule_ofList<$a, $b>(comparer: IComparer<$a>, l: FSharpList<[$a, $b]>): Option> { return fold_1<[$a, $b], Option>>((acc: Option>, tupledArg: [$a, $b]): Option> => MapTreeModule_add<$a, $b>(comparer, tupledArg[0], tupledArg[1], acc), MapTreeModule_empty<$a, $b>(), l); } export function MapTreeModule_mkFromEnumerator<$a, $b>(comparer_mut: IComparer<$a>, acc_mut: Option>, e_mut: IEnumerator<[$a, $b]>): Option> { MapTreeModule_mkFromEnumerator: while (true) { const comparer: IComparer<$a> = comparer_mut, acc: Option> = acc_mut, e: IEnumerator<[$a, $b]> = e_mut; if (e["System.Collections.IEnumerator.MoveNext"]()) { const patternInput: [$a, $b] = e["System.Collections.Generic.IEnumerator`1.get_Current"](); comparer_mut = comparer; acc_mut = MapTreeModule_add<$a, $b>(comparer, patternInput[0], patternInput[1], acc); e_mut = e; continue MapTreeModule_mkFromEnumerator; } else { return acc; } break; } } export function MapTreeModule_ofArray(comparer: IComparer, arr: MutableArray<[Key, Value]>): Option> { let res: Option> = MapTreeModule_empty(); for (let idx = 0; idx <= (arr.length - 1); idx++) { const forLoopVar: [Key, Value] = item(idx, arr); res = MapTreeModule_add(comparer, forLoopVar[0], forLoopVar[1], res); } return res; } export function MapTreeModule_ofSeq(comparer: IComparer, c: Iterable<[Key, Value]>): Option> { if (isArrayLike(c)) { return MapTreeModule_ofArray(comparer, c); } else if (c instanceof FSharpList) { return MapTreeModule_ofList(comparer, c); } else { const ie: IEnumerator<[Key, Value]> = getEnumerator(c); try { return MapTreeModule_mkFromEnumerator(comparer, MapTreeModule_empty(), ie); } finally { disposeSafe(ie as IDisposable); } } } /** * Imperative left-to-right iterators. */ export class MapTreeModule_MapIterator$2 extends Record { stack: FSharpList>>; started: boolean; constructor(stack: FSharpList>>, started: boolean) { super(); this.stack = stack; this.started = started; } } export function MapTreeModule_MapIterator$2_$reflection(gen0: TypeInfo, gen1: TypeInfo): TypeInfo { return record_type("Map.MapTreeModule.MapIterator`2", [gen0, gen1], MapTreeModule_MapIterator$2, () => [["stack", list_type(option_type(MapTreeLeaf$2_$reflection(gen0, gen1)))], ["started", bool_type]]); } export function MapTreeModule_collapseLHS(stack_mut: FSharpList>>): FSharpList>> { MapTreeModule_collapseLHS: while (true) { const stack: FSharpList>> = stack_mut; if (!isEmpty_1(stack)) { const rest: FSharpList>> = tail(stack); const m: Option> = head(stack); if (m != null) { const m2: MapTreeLeaf$2 = value_1(m); if (m2 instanceof MapTreeNode$2) { const mn = m2 as MapTreeNode$2; stack_mut = ofArrayWithTail([MapTreeNode$2__get_Left(mn), MapTreeLeaf$2_$ctor_5BDDA1(MapTreeLeaf$2__get_Key(mn), MapTreeLeaf$2__get_Value(mn)), MapTreeNode$2__get_Right(mn)], rest); continue MapTreeModule_collapseLHS; } else { return stack; } } else { stack_mut = rest; continue MapTreeModule_collapseLHS; } } else { return empty_1>>(); } break; } } export function MapTreeModule_mkIterator<$a, $b>(m: Option>): MapTreeModule_MapIterator$2<$a, $b> { return new MapTreeModule_MapIterator$2(MapTreeModule_collapseLHS<$a, $b>(singleton(m)), false); } export function MapTreeModule_notStarted<$a>(): $a { throw new Exception("enumeration not started"); } export function MapTreeModule_alreadyFinished<$a>(): $a { throw new Exception("enumeration already finished"); } export function MapTreeModule_current(i: MapTreeModule_MapIterator$2): [Key, Value] { if (i.started) { const matchValue: FSharpList>> = i.stack; if (!isEmpty_1(matchValue)) { if (head(matchValue) != null) { const m: MapTreeLeaf$2 = value_1(head(matchValue)); if (m instanceof MapTreeNode$2) { throw new Exception("Please report error: Map iterator, unexpected stack for current"); } else { return [MapTreeLeaf$2__get_Key(m), MapTreeLeaf$2__get_Value(m)] as [Key, Value]; } } else { throw new Exception("Please report error: Map iterator, unexpected stack for current"); } } else { return MapTreeModule_alreadyFinished<[Key, Value]>(); } } else { return MapTreeModule_notStarted<[Key, Value]>(); } } export function MapTreeModule_moveNext(i: MapTreeModule_MapIterator$2): boolean { if (i.started) { const matchValue: FSharpList>> = i.stack; if (!isEmpty_1(matchValue)) { if (head(matchValue) != null) { const m: MapTreeLeaf$2 = value_1(head(matchValue)); if (m instanceof MapTreeNode$2) { throw new Exception("Please report error: Map iterator, unexpected stack for moveNext"); } else { i.stack = MapTreeModule_collapseLHS(tail(matchValue)); return !isEmpty_1(i.stack); } } else { throw new Exception("Please report error: Map iterator, unexpected stack for moveNext"); } } else { return false; } } else { i.started = true; return !isEmpty_1(i.stack); } } export function MapTreeModule_mkIEnumerator(m: Option>): IEnumerator<[a, b]> { let i: MapTreeModule_MapIterator$2 = MapTreeModule_mkIterator(m); return { "System.Collections.Generic.IEnumerator`1.get_Current"(): [a, b] { return MapTreeModule_current(i); }, "System.Collections.IEnumerator.get_Current"(): any { return MapTreeModule_current(i); }, "System.Collections.IEnumerator.MoveNext"(): boolean { return MapTreeModule_moveNext(i); }, "System.Collections.IEnumerator.Reset"(): void { i = MapTreeModule_mkIterator(m); }, Dispose(): void { }, }; } export function MapTreeModule_toSeq<$a, $b>(s: Option>): Iterable<[$a, $b]> { return unfold, [$a, $b]>((en_1: IEnumerator<[$a, $b]>): Option<[[$a, $b], IEnumerator<[$a, $b]>]> => { if (en_1["System.Collections.IEnumerator.MoveNext"]()) { return [en_1["System.Collections.Generic.IEnumerator`1.get_Current"](), en_1] as [[$a, $b], IEnumerator<[$a, $b]>]; } else { return undefined; } }, MapTreeModule_mkIEnumerator<$a, $b>(s)); } export function MapTreeModule_leftmost(m_mut: Option>): [Key, Value] { MapTreeModule_leftmost: while (true) { const m: Option> = m_mut; if (m != null) { const m2: MapTreeLeaf$2 = value_1(m); let matchResult: int32 = (undefined as any), nd_1: MapTreeNode$2 = (undefined as any); if (m2 instanceof MapTreeNode$2) { if (MapTreeNode$2__get_Height(m2 as MapTreeNode$2) > 1) { matchResult = 0; nd_1 = (m2 as MapTreeNode$2); } else { matchResult = 1; } } else { matchResult = 1; } switch (matchResult) { case 0: if (MapTreeNode$2__get_Left(nd_1!) == null) { return [MapTreeLeaf$2__get_Key(nd_1!), MapTreeLeaf$2__get_Value(nd_1!)] as [Key, Value]; } else { m_mut = MapTreeNode$2__get_Left(nd_1!); continue MapTreeModule_leftmost; } default: return [MapTreeLeaf$2__get_Key(m2), MapTreeLeaf$2__get_Value(m2)] as [Key, Value]; } } else { throw KeyNotFoundException_$ctor(); } break; } } export function MapTreeModule_rightmost(m_mut: Option>): [Key, Value] { MapTreeModule_rightmost: while (true) { const m: Option> = m_mut; if (m != null) { const m2: MapTreeLeaf$2 = value_1(m); let matchResult: int32 = (undefined as any), nd_1: MapTreeNode$2 = (undefined as any); if (m2 instanceof MapTreeNode$2) { if (MapTreeNode$2__get_Height(m2 as MapTreeNode$2) > 1) { matchResult = 0; nd_1 = (m2 as MapTreeNode$2); } else { matchResult = 1; } } else { matchResult = 1; } switch (matchResult) { case 0: if (MapTreeNode$2__get_Right(nd_1!) == null) { return [MapTreeLeaf$2__get_Key(nd_1!), MapTreeLeaf$2__get_Value(nd_1!)] as [Key, Value]; } else { m_mut = MapTreeNode$2__get_Right(nd_1!); continue MapTreeModule_rightmost; } default: return [MapTreeLeaf$2__get_Key(m2), MapTreeLeaf$2__get_Value(m2)] as [Key, Value]; } } else { throw KeyNotFoundException_$ctor(); } break; } } export class FSharpMap implements IMap, Iterable<[Key, Value]>, Iterable<[Key, Value]> { readonly tree: Option>; readonly comparer: IComparer; constructor(comparer: IComparer, tree: Option>) { this.comparer = comparer; this.tree = tree; } GetHashCode(): int32 { const this$: FSharpMap = this; return FSharpMap__ComputeHashCode(this$) | 0; } Equals(other: any): boolean { const this$: FSharpMap = this; if (other instanceof FSharpMap) { const that = other as FSharpMap; const e1: IEnumerator<[Key, Value]> = getEnumerator(this$); try { const e2: IEnumerator<[Key, Value]> = getEnumerator(that); try { const loop = (): boolean => { const m1: boolean = e1["System.Collections.IEnumerator.MoveNext"](); if (m1 === e2["System.Collections.IEnumerator.MoveNext"]()) { if (!m1) { return true; } else { const e1c: [Key, Value] = e1["System.Collections.Generic.IEnumerator`1.get_Current"](); const e2c: [Key, Value] = e2["System.Collections.Generic.IEnumerator`1.get_Current"](); if (equals(e1c[0], e2c[0]) && equals(e1c[1], e2c[1])) { return loop(); } else { return false; } } } else { return false; } }; return loop(); } finally { disposeSafe(e2 as IDisposable); } } finally { disposeSafe(e1 as IDisposable); } } else { return false; } } toString(): string { const this$: FSharpMap = this; return ("map [" + join("; ", map_1<[Key, Value], string>((kv: [Key, Value]): string => format("({0}, {1})", kv[0], kv[1]), this$))) + "]"; } get [Symbol.toStringTag](): string { return "FSharpMap"; } toJSON(): any { const this$: FSharpMap = this; return Array.from(this$); } GetEnumerator(): IEnumerator<[Key, Value]> { const _: FSharpMap = this; return MapTreeModule_mkIEnumerator(_.tree); } [Symbol.iterator](): Iterator<[Key, Value]> { return toIterator(getEnumerator(this)); } "System.Collections.IEnumerable.GetEnumerator"(): IEnumerator { const _: FSharpMap = this; return MapTreeModule_mkIEnumerator(_.tree); } CompareTo(other: any): int32 { let that: FSharpMap = undefined as any; const this$: FSharpMap = this; return ((other instanceof FSharpMap) ? ((that = (other as FSharpMap), compareWith<[Key, Value]>((kvp1: [Key, Value], kvp2: [Key, Value]): int32 => { const c: int32 = this$.comparer.Compare(kvp1[0], kvp2[0]) | 0; return ((c !== 0) ? c : compare(kvp1[1], kvp2[1])) | 0; }, this$, that))) : 1) | 0; } "System.Collections.Generic.ICollection`1.Add2B595"(x: [Key, Value]): void { throw NotSupportedException_$ctor_Z721C83C5("Map cannot be mutated"); } "System.Collections.Generic.ICollection`1.Clear"(): void { throw NotSupportedException_$ctor_Z721C83C5("Map cannot be mutated"); } "System.Collections.Generic.ICollection`1.Remove2B595"(x: [Key, Value]): boolean { throw NotSupportedException_$ctor_Z721C83C5("Map cannot be mutated"); } "System.Collections.Generic.ICollection`1.Contains2B595"(x: [Key, Value]): boolean { const m: FSharpMap = this; return FSharpMap__ContainsKey(m, x[0]) && equals(FSharpMap__get_Item(m, x[0]), x[1]); } "System.Collections.Generic.ICollection`1.CopyToZ3B4C077E"(arr: MutableArray<[Key, Value]>, i: int32): void { const m: FSharpMap = this; MapTreeModule_copyToArray(m.tree, arr, i); } "System.Collections.Generic.ICollection`1.get_IsReadOnly"(): boolean { return true; } "System.Collections.Generic.ICollection`1.get_Count"(): int32 { const m: FSharpMap = this; return FSharpMap__get_Count(m) | 0; } "System.Collections.Generic.IReadOnlyCollection`1.get_Count"(): int32 { const m: FSharpMap = this; return FSharpMap__get_Count(m) | 0; } get size(): int32 { const m: FSharpMap = this; return FSharpMap__get_Count(m) | 0; } clear(): void { throw new Exception("Map cannot be mutated"); } delete(_arg: Key): boolean { throw new Exception("Map cannot be mutated"); return false; } entries(): Iterable<[Key, Value]> { const m: FSharpMap = this; return map_1<[Key, Value], [Key, Value]>((p: [Key, Value]): [Key, Value] => ([p[0], p[1]] as [Key, Value]), m); } get(k: Key): Value { const m: FSharpMap = this; return FSharpMap__get_Item(m, k); } has(k: Key): boolean { const m: FSharpMap = this; return FSharpMap__ContainsKey(m, k); } keys(): Iterable { const m: FSharpMap = this; return map_1<[Key, Value], Key>((p: [Key, Value]): Key => p[0], m); } set(k: Key, v: Value): IMap { const m: FSharpMap = this; throw new Exception("Map cannot be mutated"); return m; } values(): Iterable { const m: FSharpMap = this; return map_1<[Key, Value], Value>((p: [Key, Value]): Value => p[1], m); } forEach(f: ((arg0: Value, arg1: Key, arg2: IMap) => void), thisArg?: Option): void { const m: FSharpMap = this; iterate_1<[Key, Value]>((p: [Key, Value]): void => { f(p[1], p[0], m); }, m); } } export function FSharpMap_$reflection(gen0: TypeInfo, gen1: TypeInfo): TypeInfo { return class_type("Map.FSharpMap", [gen0, gen1], FSharpMap); } export function FSharpMap_$ctor(comparer: IComparer, tree: Option>): FSharpMap { return new FSharpMap(comparer, tree); } export function FSharpMap_Empty(comparer: IComparer): FSharpMap { return FSharpMap_$ctor(comparer, MapTreeModule_empty()); } export function FSharpMap__get_Comparer(m: FSharpMap): IComparer { return m.comparer; } export function FSharpMap__get_Tree(m: FSharpMap): Option> { return m.tree; } export function FSharpMap__Add(m: FSharpMap, key: Key, value: Value): FSharpMap { return FSharpMap_$ctor(m.comparer, MapTreeModule_add(m.comparer, key, value, m.tree)); } export function FSharpMap__Change(m: FSharpMap, key: Key, f: ((arg0: Option) => Option)): FSharpMap { return FSharpMap_$ctor(m.comparer, MapTreeModule_change(m.comparer, key, f, m.tree)); } export function FSharpMap__get_IsEmpty(m: FSharpMap): boolean { return m.tree == null; } export function FSharpMap__get_Item(m: FSharpMap, key: Key): Value { return MapTreeModule_find(m.comparer, key, m.tree); } export function FSharpMap__TryPick(m: FSharpMap, f: ((arg0: Key, arg1: Value) => Option<$a>)): Option<$a> { return MapTreeModule_tryPick(f, m.tree); } export function FSharpMap__Exists(m: FSharpMap, predicate: ((arg0: Key, arg1: Value) => boolean)): boolean { return MapTreeModule_exists(predicate, m.tree); } export function FSharpMap__Filter(m: FSharpMap, predicate: ((arg0: Key, arg1: Value) => boolean)): FSharpMap { return FSharpMap_$ctor(m.comparer, MapTreeModule_filter(m.comparer, predicate, m.tree)); } export function FSharpMap__ForAll(m: FSharpMap, predicate: ((arg0: Key, arg1: Value) => boolean)): boolean { return MapTreeModule_forall(predicate, m.tree); } export function FSharpMap__Fold(m: FSharpMap, f: ((arg0: Key, arg1: Value, arg2: $a) => $a), acc: $a): $a { return MapTreeModule_foldBack(f, m.tree, acc); } export function FSharpMap__FoldSection(m: FSharpMap, lo: Key, hi: Key, f: ((arg0: Key, arg1: Value, arg2: $a) => $a), acc: $a): $a { return MapTreeModule_foldSection(m.comparer, lo, hi, f, m.tree, acc); } export function FSharpMap__Iterate(m: FSharpMap, f: ((arg0: Key, arg1: Value) => void)): void { MapTreeModule_iter(f, m.tree); } export function FSharpMap__MapRange(m: FSharpMap, f: ((arg0: Value) => Result)): FSharpMap { return FSharpMap_$ctor(m.comparer, MapTreeModule_map(f, m.tree)); } export function FSharpMap__Map(m: FSharpMap, f: ((arg0: Key, arg1: Value) => b)): FSharpMap { return FSharpMap_$ctor(m.comparer, MapTreeModule_mapi(f, m.tree)); } export function FSharpMap__Partition(m: FSharpMap, predicate: ((arg0: Key, arg1: Value) => boolean)): [FSharpMap, FSharpMap] { const patternInput: [Option>, Option>] = MapTreeModule_partition(m.comparer, predicate, m.tree); return [FSharpMap_$ctor(m.comparer, patternInput[0]), FSharpMap_$ctor(m.comparer, patternInput[1])] as [FSharpMap, FSharpMap]; } export function FSharpMap__get_Count(m: FSharpMap): int32 { return MapTreeModule_size(m.tree) | 0; } export function FSharpMap__ContainsKey(m: FSharpMap, key: Key): boolean { return MapTreeModule_mem(m.comparer, key, m.tree); } export function FSharpMap__Remove(m: FSharpMap, key: Key): FSharpMap { return FSharpMap_$ctor(m.comparer, MapTreeModule_remove(m.comparer, key, m.tree)); } export function FSharpMap__TryGetValue(_: FSharpMap, key: Key, value: FSharpRef): boolean { const matchValue: Option = MapTreeModule_tryFind(_.comparer, key, _.tree); if (matchValue == null) { return false; } else { const v: Value = value_1(matchValue); value.contents = v; return true; } } export function FSharpMap__get_Keys(_: FSharpMap): Iterable { return map_2<[Key, Value], Key>((kvp: [Key, Value]): Key => kvp[0], MapTreeModule_toArray(_.tree)); } export function FSharpMap__get_Values(_: FSharpMap): Iterable { return map_2<[Key, Value], Value>((kvp: [Key, Value]): Value => kvp[1], MapTreeModule_toArray(_.tree)); } export function FSharpMap__get_MinKeyValue(m: FSharpMap): [Key, Value] { return MapTreeModule_leftmost(m.tree); } export function FSharpMap__get_MaxKeyValue(m: FSharpMap): [Key, Value] { return MapTreeModule_rightmost(m.tree); } export function FSharpMap__TryFind(m: FSharpMap, key: Key): Option { return MapTreeModule_tryFind(m.comparer, key, m.tree); } export function FSharpMap__ToList(m: FSharpMap): FSharpList<[Key, Value]> { return MapTreeModule_toList(m.tree); } export function FSharpMap__ToArray(m: FSharpMap): MutableArray<[Key, Value]> { return MapTreeModule_toArray(m.tree); } export function FSharpMap__ComputeHashCode(this$: FSharpMap): int32 { const combineHash = (x: int32, y: int32): int32 => ((((x << 1) + y) + 631) | 0); let res = 0; const enumerator: IEnumerator<[Key, Value]> = getEnumerator(this$); try { while (enumerator["System.Collections.IEnumerator.MoveNext"]()) { const activePatternResult: [Key, Value] = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"](); res = (combineHash(res, structuralHash(activePatternResult[0])) | 0); res = (combineHash(res, structuralHash(activePatternResult[1])) | 0); } } finally { disposeSafe(enumerator as IDisposable); } return res | 0; } export function isEmpty<$a, $b>(table: FSharpMap<$a, $b>): boolean { return FSharpMap__get_IsEmpty<$a, $b>(table); } export function add<$a, $b>(key: $a, value: $b, table: FSharpMap<$a, $b>): FSharpMap<$a, $b> { return FSharpMap__Add<$a, $b>(table, key, value); } export function change<$a, $b>(key: $a, f: ((arg0: Option<$b>) => Option<$b>), table: FSharpMap<$a, $b>): FSharpMap<$a, $b> { return FSharpMap__Change<$a, $b>(table, key, f); } export function find<$a, $b>(key: $a, table: FSharpMap<$a, $b>): $b { return FSharpMap__get_Item<$a, $b>(table, key); } export function tryFind<$a, $b>(key: $a, table: FSharpMap<$a, $b>): Option<$b> { return FSharpMap__TryFind<$a, $b>(table, key); } export function remove<$a, $b>(key: $a, table: FSharpMap<$a, $b>): FSharpMap<$a, $b> { return FSharpMap__Remove<$a, $b>(table, key); } export function containsKey<$a, $b>(key: $a, table: FSharpMap<$a, $b>): boolean { return FSharpMap__ContainsKey<$a, $b>(table, key); } export function iterate<$a, $b>(action: ((arg0: $a, arg1: $b) => void), table: FSharpMap<$a, $b>): void { FSharpMap__Iterate<$a, $b>(table, action); } export function tryPick<$a, $b, $c>(chooser: ((arg0: $a, arg1: $b) => Option<$c>), table: FSharpMap<$a, $b>): Option<$c> { return FSharpMap__TryPick<$a, $b, $c>(table, chooser); } export function pick<$a, $b, $c>(chooser: ((arg0: $a, arg1: $b) => Option<$c>), table: FSharpMap<$a, $b>): $c { const matchValue: Option<$c> = tryPick<$a, $b, $c>(chooser, table); if (matchValue != null) { return value_1(matchValue); } else { throw KeyNotFoundException_$ctor(); } } export function exists<$a, $b>(predicate: ((arg0: $a, arg1: $b) => boolean), table: FSharpMap<$a, $b>): boolean { return FSharpMap__Exists<$a, $b>(table, predicate); } export function filter<$a, $b>(predicate: ((arg0: $a, arg1: $b) => boolean), table: FSharpMap<$a, $b>): FSharpMap<$a, $b> { return FSharpMap__Filter<$a, $b>(table, predicate); } export function partition<$a, $b>(predicate: ((arg0: $a, arg1: $b) => boolean), table: FSharpMap<$a, $b>): [FSharpMap<$a, $b>, FSharpMap<$a, $b>] { return FSharpMap__Partition<$a, $b>(table, predicate); } export function forAll<$a, $b>(predicate: ((arg0: $a, arg1: $b) => boolean), table: FSharpMap<$a, $b>): boolean { return FSharpMap__ForAll<$a, $b>(table, predicate); } export function map<$a, $b, $c>(mapping: ((arg0: $a, arg1: $b) => $c), table: FSharpMap<$a, $b>): FSharpMap<$a, $c> { return FSharpMap__Map<$a, $b, $c>(table, mapping); } export function fold(folder: ((arg0: State, arg1: Key, arg2: T) => State), state: State, table: FSharpMap): State { return MapTreeModule_fold(folder, state, FSharpMap__get_Tree(table)); } export function foldBack(folder: ((arg0: Key, arg1: T, arg2: State) => State), table: FSharpMap, state: State): State { return MapTreeModule_foldBack(folder, FSharpMap__get_Tree(table), state); } export function toSeq<$a, $b>(table: FSharpMap<$a, $b>): Iterable<[$a, $b]> { return map_1<[$a, $b], [$a, $b]>((kvp: [$a, $b]): [$a, $b] => ([kvp[0], kvp[1]] as [$a, $b]), table); } export function findKey<$a, $b>(predicate: ((arg0: $a, arg1: $b) => boolean), table: FSharpMap<$a, $b>): $a { return pick_1<[$a, $b], $a>((kvp: [$a, $b]): Option<$a> => { const k: $a = kvp[0]; if (predicate(k, kvp[1])) { return some(k); } else { return undefined; } }, table); } export function tryFindKey<$a, $b>(predicate: ((arg0: $a, arg1: $b) => boolean), table: FSharpMap<$a, $b>): Option<$a> { return tryPick_1<[$a, $b], $a>((kvp: [$a, $b]): Option<$a> => { const k: $a = kvp[0]; if (predicate(k, kvp[1])) { return some(k); } else { return undefined; } }, table); } export function ofList(elements: FSharpList<[Key, Value]>, comparer: IComparer): FSharpMap { return FSharpMap_$ctor(comparer, MapTreeModule_ofSeq(comparer, elements)); } export function ofSeq(elements: Iterable<[T, $a]>, comparer: IComparer): FSharpMap { return FSharpMap_$ctor(comparer, MapTreeModule_ofSeq(comparer, elements)); } export function ofArray(elements: MutableArray<[Key, Value]>, comparer: IComparer): FSharpMap { return FSharpMap_$ctor(comparer, MapTreeModule_ofSeq(comparer, elements)); } export function toList<$a, $b>(table: FSharpMap<$a, $b>): FSharpList<[$a, $b]> { return FSharpMap__ToList<$a, $b>(table); } export function toArray<$a, $b>(table: FSharpMap<$a, $b>): MutableArray<[$a, $b]> { return FSharpMap__ToArray<$a, $b>(table); } export function keys(table: FSharpMap): Iterable { return FSharpMap__get_Keys(table); } export function values(table: FSharpMap): Iterable { return FSharpMap__get_Values(table); } export function minKeyValue<$a, $b>(table: FSharpMap<$a, $b>): [$a, $b] { return FSharpMap__get_MinKeyValue<$a, $b>(table); } export function maxKeyValue<$a, $b>(table: FSharpMap<$a, $b>): [$a, $b] { return FSharpMap__get_MaxKeyValue<$a, $b>(table); } export function empty(comparer: IComparer): FSharpMap { return FSharpMap_Empty(comparer); } export function count<$a, $b>(table: FSharpMap<$a, $b>): int32 { return FSharpMap__get_Count<$a, $b>(table) | 0; }