import { record_type, bool_type, list_type, option_type, class_type, TypeInfo } from "./Reflection.ts"; import { some, value as value_2, Option } from "./Option.ts"; import { int32 } from "./Int32.ts"; import { structuralHash, ISet, toIterator, IDisposable, disposeSafe, getEnumerator, isArrayLike, MutableArray, IEnumerator, IComparer, Exception } from "./Util.ts"; import { Record } from "./Types.ts"; import { fold as fold_2, cons, singleton as singleton_1, empty as empty_1, ofArrayWithTail, tail, head, isEmpty as isEmpty_1, FSharpList } from "./List.ts"; import { fold as fold_1, fill, setItem } from "./Array.ts"; import { join } from "./String.ts"; import { NotSupportedException_$ctor_Z721C83C5 } from "./System.ts"; import { skip, truncate, iterateIndexed, exists as exists_1, forAll as forAll_1, fold as fold_3, reduce, iterate as iterate_1, map as map_1 } from "./Seq.ts"; import { HashSet__get_Comparer, HashSet_$ctor_Z6150332D, HashSet } from "./MutableSet.ts"; export class SetTreeLeaf$1 { readonly k: T; constructor(k: T) { this.k = k; } } export function SetTreeLeaf$1_$reflection(gen0: TypeInfo): TypeInfo { return class_type("Set.SetTreeLeaf`1", [gen0], SetTreeLeaf$1); } export function SetTreeLeaf$1_$ctor_2B595(k: T): SetTreeLeaf$1 { return new SetTreeLeaf$1(k); } export function SetTreeLeaf$1__get_Key(_: SetTreeLeaf$1): T { return _.k; } export class SetTreeNode$1 extends SetTreeLeaf$1 { readonly right: Option>; readonly left: Option>; readonly h: int32; constructor(v: T, left: Option>, right: Option>, h: int32) { super(v); this.left = left; this.right = right; this.h = (h | 0); } } export function SetTreeNode$1_$reflection(gen0: TypeInfo): TypeInfo { return class_type("Set.SetTreeNode`1", [gen0], SetTreeNode$1, SetTreeLeaf$1_$reflection(gen0)); } export function SetTreeNode$1_$ctor_5F465FC9(v: T, left: Option>, right: Option>, h: int32): SetTreeNode$1 { return new SetTreeNode$1(v, left, right, h); } export function SetTreeNode$1__get_Left(_: SetTreeNode$1): Option> { return _.left; } export function SetTreeNode$1__get_Right(_: SetTreeNode$1): Option> { return _.right; } export function SetTreeNode$1__get_Height(_: SetTreeNode$1): int32 { return _.h | 0; } export function SetTreeModule_empty(): Option> { return undefined; } export function SetTreeModule_countAux(t_mut: Option>, acc_mut: int32): int32 { SetTreeModule_countAux: while (true) { const t: Option> = t_mut, acc: int32 = acc_mut; if (t != null) { const t2: SetTreeLeaf$1 = value_2(t); if (t2 instanceof SetTreeNode$1) { const tn = t2 as SetTreeNode$1; t_mut = SetTreeNode$1__get_Left(tn); acc_mut = SetTreeModule_countAux(SetTreeNode$1__get_Right(tn), acc + 1); continue SetTreeModule_countAux; } else { return (acc + 1) | 0; } } else { return acc | 0; } break; } } export function SetTreeModule_count<$a>(s: Option>): int32 { return SetTreeModule_countAux<$a>(s, 0) | 0; } export function SetTreeModule_mk(l: Option>, k: T, r: Option>): Option> { let tn: SetTreeNode$1 = (undefined as any), tn_1: SetTreeNode$1 = (undefined as any); let hl: int32; const t: Option> = l; if (t != null) { const t2: SetTreeLeaf$1 = value_2(t); hl = ((t2 instanceof SetTreeNode$1) ? ((tn = (t2 as SetTreeNode$1), SetTreeNode$1__get_Height(tn))) : 1); } else { hl = 0; } let hr: int32; const t_1: Option> = r; if (t_1 != null) { const t2_1: SetTreeLeaf$1 = value_2(t_1); hr = ((t2_1 instanceof SetTreeNode$1) ? ((tn_1 = (t2_1 as SetTreeNode$1), SetTreeNode$1__get_Height(tn_1))) : 1); } else { hr = 0; } const m: int32 = ((hl < hr) ? hr : hl) | 0; if (m === 0) { return SetTreeLeaf$1_$ctor_2B595(k); } else { return SetTreeNode$1_$ctor_5F465FC9(k, l, r, m + 1); } } export function SetTreeModule_rebalance(t1: Option>, v: T, t2: Option>): Option> { let tn: SetTreeNode$1 = (undefined as any), tn_1: SetTreeNode$1 = (undefined as any), t_2: Option> = (undefined as any), t2_3: SetTreeLeaf$1 = (undefined as any), tn_2: SetTreeNode$1 = (undefined as any), t_3: Option> = (undefined as any), t2_4: SetTreeLeaf$1 = (undefined as any), tn_3: SetTreeNode$1 = (undefined as any); let t1h: int32; const t: Option> = t1; if (t != null) { const t2_1: SetTreeLeaf$1 = value_2(t); t1h = ((t2_1 instanceof SetTreeNode$1) ? ((tn = (t2_1 as SetTreeNode$1), SetTreeNode$1__get_Height(tn))) : 1); } else { t1h = 0; } let t2h: int32; const t_1: Option> = t2; if (t_1 != null) { const t2_2: SetTreeLeaf$1 = value_2(t_1); t2h = ((t2_2 instanceof SetTreeNode$1) ? ((tn_1 = (t2_2 as SetTreeNode$1), SetTreeNode$1__get_Height(tn_1))) : 1); } else { t2h = 0; } if (t2h > (t1h + 2)) { const matchValue: SetTreeLeaf$1 = value_2(t2); if (matchValue instanceof SetTreeNode$1) { const t2$0027 = matchValue as SetTreeNode$1; if (((t_2 = SetTreeNode$1__get_Left(t2$0027), (t_2 != null) ? ((t2_3 = value_2(t_2), (t2_3 instanceof SetTreeNode$1) ? ((tn_2 = (t2_3 as SetTreeNode$1), SetTreeNode$1__get_Height(tn_2))) : 1)) : 0)) > (t1h + 1)) { const matchValue_1: SetTreeLeaf$1 = value_2(SetTreeNode$1__get_Left(t2$0027)); if (matchValue_1 instanceof SetTreeNode$1) { const t2l = matchValue_1 as SetTreeNode$1; return SetTreeModule_mk(SetTreeModule_mk(t1, v, SetTreeNode$1__get_Left(t2l)), SetTreeLeaf$1__get_Key(t2l), SetTreeModule_mk(SetTreeNode$1__get_Right(t2l), SetTreeLeaf$1__get_Key(t2$0027), SetTreeNode$1__get_Right(t2$0027))); } else { throw new Exception("internal error: Set.rebalance"); } } else { return SetTreeModule_mk(SetTreeModule_mk(t1, v, SetTreeNode$1__get_Left(t2$0027)), SetTreeLeaf$1__get_Key(t2$0027), SetTreeNode$1__get_Right(t2$0027)); } } else { throw new Exception("internal error: Set.rebalance"); } } else if (t1h > (t2h + 2)) { const matchValue_2: SetTreeLeaf$1 = value_2(t1); if (matchValue_2 instanceof SetTreeNode$1) { const t1$0027 = matchValue_2 as SetTreeNode$1; if (((t_3 = SetTreeNode$1__get_Right(t1$0027), (t_3 != null) ? ((t2_4 = value_2(t_3), (t2_4 instanceof SetTreeNode$1) ? ((tn_3 = (t2_4 as SetTreeNode$1), SetTreeNode$1__get_Height(tn_3))) : 1)) : 0)) > (t2h + 1)) { const matchValue_3: SetTreeLeaf$1 = value_2(SetTreeNode$1__get_Right(t1$0027)); if (matchValue_3 instanceof SetTreeNode$1) { const t1r = matchValue_3 as SetTreeNode$1; return SetTreeModule_mk(SetTreeModule_mk(SetTreeNode$1__get_Left(t1$0027), SetTreeLeaf$1__get_Key(t1$0027), SetTreeNode$1__get_Left(t1r)), SetTreeLeaf$1__get_Key(t1r), SetTreeModule_mk(SetTreeNode$1__get_Right(t1r), v, t2)); } else { throw new Exception("internal error: Set.rebalance"); } } else { return SetTreeModule_mk(SetTreeNode$1__get_Left(t1$0027), SetTreeLeaf$1__get_Key(t1$0027), SetTreeModule_mk(SetTreeNode$1__get_Right(t1$0027), v, t2)); } } else { throw new Exception("internal error: Set.rebalance"); } } else { return SetTreeModule_mk(t1, v, t2); } } export function SetTreeModule_add(comparer: IComparer, k: T, t: Option>): Option> { if (t != null) { const t2: SetTreeLeaf$1 = value_2(t); const c: int32 = comparer.Compare(k, SetTreeLeaf$1__get_Key(t2)) | 0; if (t2 instanceof SetTreeNode$1) { const tn = t2 as SetTreeNode$1; if (c < 0) { return SetTreeModule_rebalance(SetTreeModule_add(comparer, k, SetTreeNode$1__get_Left(tn)), SetTreeLeaf$1__get_Key(tn), SetTreeNode$1__get_Right(tn)); } else if (c === 0) { return t; } else { return SetTreeModule_rebalance(SetTreeNode$1__get_Left(tn), SetTreeLeaf$1__get_Key(tn), SetTreeModule_add(comparer, k, SetTreeNode$1__get_Right(tn))); } } else { const c_1: int32 = comparer.Compare(k, SetTreeLeaf$1__get_Key(t2)) | 0; if (c_1 < 0) { return SetTreeNode$1_$ctor_5F465FC9(k, SetTreeModule_empty(), t, 2); } else if (c_1 === 0) { return t; } else { return SetTreeNode$1_$ctor_5F465FC9(k, t, SetTreeModule_empty(), 2); } } } else { return SetTreeLeaf$1_$ctor_2B595(k); } } export function SetTreeModule_balance(comparer: IComparer, t1: Option>, k: T, t2: Option>): Option> { if (t1 != null) { const t1$0027: SetTreeLeaf$1 = value_2(t1); if (t2 != null) { const t2$0027: SetTreeLeaf$1 = value_2(t2); if (t1$0027 instanceof SetTreeNode$1) { const t1n = t1$0027 as SetTreeNode$1; if (t2$0027 instanceof SetTreeNode$1) { const t2n = t2$0027 as SetTreeNode$1; if ((SetTreeNode$1__get_Height(t1n) + 2) < SetTreeNode$1__get_Height(t2n)) { return SetTreeModule_rebalance(SetTreeModule_balance(comparer, t1, k, SetTreeNode$1__get_Left(t2n)), SetTreeLeaf$1__get_Key(t2n), SetTreeNode$1__get_Right(t2n)); } else if ((SetTreeNode$1__get_Height(t2n) + 2) < SetTreeNode$1__get_Height(t1n)) { return SetTreeModule_rebalance(SetTreeNode$1__get_Left(t1n), SetTreeLeaf$1__get_Key(t1n), SetTreeModule_balance(comparer, SetTreeNode$1__get_Right(t1n), k, t2)); } else { return SetTreeModule_mk(t1, k, t2); } } else { return SetTreeModule_add(comparer, k, SetTreeModule_add(comparer, SetTreeLeaf$1__get_Key(t2$0027), t1)); } } else { return SetTreeModule_add(comparer, k, SetTreeModule_add(comparer, SetTreeLeaf$1__get_Key(t1$0027), t2)); } } else { return SetTreeModule_add(comparer, k, t1); } } else { return SetTreeModule_add(comparer, k, t2); } } export function SetTreeModule_split(comparer: IComparer, pivot: T, t: Option>): [Option>, boolean, Option>] { if (t != null) { const t2: SetTreeLeaf$1 = value_2(t); if (t2 instanceof SetTreeNode$1) { const tn = t2 as SetTreeNode$1; const c: int32 = comparer.Compare(pivot, SetTreeLeaf$1__get_Key(tn)) | 0; if (c < 0) { const patternInput: [Option>, boolean, Option>] = SetTreeModule_split(comparer, pivot, SetTreeNode$1__get_Left(tn)); return [patternInput[0], patternInput[1], SetTreeModule_balance(comparer, patternInput[2], SetTreeLeaf$1__get_Key(tn), SetTreeNode$1__get_Right(tn))] as [Option>, boolean, Option>]; } else if (c === 0) { return [SetTreeNode$1__get_Left(tn), true, SetTreeNode$1__get_Right(tn)] as [Option>, boolean, Option>]; } else { const patternInput_1: [Option>, boolean, Option>] = SetTreeModule_split(comparer, pivot, SetTreeNode$1__get_Right(tn)); return [SetTreeModule_balance(comparer, SetTreeNode$1__get_Left(tn), SetTreeLeaf$1__get_Key(tn), patternInput_1[0]), patternInput_1[1], patternInput_1[2]] as [Option>, boolean, Option>]; } } else { const c_1: int32 = comparer.Compare(SetTreeLeaf$1__get_Key(t2), pivot) | 0; if (c_1 < 0) { return [t, false, SetTreeModule_empty()] as [Option>, boolean, Option>]; } else if (c_1 === 0) { return [SetTreeModule_empty(), true, SetTreeModule_empty()] as [Option>, boolean, Option>]; } else { return [SetTreeModule_empty(), false, t] as [Option>, boolean, Option>]; } } } else { return [SetTreeModule_empty(), false, SetTreeModule_empty()] as [Option>, boolean, Option>]; } } export function SetTreeModule_spliceOutSuccessor(t: Option>): [T, Option>] { if (t != null) { const t2: SetTreeLeaf$1 = value_2(t); if (t2 instanceof SetTreeNode$1) { const tn = t2 as SetTreeNode$1; if (SetTreeNode$1__get_Left(tn) == null) { return [SetTreeLeaf$1__get_Key(tn), SetTreeNode$1__get_Right(tn)] as [T, Option>]; } else { const patternInput: [T, Option>] = SetTreeModule_spliceOutSuccessor(SetTreeNode$1__get_Left(tn)); return [patternInput[0], SetTreeModule_mk(patternInput[1], SetTreeLeaf$1__get_Key(tn), SetTreeNode$1__get_Right(tn))] as [T, Option>]; } } else { return [SetTreeLeaf$1__get_Key(t2), SetTreeModule_empty()] as [T, Option>]; } } else { throw new Exception("internal error: Set.spliceOutSuccessor"); } } export function SetTreeModule_remove(comparer: IComparer, k: T, t: Option>): Option> { if (t != null) { const t2: SetTreeLeaf$1 = value_2(t); const c: int32 = comparer.Compare(k, SetTreeLeaf$1__get_Key(t2)) | 0; if (t2 instanceof SetTreeNode$1) { const tn = t2 as SetTreeNode$1; if (c < 0) { return SetTreeModule_rebalance(SetTreeModule_remove(comparer, k, SetTreeNode$1__get_Left(tn)), SetTreeLeaf$1__get_Key(tn), SetTreeNode$1__get_Right(tn)); } else if (c === 0) { if (SetTreeNode$1__get_Left(tn) == null) { return SetTreeNode$1__get_Right(tn); } else if (SetTreeNode$1__get_Right(tn) == null) { return SetTreeNode$1__get_Left(tn); } else { const patternInput: [T, Option>] = SetTreeModule_spliceOutSuccessor(SetTreeNode$1__get_Right(tn)); return SetTreeModule_mk(SetTreeNode$1__get_Left(tn), patternInput[0], patternInput[1]); } } else { return SetTreeModule_rebalance(SetTreeNode$1__get_Left(tn), SetTreeLeaf$1__get_Key(tn), SetTreeModule_remove(comparer, k, SetTreeNode$1__get_Right(tn))); } } else if (c === 0) { return SetTreeModule_empty(); } else { return t; } } else { return t; } } export function SetTreeModule_mem(comparer_mut: IComparer, k_mut: T, t_mut: Option>): boolean { SetTreeModule_mem: while (true) { const comparer: IComparer = comparer_mut, k: T = k_mut, t: Option> = t_mut; if (t != null) { const t2: SetTreeLeaf$1 = value_2(t); const c: int32 = comparer.Compare(k, SetTreeLeaf$1__get_Key(t2)) | 0; if (t2 instanceof SetTreeNode$1) { const tn = t2 as SetTreeNode$1; if (c < 0) { comparer_mut = comparer; k_mut = k; t_mut = SetTreeNode$1__get_Left(tn); continue SetTreeModule_mem; } else if (c === 0) { return true; } else { comparer_mut = comparer; k_mut = k; t_mut = SetTreeNode$1__get_Right(tn); continue SetTreeModule_mem; } } else { return c === 0; } } else { return false; } break; } } export function SetTreeModule_iter(f_mut: ((arg0: T) => void), t_mut: Option>): void { SetTreeModule_iter: while (true) { const f: ((arg0: T) => void) = f_mut, t: Option> = t_mut; if (t != null) { const t2: SetTreeLeaf$1 = value_2(t); if (t2 instanceof SetTreeNode$1) { const tn = t2 as SetTreeNode$1; SetTreeModule_iter(f, SetTreeNode$1__get_Left(tn)); f(SetTreeLeaf$1__get_Key(tn)); f_mut = f; t_mut = SetTreeNode$1__get_Right(tn); continue SetTreeModule_iter; } else { f(SetTreeLeaf$1__get_Key(t2)); } } break; } } export function SetTreeModule_foldBackOpt(f_mut: any, t_mut: Option>, x_mut: $a): $a { SetTreeModule_foldBackOpt: while (true) { const f: any = f_mut, t: Option> = t_mut, x: $a = x_mut; if (t != null) { const t2: SetTreeLeaf$1 = value_2(t); if (t2 instanceof SetTreeNode$1) { const tn = t2 as SetTreeNode$1; f_mut = f; t_mut = SetTreeNode$1__get_Left(tn); x_mut = f(SetTreeLeaf$1__get_Key(tn), SetTreeModule_foldBackOpt(f, SetTreeNode$1__get_Right(tn), x)); continue SetTreeModule_foldBackOpt; } else { return f(SetTreeLeaf$1__get_Key(t2), x); } } else { return x; } break; } } export function SetTreeModule_foldBack<$a, $b>(f: ((arg0: $a, arg1: $b) => $b), m: Option>, x: $b): $b { return SetTreeModule_foldBackOpt<$a, $b>(f, m, x); } export function SetTreeModule_foldOpt<$a, T>(f_mut: any, x_mut: $a, t_mut: Option>): $a { SetTreeModule_foldOpt: while (true) { const f: any = f_mut, x: $a = x_mut, t: Option> = t_mut; if (t != null) { const t2: SetTreeLeaf$1 = value_2(t); if (t2 instanceof SetTreeNode$1) { const tn = t2 as SetTreeNode$1; f_mut = f; x_mut = f(SetTreeModule_foldOpt<$a, T>(f, x, SetTreeNode$1__get_Left(tn)), SetTreeLeaf$1__get_Key(tn)); t_mut = SetTreeNode$1__get_Right(tn); continue SetTreeModule_foldOpt; } else { return f(x, SetTreeLeaf$1__get_Key(t2)); } } else { return x; } break; } } export function SetTreeModule_fold<$a, $b>(f: ((arg0: $a, arg1: $b) => $a), x: $a, m: Option>): $a { return SetTreeModule_foldOpt<$a, $b>(f, x, m); } export function SetTreeModule_forall(f_mut: ((arg0: T) => boolean), t_mut: Option>): boolean { SetTreeModule_forall: while (true) { const f: ((arg0: T) => boolean) = f_mut, t: Option> = t_mut; if (t != null) { const t2: SetTreeLeaf$1 = value_2(t); if (t2 instanceof SetTreeNode$1) { const tn = t2 as SetTreeNode$1; if (f(SetTreeLeaf$1__get_Key(tn)) && SetTreeModule_forall(f, SetTreeNode$1__get_Left(tn))) { f_mut = f; t_mut = SetTreeNode$1__get_Right(tn); continue SetTreeModule_forall; } else { return false; } } else { return f(SetTreeLeaf$1__get_Key(t2)); } } else { return true; } break; } } export function SetTreeModule_exists(f_mut: ((arg0: T) => boolean), t_mut: Option>): boolean { SetTreeModule_exists: while (true) { const f: ((arg0: T) => boolean) = f_mut, t: Option> = t_mut; if (t != null) { const t2: SetTreeLeaf$1 = value_2(t); if (t2 instanceof SetTreeNode$1) { const tn = t2 as SetTreeNode$1; if (f(SetTreeLeaf$1__get_Key(tn)) ? true : SetTreeModule_exists(f, SetTreeNode$1__get_Left(tn))) { return true; } else { f_mut = f; t_mut = SetTreeNode$1__get_Right(tn); continue SetTreeModule_exists; } } else { return f(SetTreeLeaf$1__get_Key(t2)); } } else { return false; } break; } } export function SetTreeModule_subset<$a>(comparer: IComparer<$a>, a: Option>, b: Option>): boolean { return SetTreeModule_forall<$a>((x: $a): boolean => SetTreeModule_mem<$a>(comparer, x, b), a); } export function SetTreeModule_properSubset(comparer: IComparer, a: Option>, b: Option>): boolean { if (SetTreeModule_forall((x: T): boolean => SetTreeModule_mem(comparer, x, b), a)) { return SetTreeModule_exists((x_1: T): boolean => !SetTreeModule_mem(comparer, x_1, a), b); } else { return false; } } export function SetTreeModule_filterAux(comparer_mut: IComparer, f_mut: ((arg0: T) => boolean), t_mut: Option>, acc_mut: Option>): Option> { SetTreeModule_filterAux: while (true) { const comparer: IComparer = comparer_mut, f: ((arg0: T) => boolean) = f_mut, t: Option> = t_mut, acc: Option> = acc_mut; if (t != null) { const t2: SetTreeLeaf$1 = value_2(t); if (t2 instanceof SetTreeNode$1) { const tn = t2 as SetTreeNode$1; const acc_1: Option> = f(SetTreeLeaf$1__get_Key(tn)) ? SetTreeModule_add(comparer, SetTreeLeaf$1__get_Key(tn), acc) : acc; comparer_mut = comparer; f_mut = f; t_mut = SetTreeNode$1__get_Left(tn); acc_mut = SetTreeModule_filterAux(comparer, f, SetTreeNode$1__get_Right(tn), acc_1); continue SetTreeModule_filterAux; } else if (f(SetTreeLeaf$1__get_Key(t2))) { return SetTreeModule_add(comparer, SetTreeLeaf$1__get_Key(t2), acc); } else { return acc; } } else { return acc; } break; } } export function SetTreeModule_filter<$a>(comparer: IComparer<$a>, f: ((arg0: $a) => boolean), s: Option>): Option> { return SetTreeModule_filterAux<$a>(comparer, f, s, SetTreeModule_empty<$a>()); } export function SetTreeModule_diffAux(comparer_mut: IComparer, t_mut: Option>, acc_mut: Option>): Option> { SetTreeModule_diffAux: while (true) { const comparer: IComparer = comparer_mut, t: Option> = t_mut, acc: Option> = acc_mut; if (acc == null) { return acc; } else if (t != null) { const t2: SetTreeLeaf$1 = value_2(t); if (t2 instanceof SetTreeNode$1) { const tn = t2 as SetTreeNode$1; comparer_mut = comparer; t_mut = SetTreeNode$1__get_Left(tn); acc_mut = SetTreeModule_diffAux(comparer, SetTreeNode$1__get_Right(tn), SetTreeModule_remove(comparer, SetTreeLeaf$1__get_Key(tn), acc)); continue SetTreeModule_diffAux; } else { return SetTreeModule_remove(comparer, SetTreeLeaf$1__get_Key(t2), acc); } } else { return acc; } break; } } export function SetTreeModule_diff<$a>(comparer: IComparer<$a>, a: Option>, b: Option>): Option> { return SetTreeModule_diffAux<$a>(comparer, b, a); } export function SetTreeModule_union(comparer: IComparer, t1: Option>, t2: Option>): Option> { if (t1 != null) { const t1$0027: SetTreeLeaf$1 = value_2(t1); if (t2 != null) { const t2$0027: SetTreeLeaf$1 = value_2(t2); if (t1$0027 instanceof SetTreeNode$1) { const t1n = t1$0027 as SetTreeNode$1; if (t2$0027 instanceof SetTreeNode$1) { const t2n = t2$0027 as SetTreeNode$1; if (SetTreeNode$1__get_Height(t1n) > SetTreeNode$1__get_Height(t2n)) { const patternInput: [Option>, boolean, Option>] = SetTreeModule_split(comparer, SetTreeLeaf$1__get_Key(t1n), t2); return SetTreeModule_balance(comparer, SetTreeModule_union(comparer, SetTreeNode$1__get_Left(t1n), patternInput[0]), SetTreeLeaf$1__get_Key(t1n), SetTreeModule_union(comparer, SetTreeNode$1__get_Right(t1n), patternInput[2])); } else { const patternInput_1: [Option>, boolean, Option>] = SetTreeModule_split(comparer, SetTreeLeaf$1__get_Key(t2n), t1); return SetTreeModule_balance(comparer, SetTreeModule_union(comparer, SetTreeNode$1__get_Left(t2n), patternInput_1[0]), SetTreeLeaf$1__get_Key(t2n), SetTreeModule_union(comparer, SetTreeNode$1__get_Right(t2n), patternInput_1[2])); } } else { return SetTreeModule_add(comparer, SetTreeLeaf$1__get_Key(t2$0027), t1); } } else { return SetTreeModule_add(comparer, SetTreeLeaf$1__get_Key(t1$0027), t2); } } else { return t1; } } else { return t2; } } export function SetTreeModule_intersectionAux(comparer_mut: IComparer, b_mut: Option>, t_mut: Option>, acc_mut: Option>): Option> { SetTreeModule_intersectionAux: while (true) { const comparer: IComparer = comparer_mut, b: Option> = b_mut, t: Option> = t_mut, acc: Option> = acc_mut; if (t != null) { const t2: SetTreeLeaf$1 = value_2(t); if (t2 instanceof SetTreeNode$1) { const tn = t2 as SetTreeNode$1; const acc_1: Option> = SetTreeModule_intersectionAux(comparer, b, SetTreeNode$1__get_Right(tn), acc); const acc_2: Option> = SetTreeModule_mem(comparer, SetTreeLeaf$1__get_Key(tn), b) ? SetTreeModule_add(comparer, SetTreeLeaf$1__get_Key(tn), acc_1) : acc_1; comparer_mut = comparer; b_mut = b; t_mut = SetTreeNode$1__get_Left(tn); acc_mut = acc_2; continue SetTreeModule_intersectionAux; } else if (SetTreeModule_mem(comparer, SetTreeLeaf$1__get_Key(t2), b)) { return SetTreeModule_add(comparer, SetTreeLeaf$1__get_Key(t2), acc); } else { return acc; } } else { return acc; } break; } } export function SetTreeModule_intersection<$a>(comparer: IComparer<$a>, a: Option>, b: Option>): Option> { return SetTreeModule_intersectionAux<$a>(comparer, b, a, SetTreeModule_empty<$a>()); } export function SetTreeModule_partition1<$a>(comparer: IComparer<$a>, f: ((arg0: $a) => boolean), k: $a, acc1: Option>, acc2: Option>): [Option>, Option>] { if (f(k)) { return [SetTreeModule_add<$a>(comparer, k, acc1), acc2] as [Option>, Option>]; } else { return [acc1, SetTreeModule_add<$a>(comparer, k, acc2)] as [Option>, Option>]; } } export function SetTreeModule_partitionAux(comparer_mut: IComparer, f_mut: ((arg0: T) => boolean), t_mut: Option>, acc__mut: Option>, acc__1_mut: Option>): [Option>, Option>] { SetTreeModule_partitionAux: while (true) { const comparer: IComparer = comparer_mut, f: ((arg0: T) => boolean) = f_mut, t: Option> = t_mut, acc_: Option> = acc__mut, acc__1: Option> = acc__1_mut; const acc = [acc_, acc__1] as [Option>, Option>]; if (t != null) { const t2: SetTreeLeaf$1 = value_2(t); if (t2 instanceof SetTreeNode$1) { const tn = t2 as SetTreeNode$1; const acc_1: [Option>, Option>] = SetTreeModule_partitionAux(comparer, f, SetTreeNode$1__get_Right(tn), acc[0], acc[1]); const acc_4: [Option>, Option>] = SetTreeModule_partition1(comparer, f, SetTreeLeaf$1__get_Key(tn), acc_1[0], acc_1[1]); comparer_mut = comparer; f_mut = f; t_mut = SetTreeNode$1__get_Left(tn); acc__mut = acc_4[0]; acc__1_mut = acc_4[1]; continue SetTreeModule_partitionAux; } else { return SetTreeModule_partition1(comparer, f, SetTreeLeaf$1__get_Key(t2), acc[0], acc[1]); } } else { return acc; } break; } } export function SetTreeModule_partition<$a>(comparer: IComparer<$a>, f: ((arg0: $a) => boolean), s: Option>): [Option>, Option>] { return SetTreeModule_partitionAux<$a>(comparer, f, s, SetTreeModule_empty<$a>(), SetTreeModule_empty<$a>()); } export function SetTreeModule_minimumElementAux(t_mut: Option>, n_mut: T): T { SetTreeModule_minimumElementAux: while (true) { const t: Option> = t_mut, n: T = n_mut; if (t != null) { const t2: SetTreeLeaf$1 = value_2(t); if (t2 instanceof SetTreeNode$1) { const tn = t2 as SetTreeNode$1; t_mut = SetTreeNode$1__get_Left(tn); n_mut = SetTreeLeaf$1__get_Key(tn); continue SetTreeModule_minimumElementAux; } else { return SetTreeLeaf$1__get_Key(t2); } } else { return n; } break; } } export function SetTreeModule_minimumElementOpt(t: Option>): Option { if (t != null) { const t2: SetTreeLeaf$1 = value_2(t); if (t2 instanceof SetTreeNode$1) { const tn = t2 as SetTreeNode$1; return some(SetTreeModule_minimumElementAux(SetTreeNode$1__get_Left(tn), SetTreeLeaf$1__get_Key(tn))); } else { return some(SetTreeLeaf$1__get_Key(t2)); } } else { return undefined; } } export function SetTreeModule_maximumElementAux(t_mut: Option>, n_mut: T): T { SetTreeModule_maximumElementAux: while (true) { const t: Option> = t_mut, n: T = n_mut; if (t != null) { const t2: SetTreeLeaf$1 = value_2(t); if (t2 instanceof SetTreeNode$1) { const tn = t2 as SetTreeNode$1; t_mut = SetTreeNode$1__get_Right(tn); n_mut = SetTreeLeaf$1__get_Key(tn); continue SetTreeModule_maximumElementAux; } else { return SetTreeLeaf$1__get_Key(t2); } } else { return n; } break; } } export function SetTreeModule_maximumElementOpt(t: Option>): Option { if (t != null) { const t2: SetTreeLeaf$1 = value_2(t); if (t2 instanceof SetTreeNode$1) { const tn = t2 as SetTreeNode$1; return some(SetTreeModule_maximumElementAux(SetTreeNode$1__get_Right(tn), SetTreeLeaf$1__get_Key(tn))); } else { return some(SetTreeLeaf$1__get_Key(t2)); } } else { return undefined; } } export function SetTreeModule_minimumElement<$a>(s: Option>): $a { const matchValue: Option<$a> = SetTreeModule_minimumElementOpt<$a>(s); if (matchValue == null) { throw new Exception("Set contains no elements"); } else { return value_2(matchValue); } } export function SetTreeModule_maximumElement<$a>(s: Option>): $a { const matchValue: Option<$a> = SetTreeModule_maximumElementOpt<$a>(s); if (matchValue == null) { throw new Exception("Set contains no elements"); } else { return value_2(matchValue); } } export class SetTreeModule_SetIterator$1 extends Record { stack: FSharpList>>; started: boolean; constructor(stack: FSharpList>>, started: boolean) { super(); this.stack = stack; this.started = started; } } export function SetTreeModule_SetIterator$1_$reflection(gen0: TypeInfo): TypeInfo { return record_type("Set.SetTreeModule.SetIterator`1", [gen0], SetTreeModule_SetIterator$1, () => [["stack", list_type(option_type(SetTreeLeaf$1_$reflection(gen0)))], ["started", bool_type]]); } export function SetTreeModule_collapseLHS(stack_mut: FSharpList>>): FSharpList>> { SetTreeModule_collapseLHS: while (true) { const stack: FSharpList>> = stack_mut; if (!isEmpty_1(stack)) { const x: Option> = head(stack); const rest: FSharpList>> = tail(stack); if (x != null) { const x2: SetTreeLeaf$1 = value_2(x); if (x2 instanceof SetTreeNode$1) { const xn = x2 as SetTreeNode$1; stack_mut = ofArrayWithTail([SetTreeNode$1__get_Left(xn), SetTreeLeaf$1_$ctor_2B595(SetTreeLeaf$1__get_Key(xn)), SetTreeNode$1__get_Right(xn)], rest); continue SetTreeModule_collapseLHS; } else { return stack; } } else { stack_mut = rest; continue SetTreeModule_collapseLHS; } } else { return empty_1>>(); } break; } } export function SetTreeModule_mkIterator<$a>(s: Option>): SetTreeModule_SetIterator$1<$a> { return new SetTreeModule_SetIterator$1(SetTreeModule_collapseLHS<$a>(singleton_1(s)), false); } export function SetTreeModule_notStarted<$a>(): $a { throw new Exception("Enumeration not started"); } export function SetTreeModule_alreadyFinished<$a>(): $a { throw new Exception("Enumeration already started"); } export function SetTreeModule_current<$a>(i: SetTreeModule_SetIterator$1<$a>): $a { if (i.started) { const matchValue: FSharpList>> = i.stack; if (isEmpty_1(matchValue)) { return SetTreeModule_alreadyFinished<$a>(); } else if (head(matchValue) != null) { const t: SetTreeLeaf$1<$a> = value_2(head(matchValue)); return SetTreeLeaf$1__get_Key<$a>(t); } else { throw new Exception("Please report error: Set iterator, unexpected stack for current"); } } else { return SetTreeModule_notStarted<$a>(); } } export function SetTreeModule_moveNext(i: SetTreeModule_SetIterator$1): boolean { if (i.started) { const matchValue: FSharpList>> = i.stack; if (!isEmpty_1(matchValue)) { if (head(matchValue) != null) { const t: SetTreeLeaf$1 = value_2(head(matchValue)); if (t instanceof SetTreeNode$1) { throw new Exception("Please report error: Set iterator, unexpected stack for moveNext"); } else { i.stack = SetTreeModule_collapseLHS(tail(matchValue)); return !isEmpty_1(i.stack); } } else { throw new Exception("Please report error: Set iterator, unexpected stack for moveNext"); } } else { return false; } } else { i.started = true; return !isEmpty_1(i.stack); } } export function SetTreeModule_mkIEnumerator(s: Option>): IEnumerator { let i: SetTreeModule_SetIterator$1 = SetTreeModule_mkIterator(s); return { "System.Collections.Generic.IEnumerator`1.get_Current"(): a { return SetTreeModule_current(i); }, "System.Collections.IEnumerator.get_Current"(): any { return SetTreeModule_current(i); }, "System.Collections.IEnumerator.MoveNext"(): boolean { return SetTreeModule_moveNext(i); }, "System.Collections.IEnumerator.Reset"(): void { i = SetTreeModule_mkIterator(s); }, Dispose(): void { }, }; } /** * Set comparison. Note this can be expensive. */ export function SetTreeModule_compareStacks(comparer_mut: IComparer, l1_mut: FSharpList>>, l2_mut: FSharpList>>): int32 { SetTreeModule_compareStacks: while (true) { const comparer: IComparer = comparer_mut, l1: FSharpList>> = l1_mut, l2: FSharpList>> = l2_mut; if (!isEmpty_1(l1)) { if (!isEmpty_1(l2)) { if (head(l2) != null) { if (head(l1) != null) { const x1_3: SetTreeLeaf$1 = value_2(head(l1)); const x2_3: SetTreeLeaf$1 = value_2(head(l2)); if (x1_3 instanceof SetTreeNode$1) { const x1n_2 = x1_3 as SetTreeNode$1; if (SetTreeNode$1__get_Left(x1n_2) == null) { if (x2_3 instanceof SetTreeNode$1) { const x2n_2 = x2_3 as SetTreeNode$1; if (SetTreeNode$1__get_Left(x2n_2) == null) { const c: int32 = comparer.Compare(SetTreeLeaf$1__get_Key(x1n_2), SetTreeLeaf$1__get_Key(x2n_2)) | 0; if (c !== 0) { return c | 0; } else { comparer_mut = comparer; l1_mut = cons(SetTreeNode$1__get_Right(x1n_2), tail(l1)); l2_mut = cons(SetTreeNode$1__get_Right(x2n_2), tail(l2)); continue SetTreeModule_compareStacks; } } else { let matchResult: int32 = (undefined as any), t1_6: FSharpList>> = (undefined as any), x1_4: SetTreeLeaf$1 = (undefined as any), t2_6: FSharpList>> = (undefined as any), x2_4: SetTreeLeaf$1 = (undefined as any); if (!isEmpty_1(l1)) { if (head(l1) != null) { matchResult = 0; t1_6 = tail(l1); x1_4 = value_2(head(l1)); } else if (!isEmpty_1(l2)) { if (head(l2) != null) { matchResult = 1; t2_6 = tail(l2); x2_4 = value_2(head(l2)); } else { matchResult = 2; } } else { matchResult = 2; } } else if (!isEmpty_1(l2)) { if (head(l2) != null) { matchResult = 1; t2_6 = tail(l2); x2_4 = value_2(head(l2)); } else { matchResult = 2; } } else { matchResult = 2; } switch (matchResult) { case 0: if (x1_4! instanceof SetTreeNode$1) { const x1n_3 = x1_4! as SetTreeNode$1; comparer_mut = comparer; l1_mut = ofArrayWithTail([SetTreeNode$1__get_Left(x1n_3), SetTreeNode$1_$ctor_5F465FC9(SetTreeLeaf$1__get_Key(x1n_3), SetTreeModule_empty(), SetTreeNode$1__get_Right(x1n_3), 0)], t1_6!); l2_mut = l2; continue SetTreeModule_compareStacks; } else { comparer_mut = comparer; l1_mut = ofArrayWithTail([SetTreeModule_empty(), SetTreeLeaf$1_$ctor_2B595(SetTreeLeaf$1__get_Key(x1_4!))], t1_6!); l2_mut = l2; continue SetTreeModule_compareStacks; } case 1: if (x2_4! instanceof SetTreeNode$1) { const x2n_3 = x2_4! as SetTreeNode$1; comparer_mut = comparer; l1_mut = l1; l2_mut = ofArrayWithTail([SetTreeNode$1__get_Left(x2n_3), SetTreeNode$1_$ctor_5F465FC9(SetTreeLeaf$1__get_Key(x2n_3), SetTreeModule_empty(), SetTreeNode$1__get_Right(x2n_3), 0)], t2_6!); continue SetTreeModule_compareStacks; } else { comparer_mut = comparer; l1_mut = l1; l2_mut = ofArrayWithTail([SetTreeModule_empty(), SetTreeLeaf$1_$ctor_2B595(SetTreeLeaf$1__get_Key(x2_4!))], t2_6!); continue SetTreeModule_compareStacks; } default: throw new Exception("unexpected state in SetTree.compareStacks"); } } } else { const c_1: int32 = comparer.Compare(SetTreeLeaf$1__get_Key(x1n_2), SetTreeLeaf$1__get_Key(x2_3)) | 0; if (c_1 !== 0) { return c_1 | 0; } else { comparer_mut = comparer; l1_mut = cons(SetTreeNode$1__get_Right(x1n_2), tail(l1)); l2_mut = cons(SetTreeModule_empty(), tail(l2)); continue SetTreeModule_compareStacks; } } } else { let matchResult_1: int32 = (undefined as any), t1_7: FSharpList>> = (undefined as any), x1_5: SetTreeLeaf$1 = (undefined as any), t2_7: FSharpList>> = (undefined as any), x2_5: SetTreeLeaf$1 = (undefined as any); if (!isEmpty_1(l1)) { if (head(l1) != null) { matchResult_1 = 0; t1_7 = tail(l1); x1_5 = value_2(head(l1)); } else if (!isEmpty_1(l2)) { if (head(l2) != null) { matchResult_1 = 1; t2_7 = tail(l2); x2_5 = value_2(head(l2)); } else { matchResult_1 = 2; } } else { matchResult_1 = 2; } } else if (!isEmpty_1(l2)) { if (head(l2) != null) { matchResult_1 = 1; t2_7 = tail(l2); x2_5 = value_2(head(l2)); } else { matchResult_1 = 2; } } else { matchResult_1 = 2; } switch (matchResult_1) { case 0: if (x1_5! instanceof SetTreeNode$1) { const x1n_4 = x1_5! as SetTreeNode$1; comparer_mut = comparer; l1_mut = ofArrayWithTail([SetTreeNode$1__get_Left(x1n_4), SetTreeNode$1_$ctor_5F465FC9(SetTreeLeaf$1__get_Key(x1n_4), SetTreeModule_empty(), SetTreeNode$1__get_Right(x1n_4), 0)], t1_7!); l2_mut = l2; continue SetTreeModule_compareStacks; } else { comparer_mut = comparer; l1_mut = ofArrayWithTail([SetTreeModule_empty(), SetTreeLeaf$1_$ctor_2B595(SetTreeLeaf$1__get_Key(x1_5!))], t1_7!); l2_mut = l2; continue SetTreeModule_compareStacks; } case 1: if (x2_5! instanceof SetTreeNode$1) { const x2n_4 = x2_5! as SetTreeNode$1; comparer_mut = comparer; l1_mut = l1; l2_mut = ofArrayWithTail([SetTreeNode$1__get_Left(x2n_4), SetTreeNode$1_$ctor_5F465FC9(SetTreeLeaf$1__get_Key(x2n_4), SetTreeModule_empty(), SetTreeNode$1__get_Right(x2n_4), 0)], t2_7!); continue SetTreeModule_compareStacks; } else { comparer_mut = comparer; l1_mut = l1; l2_mut = ofArrayWithTail([SetTreeModule_empty(), SetTreeLeaf$1_$ctor_2B595(SetTreeLeaf$1__get_Key(x2_5!))], t2_7!); continue SetTreeModule_compareStacks; } default: throw new Exception("unexpected state in SetTree.compareStacks"); } } } else if (x2_3 instanceof SetTreeNode$1) { const x2n_5 = x2_3 as SetTreeNode$1; if (SetTreeNode$1__get_Left(x2n_5) == null) { const c_2: int32 = comparer.Compare(SetTreeLeaf$1__get_Key(x1_3), SetTreeLeaf$1__get_Key(x2n_5)) | 0; if (c_2 !== 0) { return c_2 | 0; } else { comparer_mut = comparer; l1_mut = cons(SetTreeModule_empty(), tail(l1)); l2_mut = cons(SetTreeNode$1__get_Right(x2n_5), tail(l2)); continue SetTreeModule_compareStacks; } } else { let matchResult_2: int32 = (undefined as any), t1_8: FSharpList>> = (undefined as any), x1_6: SetTreeLeaf$1 = (undefined as any), t2_8: FSharpList>> = (undefined as any), x2_6: SetTreeLeaf$1 = (undefined as any); if (!isEmpty_1(l1)) { if (head(l1) != null) { matchResult_2 = 0; t1_8 = tail(l1); x1_6 = value_2(head(l1)); } else if (!isEmpty_1(l2)) { if (head(l2) != null) { matchResult_2 = 1; t2_8 = tail(l2); x2_6 = value_2(head(l2)); } else { matchResult_2 = 2; } } else { matchResult_2 = 2; } } else if (!isEmpty_1(l2)) { if (head(l2) != null) { matchResult_2 = 1; t2_8 = tail(l2); x2_6 = value_2(head(l2)); } else { matchResult_2 = 2; } } else { matchResult_2 = 2; } switch (matchResult_2) { case 0: if (x1_6! instanceof SetTreeNode$1) { const x1n_5 = x1_6! as SetTreeNode$1; comparer_mut = comparer; l1_mut = ofArrayWithTail([SetTreeNode$1__get_Left(x1n_5), SetTreeNode$1_$ctor_5F465FC9(SetTreeLeaf$1__get_Key(x1n_5), SetTreeModule_empty(), SetTreeNode$1__get_Right(x1n_5), 0)], t1_8!); l2_mut = l2; continue SetTreeModule_compareStacks; } else { comparer_mut = comparer; l1_mut = ofArrayWithTail([SetTreeModule_empty(), SetTreeLeaf$1_$ctor_2B595(SetTreeLeaf$1__get_Key(x1_6!))], t1_8!); l2_mut = l2; continue SetTreeModule_compareStacks; } case 1: if (x2_6! instanceof SetTreeNode$1) { const x2n_6 = x2_6! as SetTreeNode$1; comparer_mut = comparer; l1_mut = l1; l2_mut = ofArrayWithTail([SetTreeNode$1__get_Left(x2n_6), SetTreeNode$1_$ctor_5F465FC9(SetTreeLeaf$1__get_Key(x2n_6), SetTreeModule_empty(), SetTreeNode$1__get_Right(x2n_6), 0)], t2_8!); continue SetTreeModule_compareStacks; } else { comparer_mut = comparer; l1_mut = l1; l2_mut = ofArrayWithTail([SetTreeModule_empty(), SetTreeLeaf$1_$ctor_2B595(SetTreeLeaf$1__get_Key(x2_6!))], t2_8!); continue SetTreeModule_compareStacks; } default: throw new Exception("unexpected state in SetTree.compareStacks"); } } } else { const c_3: int32 = comparer.Compare(SetTreeLeaf$1__get_Key(x1_3), SetTreeLeaf$1__get_Key(x2_3)) | 0; if (c_3 !== 0) { return c_3 | 0; } else { comparer_mut = comparer; l1_mut = tail(l1); l2_mut = tail(l2); continue SetTreeModule_compareStacks; } } } else { const x2: SetTreeLeaf$1 = value_2(head(l2)); let matchResult_3: int32 = (undefined as any), t1_2: FSharpList>> = (undefined as any), x1: SetTreeLeaf$1 = (undefined as any), t2_2: FSharpList>> = (undefined as any), x2_1: SetTreeLeaf$1 = (undefined as any); if (!isEmpty_1(l1)) { if (head(l1) != null) { matchResult_3 = 0; t1_2 = tail(l1); x1 = value_2(head(l1)); } else if (!isEmpty_1(l2)) { if (head(l2) != null) { matchResult_3 = 1; t2_2 = tail(l2); x2_1 = value_2(head(l2)); } else { matchResult_3 = 2; } } else { matchResult_3 = 2; } } else if (!isEmpty_1(l2)) { if (head(l2) != null) { matchResult_3 = 1; t2_2 = tail(l2); x2_1 = value_2(head(l2)); } else { matchResult_3 = 2; } } else { matchResult_3 = 2; } switch (matchResult_3) { case 0: if (x1! instanceof SetTreeNode$1) { const x1n = x1! as SetTreeNode$1; comparer_mut = comparer; l1_mut = ofArrayWithTail([SetTreeNode$1__get_Left(x1n), SetTreeNode$1_$ctor_5F465FC9(SetTreeLeaf$1__get_Key(x1n), SetTreeModule_empty(), SetTreeNode$1__get_Right(x1n), 0)], t1_2!); l2_mut = l2; continue SetTreeModule_compareStacks; } else { comparer_mut = comparer; l1_mut = ofArrayWithTail([SetTreeModule_empty(), SetTreeLeaf$1_$ctor_2B595(SetTreeLeaf$1__get_Key(x1!))], t1_2!); l2_mut = l2; continue SetTreeModule_compareStacks; } case 1: if (x2_1! instanceof SetTreeNode$1) { const x2n = x2_1! as SetTreeNode$1; comparer_mut = comparer; l1_mut = l1; l2_mut = ofArrayWithTail([SetTreeNode$1__get_Left(x2n), SetTreeNode$1_$ctor_5F465FC9(SetTreeLeaf$1__get_Key(x2n), SetTreeModule_empty(), SetTreeNode$1__get_Right(x2n), 0)], t2_2!); continue SetTreeModule_compareStacks; } else { comparer_mut = comparer; l1_mut = l1; l2_mut = ofArrayWithTail([SetTreeModule_empty(), SetTreeLeaf$1_$ctor_2B595(SetTreeLeaf$1__get_Key(x2_1!))], t2_2!); continue SetTreeModule_compareStacks; } default: throw new Exception("unexpected state in SetTree.compareStacks"); } } } else if (head(l1) != null) { const x1_1: SetTreeLeaf$1 = value_2(head(l1)); let matchResult_4: int32 = (undefined as any), t1_4: FSharpList>> = (undefined as any), x1_2: SetTreeLeaf$1 = (undefined as any), t2_4: FSharpList>> = (undefined as any), x2_2: SetTreeLeaf$1 = (undefined as any); if (!isEmpty_1(l1)) { if (head(l1) != null) { matchResult_4 = 0; t1_4 = tail(l1); x1_2 = value_2(head(l1)); } else if (!isEmpty_1(l2)) { if (head(l2) != null) { matchResult_4 = 1; t2_4 = tail(l2); x2_2 = value_2(head(l2)); } else { matchResult_4 = 2; } } else { matchResult_4 = 2; } } else if (!isEmpty_1(l2)) { if (head(l2) != null) { matchResult_4 = 1; t2_4 = tail(l2); x2_2 = value_2(head(l2)); } else { matchResult_4 = 2; } } else { matchResult_4 = 2; } switch (matchResult_4) { case 0: if (x1_2! instanceof SetTreeNode$1) { const x1n_1 = x1_2! as SetTreeNode$1; comparer_mut = comparer; l1_mut = ofArrayWithTail([SetTreeNode$1__get_Left(x1n_1), SetTreeNode$1_$ctor_5F465FC9(SetTreeLeaf$1__get_Key(x1n_1), SetTreeModule_empty(), SetTreeNode$1__get_Right(x1n_1), 0)], t1_4!); l2_mut = l2; continue SetTreeModule_compareStacks; } else { comparer_mut = comparer; l1_mut = ofArrayWithTail([SetTreeModule_empty(), SetTreeLeaf$1_$ctor_2B595(SetTreeLeaf$1__get_Key(x1_2!))], t1_4!); l2_mut = l2; continue SetTreeModule_compareStacks; } case 1: if (x2_2! instanceof SetTreeNode$1) { const x2n_1 = x2_2! as SetTreeNode$1; comparer_mut = comparer; l1_mut = l1; l2_mut = ofArrayWithTail([SetTreeNode$1__get_Left(x2n_1), SetTreeNode$1_$ctor_5F465FC9(SetTreeLeaf$1__get_Key(x2n_1), SetTreeModule_empty(), SetTreeNode$1__get_Right(x2n_1), 0)], t2_4!); continue SetTreeModule_compareStacks; } else { comparer_mut = comparer; l1_mut = l1; l2_mut = ofArrayWithTail([SetTreeModule_empty(), SetTreeLeaf$1_$ctor_2B595(SetTreeLeaf$1__get_Key(x2_2!))], t2_4!); continue SetTreeModule_compareStacks; } default: throw new Exception("unexpected state in SetTree.compareStacks"); } } else { comparer_mut = comparer; l1_mut = tail(l1); l2_mut = tail(l2); continue SetTreeModule_compareStacks; } } else { return 1; } } else if (isEmpty_1(l2)) { return 0; } else { return -1; } break; } } export function SetTreeModule_compare(comparer: IComparer, t1: Option>, t2: Option>): int32 { if (t1 == null) { if (t2 == null) { return 0; } else { return -1; } } else if (t2 == null) { return 1; } else { return SetTreeModule_compareStacks(comparer, singleton_1(t1), singleton_1(t2)) | 0; } } export function SetTreeModule_choose<$a>(s: Option>): $a { return SetTreeModule_minimumElement<$a>(s); } export function SetTreeModule_toList(t: Option>): FSharpList { const loop = (t$0027_mut: Option>, acc_mut: FSharpList): FSharpList => { loop: while (true) { const t$0027: Option> = t$0027_mut, acc: FSharpList = acc_mut; if (t$0027 != null) { const t2: SetTreeLeaf$1 = value_2(t$0027); if (t2 instanceof SetTreeNode$1) { const tn = t2 as SetTreeNode$1; t$0027_mut = SetTreeNode$1__get_Left(tn); acc_mut = cons(SetTreeLeaf$1__get_Key(tn), loop(SetTreeNode$1__get_Right(tn), acc)); continue loop; } else { return cons(SetTreeLeaf$1__get_Key(t2), acc); } } else { return acc; } break; } }; return loop(t, empty_1()); } export function SetTreeModule_copyToArray<$a>(s: Option>, arr: MutableArray<$a>, i: int32): void { let j: int32 = i; SetTreeModule_iter<$a>((x: $a): void => { setItem(arr, j, x); j = ((j + 1) | 0); }, s); } export function SetTreeModule_toArray<$a>(s: Option>): MutableArray<$a> { const n: int32 = SetTreeModule_count<$a>(s) | 0; const res: MutableArray<$a> = fill(new Array(n), 0, n, null); SetTreeModule_copyToArray<$a>(s, res, 0); return res; } export function SetTreeModule_mkFromEnumerator<$a>(comparer_mut: IComparer<$a>, acc_mut: Option>, e_mut: IEnumerator<$a>): Option> { SetTreeModule_mkFromEnumerator: while (true) { const comparer: IComparer<$a> = comparer_mut, acc: Option> = acc_mut, e: IEnumerator<$a> = e_mut; if (e["System.Collections.IEnumerator.MoveNext"]()) { comparer_mut = comparer; acc_mut = SetTreeModule_add<$a>(comparer, e["System.Collections.Generic.IEnumerator`1.get_Current"](), acc); e_mut = e; continue SetTreeModule_mkFromEnumerator; } else { return acc; } break; } } export function SetTreeModule_ofArray<$a>(comparer: IComparer<$a>, l: MutableArray<$a>): Option> { return fold_1<$a, Option>>((acc: Option>, k: $a): Option> => SetTreeModule_add<$a>(comparer, k, acc), SetTreeModule_empty<$a>(), l); } export function SetTreeModule_ofList<$a>(comparer: IComparer<$a>, l: FSharpList<$a>): Option> { return fold_2<$a, Option>>((acc: Option>, k: $a): Option> => SetTreeModule_add<$a>(comparer, k, acc), SetTreeModule_empty<$a>(), l); } export function SetTreeModule_ofSeq(comparer: IComparer, c: Iterable): Option> { if (isArrayLike(c)) { return SetTreeModule_ofArray(comparer, c); } else if (c instanceof FSharpList) { return SetTreeModule_ofList(comparer, c); } else { const ie: IEnumerator = getEnumerator(c); try { return SetTreeModule_mkFromEnumerator(comparer, SetTreeModule_empty(), ie); } finally { disposeSafe(ie as IDisposable); } } } export class FSharpSet implements ISet, Iterable, Iterable { readonly tree: Option>; readonly comparer: IComparer; constructor(comparer: IComparer, tree: Option>) { this.comparer = comparer; this.tree = tree; } GetHashCode(): int32 { const this$: FSharpSet = this; return FSharpSet__ComputeHashCode(this$) | 0; } Equals(other: any): boolean { let that: FSharpSet = undefined as any; const this$: FSharpSet = this; return (other instanceof FSharpSet) && ((that = (other as FSharpSet), SetTreeModule_compare(FSharpSet__get_Comparer(this$), FSharpSet__get_Tree(this$), FSharpSet__get_Tree(that)) === 0)); } toString(): string { const this$: FSharpSet = this; return ("set [" + join("; ", this$)) + "]"; } get [Symbol.toStringTag](): string { return "FSharpSet"; } toJSON(): any { const this$: FSharpSet = this; return Array.from(this$); } CompareTo(other: any): int32 { let that: FSharpSet = undefined as any; const this$: FSharpSet = this; return ((other instanceof FSharpSet) ? ((that = (other as FSharpSet), SetTreeModule_compare(FSharpSet__get_Comparer(this$), FSharpSet__get_Tree(this$), FSharpSet__get_Tree(that)))) : 1) | 0; } "System.Collections.Generic.ICollection`1.Add2B595"(x: T): void { throw NotSupportedException_$ctor_Z721C83C5("ReadOnlyCollection"); } "System.Collections.Generic.ICollection`1.Clear"(): void { throw NotSupportedException_$ctor_Z721C83C5("ReadOnlyCollection"); } "System.Collections.Generic.ICollection`1.Remove2B595"(x: T): boolean { throw NotSupportedException_$ctor_Z721C83C5("ReadOnlyCollection"); } "System.Collections.Generic.ICollection`1.Contains2B595"(x: T): boolean { const s: FSharpSet = this; return SetTreeModule_mem(FSharpSet__get_Comparer(s), x, FSharpSet__get_Tree(s)); } "System.Collections.Generic.ICollection`1.CopyToZ3B4C077E"(arr: MutableArray, i: int32): void { const s: FSharpSet = this; SetTreeModule_copyToArray(FSharpSet__get_Tree(s), arr, i); } "System.Collections.Generic.ICollection`1.get_IsReadOnly"(): boolean { return true; } "System.Collections.Generic.ICollection`1.get_Count"(): int32 { const s: FSharpSet = this; return FSharpSet__get_Count(s) | 0; } "System.Collections.Generic.IReadOnlyCollection`1.get_Count"(): int32 { const s: FSharpSet = this; return FSharpSet__get_Count(s) | 0; } GetEnumerator(): IEnumerator { const s: FSharpSet = this; return SetTreeModule_mkIEnumerator(FSharpSet__get_Tree(s)); } [Symbol.iterator](): Iterator { return toIterator(getEnumerator(this)); } "System.Collections.IEnumerable.GetEnumerator"(): IEnumerator { const s: FSharpSet = this; return SetTreeModule_mkIEnumerator(FSharpSet__get_Tree(s)); } get size(): int32 { const s: FSharpSet = this; return FSharpSet__get_Count(s) | 0; } add(k: T): ISet { const s: FSharpSet = this; throw new Exception("Set cannot be mutated"); return s; } clear(): void { throw new Exception("Set cannot be mutated"); } delete(k: T): boolean { throw new Exception("Set cannot be mutated"); return false; } has(k: T): boolean { const s: FSharpSet = this; return FSharpSet__Contains(s, k); } keys(): Iterable { const s: FSharpSet = this; return map_1((x: T): T => x, s); } values(): Iterable { const s: FSharpSet = this; return map_1((x: T): T => x, s); } entries(): Iterable<[T, T]> { const s: FSharpSet = this; return map_1((v: T): [T, T] => ([v, v] as [T, T]), s); } forEach(f: ((arg0: T, arg1: T, arg2: ISet) => void), thisArg?: Option): void { const s: FSharpSet = this; iterate_1((x: T): void => { f(x, x, s); }, s); } } export function FSharpSet_$reflection(gen0: TypeInfo): TypeInfo { return class_type("Set.FSharpSet", [gen0], FSharpSet); } export function FSharpSet_$ctor(comparer: IComparer, tree: Option>): FSharpSet { return new FSharpSet(comparer, tree); } export function FSharpSet__get_Comparer(set$: FSharpSet): IComparer { return set$.comparer; } export function FSharpSet__get_Tree(set$: FSharpSet): Option> { return set$.tree; } export function FSharpSet_Empty(comparer: IComparer): FSharpSet { return FSharpSet_$ctor(comparer, SetTreeModule_empty()); } export function FSharpSet__Add(s: FSharpSet, value: T): FSharpSet { return FSharpSet_$ctor(FSharpSet__get_Comparer(s), SetTreeModule_add(FSharpSet__get_Comparer(s), value, FSharpSet__get_Tree(s))); } export function FSharpSet__Remove(s: FSharpSet, value: T): FSharpSet { return FSharpSet_$ctor(FSharpSet__get_Comparer(s), SetTreeModule_remove(FSharpSet__get_Comparer(s), value, FSharpSet__get_Tree(s))); } export function FSharpSet__get_Count(s: FSharpSet): int32 { return SetTreeModule_count(FSharpSet__get_Tree(s)) | 0; } export function FSharpSet__Contains(s: FSharpSet, value: T): boolean { return SetTreeModule_mem(FSharpSet__get_Comparer(s), value, FSharpSet__get_Tree(s)); } export function FSharpSet__Iterate(s: FSharpSet, x: ((arg0: T) => void)): void { SetTreeModule_iter(x, FSharpSet__get_Tree(s)); } export function FSharpSet__Fold(s: FSharpSet, f: ((arg0: T, arg1: $a) => $a), z: $a): $a { const f_1: any = f; return SetTreeModule_fold<$a, T>((x: $a, z_1: T): $a => f_1(z_1, x), z, FSharpSet__get_Tree(s)); } export function FSharpSet__get_IsEmpty(s: FSharpSet): boolean { return FSharpSet__get_Tree(s) == null; } export function FSharpSet__Partition(s: FSharpSet, f: ((arg0: T) => boolean)): [FSharpSet, FSharpSet] { if (FSharpSet__get_Tree(s) == null) { return [s, s] as [FSharpSet, FSharpSet]; } else { const patternInput: [Option>, Option>] = SetTreeModule_partition(FSharpSet__get_Comparer(s), f, FSharpSet__get_Tree(s)); return [FSharpSet_$ctor(FSharpSet__get_Comparer(s), patternInput[0]), FSharpSet_$ctor(FSharpSet__get_Comparer(s), patternInput[1])] as [FSharpSet, FSharpSet]; } } export function FSharpSet__Filter(s: FSharpSet, f: ((arg0: T) => boolean)): FSharpSet { if (FSharpSet__get_Tree(s) == null) { return s; } else { return FSharpSet_$ctor(FSharpSet__get_Comparer(s), SetTreeModule_filter(FSharpSet__get_Comparer(s), f, FSharpSet__get_Tree(s))); } } export function FSharpSet__Map(s: FSharpSet, f: ((arg0: T) => U), comparer: IComparer): FSharpSet { return FSharpSet_$ctor(comparer, SetTreeModule_fold>, T>((acc: Option>, k: T): Option> => SetTreeModule_add(comparer, f(k), acc), SetTreeModule_empty(), FSharpSet__get_Tree(s))); } export function FSharpSet__Exists(s: FSharpSet, f: ((arg0: T) => boolean)): boolean { return SetTreeModule_exists(f, FSharpSet__get_Tree(s)); } export function FSharpSet__ForAll(s: FSharpSet, f: ((arg0: T) => boolean)): boolean { return SetTreeModule_forall(f, FSharpSet__get_Tree(s)); } export function FSharpSet_op_Subtraction(set1: FSharpSet, set2: FSharpSet): FSharpSet { if (FSharpSet__get_Tree(set1) == null) { return set1; } else if (FSharpSet__get_Tree(set2) == null) { return set1; } else { return FSharpSet_$ctor(FSharpSet__get_Comparer(set1), SetTreeModule_diff(FSharpSet__get_Comparer(set1), FSharpSet__get_Tree(set1), FSharpSet__get_Tree(set2))); } } export function FSharpSet_op_Addition(set1: FSharpSet, set2: FSharpSet): FSharpSet { if (FSharpSet__get_Tree(set2) == null) { return set1; } else if (FSharpSet__get_Tree(set1) == null) { return set2; } else { return FSharpSet_$ctor(FSharpSet__get_Comparer(set1), SetTreeModule_union(FSharpSet__get_Comparer(set1), FSharpSet__get_Tree(set1), FSharpSet__get_Tree(set2))); } } export function FSharpSet_Intersection(a: FSharpSet, b: FSharpSet): FSharpSet { if (FSharpSet__get_Tree(b) == null) { return b; } else if (FSharpSet__get_Tree(a) == null) { return a; } else { return FSharpSet_$ctor(FSharpSet__get_Comparer(a), SetTreeModule_intersection(FSharpSet__get_Comparer(a), FSharpSet__get_Tree(a), FSharpSet__get_Tree(b))); } } export function FSharpSet_IntersectionMany(sets: Iterable>): FSharpSet { return reduce>(FSharpSet_Intersection, sets); } export function FSharpSet_Equality(a: FSharpSet, b: FSharpSet): boolean { return SetTreeModule_compare(FSharpSet__get_Comparer(a), FSharpSet__get_Tree(a), FSharpSet__get_Tree(b)) === 0; } export function FSharpSet_Compare(a: FSharpSet, b: FSharpSet): int32 { return SetTreeModule_compare(FSharpSet__get_Comparer(a), FSharpSet__get_Tree(a), FSharpSet__get_Tree(b)) | 0; } export function FSharpSet__get_Choose(x: FSharpSet): T { return SetTreeModule_choose(FSharpSet__get_Tree(x)); } export function FSharpSet__get_MinimumElement(x: FSharpSet): T { return SetTreeModule_minimumElement(FSharpSet__get_Tree(x)); } export function FSharpSet__get_MaximumElement(x: FSharpSet): T { return SetTreeModule_maximumElement(FSharpSet__get_Tree(x)); } export function FSharpSet__IsSubsetOf(x: FSharpSet, otherSet: FSharpSet): boolean { return SetTreeModule_subset(FSharpSet__get_Comparer(x), FSharpSet__get_Tree(x), FSharpSet__get_Tree(otherSet)); } export function FSharpSet__IsSupersetOf(x: FSharpSet, otherSet: FSharpSet): boolean { return SetTreeModule_subset(FSharpSet__get_Comparer(x), FSharpSet__get_Tree(otherSet), FSharpSet__get_Tree(x)); } export function FSharpSet__IsProperSubsetOf(x: FSharpSet, otherSet: FSharpSet): boolean { return SetTreeModule_properSubset(FSharpSet__get_Comparer(x), FSharpSet__get_Tree(x), FSharpSet__get_Tree(otherSet)); } export function FSharpSet__IsProperSupersetOf(x: FSharpSet, otherSet: FSharpSet): boolean { return SetTreeModule_properSubset(FSharpSet__get_Comparer(x), FSharpSet__get_Tree(otherSet), FSharpSet__get_Tree(x)); } export function FSharpSet__ToList(x: FSharpSet): FSharpList { return SetTreeModule_toList(FSharpSet__get_Tree(x)); } export function FSharpSet__ToArray(x: FSharpSet): MutableArray { return SetTreeModule_toArray(FSharpSet__get_Tree(x)); } export function FSharpSet__ComputeHashCode(this$: FSharpSet): int32 { let res = 0; const enumerator: IEnumerator = getEnumerator(this$); try { while (enumerator["System.Collections.IEnumerator.MoveNext"]()) { const x_1: T = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"](); res = ((((res << 1) + structuralHash(x_1)) + 631) | 0); } } finally { disposeSafe(enumerator as IDisposable); } return Math.abs(res) | 0; } export function isEmpty(set$: FSharpSet): boolean { return FSharpSet__get_IsEmpty(set$); } export function contains(element: T, set$: FSharpSet): boolean { return FSharpSet__Contains(set$, element); } export function add(value: T, set$: FSharpSet): FSharpSet { return FSharpSet__Add(set$, value); } export function singleton(value: T, comparer: IComparer): FSharpSet { return FSharpSet__Add(FSharpSet_Empty(comparer), value); } export function remove(value: T, set$: FSharpSet): FSharpSet { return FSharpSet__Remove(set$, value); } export function union(set1: FSharpSet, set2: FSharpSet): FSharpSet { return FSharpSet_op_Addition(set1, set2); } export function unionMany(sets: Iterable>, comparer: IComparer): FSharpSet { return fold_3, FSharpSet>(FSharpSet_op_Addition, FSharpSet_Empty(comparer), sets); } export function intersect(set1: FSharpSet, set2: FSharpSet): FSharpSet { return FSharpSet_Intersection(set1, set2); } export function intersectMany(sets: Iterable>): FSharpSet { return FSharpSet_IntersectionMany(sets); } export function iterate(action: ((arg0: T) => void), set$: FSharpSet): void { FSharpSet__Iterate(set$, action); } export function empty(comparer: IComparer): FSharpSet { return FSharpSet_Empty(comparer); } export function forAll(predicate: ((arg0: T) => boolean), set$: FSharpSet): boolean { return FSharpSet__ForAll(set$, predicate); } export function exists(predicate: ((arg0: T) => boolean), set$: FSharpSet): boolean { return FSharpSet__Exists(set$, predicate); } export function filter(predicate: ((arg0: T) => boolean), set$: FSharpSet): FSharpSet { return FSharpSet__Filter(set$, predicate); } export function partition(predicate: ((arg0: T) => boolean), set$: FSharpSet): [FSharpSet, FSharpSet] { return FSharpSet__Partition(set$, predicate); } export function fold(folder: ((arg0: State, arg1: T) => State), state: State, set$: FSharpSet): State { return SetTreeModule_fold(folder, state, FSharpSet__get_Tree(set$)); } export function foldBack(folder: ((arg0: T, arg1: State) => State), set$: FSharpSet, state: State): State { return SetTreeModule_foldBack(folder, FSharpSet__get_Tree(set$), state); } export function map(mapping: ((arg0: T) => U), set$: FSharpSet, comparer: IComparer): FSharpSet { return FSharpSet__Map(set$, mapping, comparer); } export function count(set$: FSharpSet): int32 { return FSharpSet__get_Count(set$) | 0; } export function ofList(elements: Iterable, comparer: IComparer): FSharpSet { return FSharpSet_$ctor(comparer, SetTreeModule_ofSeq(comparer, elements)); } export function ofArray(array: MutableArray, comparer: IComparer): FSharpSet { return FSharpSet_$ctor(comparer, SetTreeModule_ofArray(comparer, array)); } export function toList(set$: FSharpSet): FSharpList { return FSharpSet__ToList(set$); } export function toArray(set$: FSharpSet): MutableArray { return FSharpSet__ToArray(set$); } export function toSeq(set$: FSharpSet): Iterable { return map_1((x: T): T => x, set$); } export function ofSeq(elements: Iterable, comparer: IComparer): FSharpSet { return FSharpSet_$ctor(comparer, SetTreeModule_ofSeq(comparer, elements)); } export function difference(set1: FSharpSet, set2: FSharpSet): FSharpSet { return FSharpSet_op_Subtraction(set1, set2); } export function isSubset(set1: FSharpSet, set2: FSharpSet): boolean { return SetTreeModule_subset(FSharpSet__get_Comparer(set1), FSharpSet__get_Tree(set1), FSharpSet__get_Tree(set2)); } export function isSuperset(set1: FSharpSet, set2: FSharpSet): boolean { return SetTreeModule_subset(FSharpSet__get_Comparer(set1), FSharpSet__get_Tree(set2), FSharpSet__get_Tree(set1)); } export function isProperSubset(set1: FSharpSet, set2: FSharpSet): boolean { return SetTreeModule_properSubset(FSharpSet__get_Comparer(set1), FSharpSet__get_Tree(set1), FSharpSet__get_Tree(set2)); } export function isProperSuperset(set1: FSharpSet, set2: FSharpSet): boolean { return SetTreeModule_properSubset(FSharpSet__get_Comparer(set1), FSharpSet__get_Tree(set2), FSharpSet__get_Tree(set1)); } export function minElement(set$: FSharpSet): T { return FSharpSet__get_MinimumElement(set$); } export function maxElement(set$: FSharpSet): T { return FSharpSet__get_MaximumElement(set$); } export function unionWith(s1: ISet, s2: Iterable): ISet { return fold_3>((acc: ISet, x: T): ISet => acc.add(x), s1, s2); } export function newMutableSetWith(s1: ISet, s2: Iterable): ISet { if (s1 instanceof HashSet) { const s1_1 = s1 as HashSet; return HashSet_$ctor_Z6150332D(s2, HashSet__get_Comparer(s1_1)); } else { return new Set(s2); } } export function intersectWith(s1: ISet, s2: Iterable): void { const s2_1: ISet = newMutableSetWith(s1, s2); iterate_1((x: T): void => { if (!s2_1.has(x)) { s1.delete(x); } }, s1.values()); } export function exceptWith(s1: ISet, s2: Iterable): void { iterate_1((x: T): void => { s1.delete(x); }, s2); } export function isSubsetOf(s1: ISet, s2: Iterable): boolean { const s2_1: ISet = newMutableSetWith(s1, s2); return forAll_1((value: T): boolean => s2_1.has(value), s1.values()); } export function isSupersetOf(s1: ISet, s2: Iterable): boolean { return forAll_1((value: T): boolean => s1.has(value), s2); } export function isProperSubsetOf(s1: ISet, s2: Iterable): boolean { const s2_1: ISet = newMutableSetWith(s1, s2); if (s2_1.size > s1.size) { return forAll_1((value: T): boolean => s2_1.has(value), s1.values()); } else { return false; } } export function isProperSupersetOf(s1: ISet, s2: Iterable): boolean { const s2_1: ISet = newMutableSetWith(s1, s2); if (s1.size > s2_1.size) { return forAll_1((value: T): boolean => s1.has(value), s2_1.values()); } else { return false; } } export function symmetricExceptWith(s1: ISet, s2: Iterable): void { const s2_1: ISet = newMutableSetWith(s1, s2); iterate_1((x: T): void => { if (s1.has(x)) { s1.delete(x); } else { s1.add(x); } }, s2_1.values()); } export function overlaps(s1: ISet, s2: Iterable): boolean { return exists_1((value: T): boolean => s1.has(value), s2); } export function setEquals(s1: ISet, s2: Iterable): boolean { const s2_1: ISet = newMutableSetWith(s1, s2); if (s1.size === s2_1.size) { return forAll_1((value: T): boolean => s2_1.has(value), s1.values()); } else { return false; } } export function copyToArray(s1: ISet, target: MutableArray, sourceIndex: int32, targetIndex: int32, count_1: int32): void { iterateIndexed((index: int32, value: T): void => { setItem(target, targetIndex + index, value); }, truncate(count_1, skip(sourceIndex, s1.values()))); }