Wrappers.cs (53975B)
1 using Std.Clone; 2 using Std.Cmp; 3 using static Std.Cmp.Ordering; 4 using Std.Convert; 5 using Std.Hashing; 6 using Std.Iter; 7 using Std.Maybe; 8 using static Std.Maybe.Maybe<Std.Cmp.Ordering>; 9 using static Std.Maybe.Maybe<uint>; 10 using Std.Ops; 11 using Std.Result; 12 using System; 13 using System.Globalization; 14 using System.Runtime.InteropServices; 15 #region Namespaces 16 namespace Std.Wrappers { 17 #region Types 18 #pragma warning disable CA1051, CA1066, CA1716, CA1720, CA1724, CA1815, CA1819, CA2231, IDE1006 19 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 0)] 20 public struct Array<T>: IProduct<T[]>, IIndex<uint, T>, IIndexMut<uint, T>, IInto<Array<T>>, IIntoIterator<T, ArrayIntoIter<T>> where T: notnull { 21 22 #region Type-level Constructors 23 #endregion 24 25 #region Instance Constructors 26 public Array() => Value = Array.Empty<T>(); 27 public Array(T[] arr) => Value = arr; 28 #endregion 29 30 #region Type-level Fields 31 #endregion 32 33 #region Instance Fields 34 public T[] Value; 35 #endregion 36 37 #region Type-level Properties 38 #endregion 39 40 #region Instance Properties 41 public readonly ref readonly T this[uint index] => ref Value[(int)index]; 42 public readonly T[] Field0 => Value; 43 #endregion 44 45 #region Type-level Functions 46 #endregion 47 48 #region Instance Functions 49 public readonly void Deconstruct(out T[] t0) => t0 = Value; 50 public override readonly bool Equals(object? _) => false; 51 public override readonly int GetHashCode() => 0; 52 public readonly Array<T> Into() => this; 53 public readonly ArrayIntoIter<T> IntoIter() => new(Value); 54 public readonly ref T ItemMut(uint index) => ref Value[(int)index]; 55 public override readonly string ToString() => string.Empty; 56 readonly Result<Array<T>, Bottom> ITryInto<Array<T>, Bottom>.TryInto() => new(this); 57 #endregion 58 59 #region Operators 60 public static implicit operator Array<T>(in T[] val) => new(val); 61 public static implicit operator T[](Array<T> val) => val.Value; 62 #endregion 63 64 #region Types 65 #endregion 66 } 67 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 0)] 68 public struct ArrayIntoIter<T>: IDoubleEndedIterator<T>, IExactSizeIterator<T>, IFusedIterator<T>, IInto<ArrayIntoIter<T>>, IIntoIterator<T, ArrayIntoIter<T>> where T: notnull { 69 70 #region Type-level Constructors 71 #endregion 72 73 #region Instance Constructors 74 public ArrayIntoIter() => throw new InvalidOperationException("Parameterless constructor is not allowed to be called!"); 75 internal ArrayIntoIter(T[] arr) => (_arr, _index, _indexBack) = (arr, 0, arr.Length - 1); 76 #endregion 77 78 #region Type-level Fields 79 #endregion 80 81 #region Instance Fields 82 readonly T[] _arr; 83 int _index; 84 int _indexBack; 85 #endregion 86 87 #region Type-level Properties 88 #endregion 89 90 #region Instance Properties 91 #endregion 92 93 #region Type-level Functions 94 #endregion 95 96 #region Instance Functions 97 public Result<Unit, ulong> AdvanceBy(ulong n) { 98 99 if (n == ulong.MinValue) { 100 return new(new Unit()); 101 } else { 102 var val = _indexBack - _index + 1; 103 104 if (n > (ulong)val) { 105 _index = _indexBack + 1; 106 return new((ulong)val); 107 } else { 108 _index += (int)n; 109 return new(new Unit()); 110 } 111 } 112 } 113 public Result<Unit, ulong> AdvanceBackBy(ulong n) { 114 115 if (n == ulong.MinValue) { 116 return new(new Unit()); 117 } else { 118 var val = _indexBack - _index + 1; 119 120 if (n > (ulong)val) { 121 _indexBack = _index - 1; 122 return new((ulong)val); 123 } else { 124 _indexBack -= (int)n; 125 return new(new Unit()); 126 } 127 } 128 } 129 public readonly Span<T> AsMutSlice() => _index <= _indexBack ? _arr.AsSpan()[_index..(_indexBack + 1)] : Span<T>.Empty; 130 public readonly ReadOnlySpan<T> AsSlice() => _index <= _indexBack ? _arr.AsSpan()[_index..(_indexBack + 1)] : ReadOnlySpan<T>.Empty; 131 public readonly ulong Count() => Len(); 132 public override readonly bool Equals(object? _) => false; 133 public TInit Fold<TInit>(TInit init, Fn<TInit, T, TInit> f) where TInit: notnull { 134 135 while (_index <= _indexBack) { init = f(init, _arr[_index++]); } 136 return init; 137 } 138 public override readonly int GetHashCode() => 0; 139 public readonly ArrayIntoIter<T> Into() => this; 140 public readonly ArrayIntoIter<T> IntoIter() => this; 141 public readonly bool IsEmpty() => Len() == ulong.MinValue; 142 public Maybe<T> Last() => _index > _indexBack ? Maybe<T>.None() : new(_arr[_indexBack]); 143 public readonly ulong Len() => (ulong)(1 + _indexBack - _index); 144 public Maybe<T> Next() => _index > _indexBack ? Maybe<T>.None() : Maybe<T>.Some(_arr[_index++]); 145 public Maybe<T> NextBack() => _indexBack < _index ? Maybe<T>.None() : Maybe<T>.Some(_arr[_indexBack--]); 146 public TInit RFold<TInit>(TInit init, Fn<TInit, T, TInit> f) where TInit: notnull { 147 148 while (_index <= _indexBack) { init = f(init, _arr[_indexBack--]); } 149 return init; 150 } 151 public readonly Prod<ulong, Maybe<ulong>> SizeHint() => new(Len(), new(Len())); 152 public override readonly string ToString() => string.Empty; 153 public Result<TInit, TErr> TryFold<TInit, TErr>(TInit init, Fn<TInit, T, Result<TInit, TErr>> f) where TInit: notnull where TErr: notnull { 154 155 while (_index <= _indexBack) { 156 var res = f(init!, _arr[_index++]); 157 158 if (res.IsErr) { 159 return res; 160 } else { 161 init = res._ok; 162 } 163 } 164 return new(init!); 165 } 166 readonly Result<ArrayIntoIter<T>, Bottom> ITryInto<ArrayIntoIter<T>, Bottom>.TryInto() => new(this); 167 public Result<TInit, TErr> TryRFold<TInit, TErr>(TInit init, Fn<TInit, T, Result<TInit, TErr>> f) where TInit: notnull where TErr: notnull { 168 169 while (_index <= _indexBack) { 170 var res = f(init, _arr[_indexBack--]); 171 172 if (res.IsErr) { 173 return res; 174 } else { 175 init = res._ok; 176 } 177 } 178 return new(init); 179 } 180 #endregion 181 182 #region Operators 183 #endregion 184 185 #region Types 186 #endregion 187 } 188 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 0)] 189 public readonly struct CulturedString: IProduct<string, CultureInfo, CompareOptions>, IClone<CulturedString>, IHashable, IInto<CulturedString>, IInto<string>, IOrd<CulturedString> { 190 191 #region Type-level Constructors 192 #endregion 193 194 #region Instance Constructors 195 public CulturedString() => (Value, Culture, Options) = (string.Empty, CultureInfo.ReadOnly(CultureInfo.InvariantCulture), CompareOptions.Ordinal); 196 public CulturedString(string val, CultureInfo culture, CompareOptions options) => (Value, Culture, Options) = (val, CultureInfo.ReadOnly((CultureInfo)culture.Clone()), options); 197 #endregion 198 199 #region Type-level Fields 200 #endregion 201 202 #region Instance Fields 203 public readonly string Value; 204 public readonly CultureInfo Culture; 205 public readonly CompareOptions Options; 206 #endregion 207 208 #region Type-level Properties 209 #endregion 210 211 #region Instance Properties 212 public readonly string Field0 => Value; 213 public readonly CultureInfo Field1 => Culture; 214 public readonly CompareOptions Field2 => Options; 215 #endregion 216 217 #region Type-level Functions 218 #endregion 219 220 #region Instance Functions 221 public readonly CulturedString Clone() => this; 222 public readonly Ordering Cmp(in CulturedString other) => Options != other.Options || !Culture.Equals(other.Culture) ? throw new InvalidOperationException($"The Cultures, {Culture.ToString()} and {other.Culture.ToString()}, of the two CulturedStrings are not the same or the Options, {Options.ToString()} and {other.Options.ToString()}, are not the same.") : (Culture.CompareInfo.Compare(Value, other.Value, Options) switch { 223 < 0 => Less, 224 > 0 => Greater, 225 0=> Equivalent, 226 }); 227 public readonly void Deconstruct(out string t0, out CultureInfo t1, out CompareOptions t2) => (t0, t1, t2) = (Value, Culture, Options); 228 public override readonly bool Equals(object? _) => false; 229 public override readonly int GetHashCode() => 0; 230 public readonly Unit Hash<THasher>(ref THasher hasher) where THasher: notnull, IHasher => hasher.WriteUnsafe(Culture.CompareInfo.GetHashCode(Value, Options)); 231 public readonly CulturedString Into() => this; 232 public readonly string IntoString() => ToString(); 233 readonly string IInto<string>.Into() => IntoString(); 234 public readonly Maybe<Ordering> PartialCmp(in CulturedString other) => Some(Cmp(in other)); 235 public override readonly string ToString() => Value; 236 readonly Result<CulturedString, Bottom> ITryInto<CulturedString, Bottom>.TryInto() => new(this); 237 readonly Result<string, Bottom> ITryInto<string, Bottom>.TryInto() => new(ToString()); 238 #endregion 239 240 #region Operators 241 public static bool operator !=(CulturedString val0, CulturedString val1) => !(val0 == val1); 242 public static bool operator <(CulturedString val0, CulturedString val1) => val0.Cmp(in val1).Var == Ordering.Ord.Less; 243 public static bool operator <=(CulturedString val0, CulturedString val1) => !(val0 > val1); 244 public static bool operator ==(CulturedString val0, CulturedString val1) => val0.Cmp(in val1).Var == Ordering.Ord.Equivalent; 245 public static bool operator >(CulturedString val0, CulturedString val1) => val0.Cmp(in val1).Var == Ordering.Ord.Greater; 246 public static bool operator >=(CulturedString val0, CulturedString val1) => !(val0 < val1); 247 #endregion 248 249 #region Types 250 #endregion 251 } 252 [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode, Pack = 8, Size = 8)] 253 public struct DateTime: IProduct<System.DateTime>, IClone<DateTime>, IEquality<DateTime>, IHashable, IInto<DateTime>, IInto<string>, IOrd<DateTime> { 254 255 #region Type-level Constructors 256 #endregion 257 258 #region Instance Constructors 259 public DateTime() => Value = System.DateTime.MinValue; 260 public DateTime(System.DateTime val) => Value = val; 261 #endregion 262 263 #region Type-level Fields 264 #endregion 265 266 #region Instance Fields 267 [FieldOffset(0)]public System.DateTime Value; 268 #endregion 269 270 #region Type-level Properties 271 #endregion 272 273 #region Instance Properties 274 public readonly System.DateTime Field0 => Value; 275 #endregion 276 277 #region Type-level Functions 278 #endregion 279 280 #region Instance Functions 281 public readonly DateTime Clone() => this; 282 public readonly Ordering Cmp(in DateTime other) => Value.CompareTo(other.Value) switch { 283 < 0 => Less, 284 > 0 => Greater, 285 0=> Equivalent, 286 }; 287 public readonly void Deconstruct(out System.DateTime t0) => t0 = Value; 288 public readonly bool Equals(in DateTime other) => this == other; 289 public override readonly bool Equals(object? _) => false; 290 public override readonly int GetHashCode() => 0; 291 public readonly Unit Hash<THasher>(ref THasher hasher) where THasher: notnull, IHasher => hasher.WriteLong(Value.Ticks); 292 public readonly DateTime Into() => this; 293 public readonly string IntoString() => ToString(); 294 readonly string IInto<string>.Into() => IntoString(); 295 public readonly Maybe<Ordering> PartialCmp(in DateTime other) => Some(Cmp(in other)); 296 public override readonly string ToString() => Value.ToString("O"); 297 readonly Result<DateTime, Bottom> ITryInto<DateTime, Bottom>.TryInto() => new(this); 298 readonly Result<string, Bottom> ITryInto<string, Bottom>.TryInto() => new(ToString()); 299 #endregion 300 301 #region Operators 302 public static bool operator !=(DateTime val0, DateTime val1) => !(val0 == val1); 303 public static bool operator <(DateTime val0, DateTime val1) => val0.Value < val1.Value; 304 public static bool operator <=(DateTime val0, DateTime val1) => !(val0 > val1); 305 public static bool operator ==(DateTime val0, DateTime val1) => val0 == val1; 306 public static bool operator >(DateTime val0, DateTime val1) => val0.Value > val1.Value; 307 public static bool operator >=(DateTime val0, DateTime val1) => !(val0 < val1); 308 public static implicit operator DateTime(System.DateTime val) => new(val); 309 public static implicit operator System.DateTime(DateTime val) => val.Value; 310 #endregion 311 312 #region Types 313 #endregion 314 } 315 [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode, Pack = 8, Size = 16)] 316 public struct DateTimeOffset: IProduct<System.DateTimeOffset>, IClone<DateTimeOffset>, IEquality<DateTimeOffset>, IHashable, IInto<DateTimeOffset>, IInto<string>, IOrd<DateTimeOffset> { 317 318 #region Type-level Constructors 319 #endregion 320 321 #region Instance Constructors 322 public DateTimeOffset() => Value = System.DateTimeOffset.MinValue; 323 public DateTimeOffset(System.DateTimeOffset val) => Value = val; 324 #endregion 325 326 #region Type-level Fields 327 #endregion 328 329 #region Instance Fields 330 [FieldOffset(0)]public System.DateTimeOffset Value; 331 #endregion 332 333 #region Type-level Properties 334 #endregion 335 336 #region Instance Properties 337 public readonly System.DateTimeOffset Field0 => Value; 338 #endregion 339 340 #region Type-level Functions 341 #endregion 342 343 #region Instance Functions 344 public readonly DateTimeOffset Clone() => this; 345 public readonly Ordering Cmp(in DateTimeOffset other) => Value.CompareTo(other.Value) switch { 346 < 0 => Less, 347 > 0 => Greater, 348 0=> Equivalent, 349 }; 350 public readonly void Deconstruct(out System.DateTimeOffset t0) => t0 = Value; 351 public readonly bool Equals(in DateTimeOffset other) => this == other; 352 public override readonly bool Equals(object? _) => false; 353 public override readonly int GetHashCode() => 0; 354 public readonly Unit Hash<THasher>(ref THasher hasher) where THasher: notnull, IHasher => hasher.WriteLong(Value.UtcTicks); 355 public readonly DateTimeOffset Into() => this; 356 public readonly string IntoString() => ToString(); 357 readonly string IInto<string>.Into() => IntoString(); 358 public readonly Maybe<Ordering> PartialCmp(in DateTimeOffset other) => Some(Cmp(in other)); 359 public override readonly string ToString() => Value.ToString("O"); 360 readonly Result<DateTimeOffset, Bottom> ITryInto<DateTimeOffset, Bottom>.TryInto() => new(this); 361 readonly Result<string, Bottom> ITryInto<string, Bottom>.TryInto() => new(ToString()); 362 #endregion 363 364 #region Operators 365 public static bool operator !=(DateTimeOffset val0, DateTimeOffset val1) => !(val0 == val1); 366 public static bool operator <(DateTimeOffset val0, DateTimeOffset val1) => val0.Value < val1.Value; 367 public static bool operator <=(DateTimeOffset val0, DateTimeOffset val1) => !(val0 > val1); 368 public static bool operator ==(DateTimeOffset val0, DateTimeOffset val1) => val0 == val1; 369 public static bool operator >(DateTimeOffset val0, DateTimeOffset val1) => val0.Value > val1.Value; 370 public static bool operator >=(DateTimeOffset val0, DateTimeOffset val1) => !(val0 < val1); 371 public static implicit operator DateTimeOffset(System.DateTimeOffset val) => new(val); 372 public static implicit operator System.DateTimeOffset(DateTimeOffset val) => val.Value; 373 #endregion 374 375 #region Types 376 #endregion 377 } 378 [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode, Pack = 4, Size = 16)] 379 public struct Guid: IProduct<System.Guid>, IClone<Guid>, IEquality<Guid>, IHashable, IInto<Guid>, IInto<string>, IOrd<Guid> { 380 381 #region Type-level Constructors 382 #endregion 383 384 #region Instance Constructors 385 public Guid() => Value = System.Guid.Empty; 386 public Guid(System.Guid val) => Value = val; 387 #endregion 388 389 #region Type-level Fields 390 #endregion 391 392 #region Instance Fields 393 [FieldOffset(0)]public System.Guid Value; 394 #endregion 395 396 #region Type-level Properties 397 #endregion 398 399 #region Instance Properties 400 public readonly System.Guid Field0 => Value; 401 #endregion 402 403 #region Type-level Functions 404 #endregion 405 406 #region Instance Functions 407 public readonly Guid Clone() => this; 408 public readonly Ordering Cmp(in Guid other) => Value.CompareTo(other.Value) switch { 409 < 0 => Less, 410 > 0 => Greater, 411 0=> Equivalent, 412 }; 413 public readonly void Deconstruct(out System.Guid t0) => t0 = Value; 414 public readonly bool Equals(in Guid other) => this == other; 415 public override readonly bool Equals(object? _) => false; 416 public override readonly int GetHashCode() => 0; 417 public readonly Unit Hash<THasher>(ref THasher hasher) where THasher: notnull, IHasher => hasher.WriteUnsafe(this); 418 public readonly Guid Into() => this; 419 public readonly string IntoString() => ToString(); 420 readonly string IInto<string>.Into() => IntoString(); 421 public readonly Maybe<Ordering> PartialCmp(in Guid other) => Some(Cmp(in other)); 422 public override readonly string ToString() => Value.ToString("D"); 423 readonly Result<Guid, Bottom> ITryInto<Guid, Bottom>.TryInto() => new(this); 424 readonly Result<string, Bottom> ITryInto<string, Bottom>.TryInto() => new(ToString()); 425 #endregion 426 427 #region Operators 428 public static bool operator !=(Guid val0, Guid val1) => !(val0 == val1); 429 public static bool operator <(Guid val0, Guid val1) => val0.Value < val1.Value; 430 public static bool operator <=(Guid val0, Guid val1) => !(val0 > val1); 431 public static bool operator ==(Guid val0, Guid val1) => val0 == val1; 432 public static bool operator >(Guid val0, Guid val1) => val0.Value > val1.Value; 433 public static bool operator >=(Guid val0, Guid val1) => !(val0 < val1); 434 public static implicit operator Guid(System.Guid val) => new(val); 435 public static implicit operator System.Guid(Guid val) => val.Value; 436 #endregion 437 438 #region Types 439 #endregion 440 } 441 [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode, Pack = 8, Size = 8)] 442 public struct TimeSpan: IProduct<System.TimeSpan>, IClone<TimeSpan>, IEquality<TimeSpan>, IHashable, IInto<TimeSpan>, IInto<string>, IOrd<TimeSpan> { 443 444 #region Type-level Constructors 445 #endregion 446 447 #region Instance Constructors 448 public TimeSpan() => Value = System.TimeSpan.Zero; 449 public TimeSpan(System.TimeSpan val) => Value = val; 450 #endregion 451 452 #region Type-level Fields 453 #endregion 454 455 #region Instance Fields 456 [FieldOffset(0)]public System.TimeSpan Value; 457 #endregion 458 459 #region Type-level Properties 460 #endregion 461 462 #region Instance Properties 463 public readonly System.TimeSpan Field0 => Value; 464 #endregion 465 466 #region Type-level Functions 467 #endregion 468 469 #region Instance Functions 470 public readonly TimeSpan Clone() => this; 471 public readonly Ordering Cmp(in TimeSpan other) => Value.CompareTo(other.Value) switch { 472 < 0 => Less, 473 > 0 => Greater, 474 0=> Equivalent, 475 }; 476 public readonly void Deconstruct(out System.TimeSpan t0) => t0 = Value; 477 public readonly bool Equals(in TimeSpan other) => this == other; 478 public override readonly bool Equals(object? _) => false; 479 public override readonly int GetHashCode() => 0; 480 public readonly Unit Hash<THasher>(ref THasher hasher) where THasher: notnull, IHasher => hasher.WriteUnsafe(this); 481 public readonly TimeSpan Into() => this; 482 public readonly string IntoString() => ToString(); 483 readonly string IInto<string>.Into() => IntoString(); 484 public readonly Maybe<Ordering> PartialCmp(in TimeSpan other) => Some(Cmp(in other)); 485 public override readonly string ToString() => Value.ToString("c"); 486 readonly Result<TimeSpan, Bottom> ITryInto<TimeSpan, Bottom>.TryInto() => new(this); 487 readonly Result<string, Bottom> ITryInto<string, Bottom>.TryInto() => new(ToString()); 488 #endregion 489 490 #region Operators 491 public static bool operator !=(TimeSpan val0, TimeSpan val1) => !(val0 == val1); 492 public static bool operator <(TimeSpan val0, TimeSpan val1) => val0.Value < val1.Value; 493 public static bool operator <=(TimeSpan val0, TimeSpan val1) => !(val0 > val1); 494 public static bool operator ==(TimeSpan val0, TimeSpan val1) => val0 == val1; 495 public static bool operator >(TimeSpan val0, TimeSpan val1) => val0.Value > val1.Value; 496 public static bool operator >=(TimeSpan val0, TimeSpan val1) => !(val0 < val1); 497 public static implicit operator TimeSpan(System.TimeSpan val) => new(val); 498 public static implicit operator System.TimeSpan(TimeSpan val) => val.Value; 499 #endregion 500 501 #region Types 502 #endregion 503 } 504 [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode, Pack = 1, Size = 1)] 505 public struct @bool: IProduct<bool>, IClone<@bool>, IEquality<@bool>, IHashable, IInto<@bool>, IInto<string>, IOrd<@bool> { 506 507 #region Type-level Constructors 508 #endregion 509 510 #region Instance Constructors 511 public @bool() => Value = false; 512 public @bool(bool val) => Value = val; 513 #endregion 514 515 #region Type-level Fields 516 #endregion 517 518 #region Instance Fields 519 [FieldOffset(0)]public bool Value; 520 #endregion 521 522 #region Type-level Properties 523 #endregion 524 525 #region Instance Properties 526 public readonly bool Field0 => Value; 527 #endregion 528 529 #region Type-level Functions 530 #endregion 531 532 #region Instance Functions 533 public readonly @bool Clone() => this; 534 public readonly Ordering Cmp(in @bool other) => Value.CompareTo(other.Value) switch { 535 < 0 => Less, 536 > 0 => Greater, 537 0=> Equivalent, 538 }; 539 public readonly void Deconstruct(out bool t0) => t0 = Value; 540 public readonly bool Equals(in @bool other) => this == other; 541 public override readonly bool Equals(object? _) => false; 542 public override readonly int GetHashCode() => 0; 543 public readonly Unit Hash<THasher>(ref THasher hasher) where THasher: notnull, IHasher => hasher.WriteByte(Value ? (byte)1 : byte.MinValue); 544 public readonly @bool Into() => this; 545 public readonly string IntoString() => ToString(); 546 readonly string IInto<string>.Into() => IntoString(); 547 public readonly Maybe<Ordering> PartialCmp(in @bool other) => Some(Cmp(in other)); 548 public override readonly string ToString() => Value.ToString(); 549 readonly Result<@bool, Bottom> ITryInto<@bool, Bottom>.TryInto() => new(this); 550 readonly Result<string, Bottom> ITryInto<string, Bottom>.TryInto() => new(ToString()); 551 #endregion 552 553 #region Operators 554 public static bool operator !=(@bool val0, @bool val1) => !(val0 == val1); 555 public static bool operator <(@bool val0, @bool val1) => !val0.Value && val1.Value; 556 public static bool operator <=(@bool val0, @bool val1) => !(val0 > val1); 557 public static bool operator ==(@bool val0, @bool val1) => val0 == val1; 558 public static bool operator >(@bool val0, @bool val1) => val0.Value && !val1.Value; 559 public static bool operator >=(@bool val0, @bool val1) => !(val0 < val1); 560 public static implicit operator @bool(bool val) => new(val); 561 public static implicit operator bool(@bool val) => val.Value; 562 #endregion 563 564 #region Types 565 #endregion 566 } 567 [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode, Pack = 2, Size = 2)] 568 public struct @char: IProduct<char>, IClone<@char>, IEquality<@char>, IHashable, IInto<@char>, IInto<string>, IOrd<@char> { 569 570 #region Type-level Constructors 571 #endregion 572 573 #region Instance Constructors 574 public @char() => Value = char.MinValue; 575 public @char(char val) => Value = val; 576 #endregion 577 578 #region Type-level Fields 579 #endregion 580 581 #region Instance Fields 582 [FieldOffset(0)]public char Value; 583 #endregion 584 585 #region Type-level Properties 586 #endregion 587 588 #region Instance Properties 589 public readonly char Field0 => Value; 590 #endregion 591 592 #region Type-level Functions 593 #endregion 594 595 #region Instance Functions 596 public readonly @char Clone() => this; 597 public readonly Ordering Cmp(in @char other) => Value.CompareTo(other.Value) switch { 598 < 0 => Less, 599 > 0 => Greater, 600 0=> Equivalent, 601 }; 602 public readonly void Deconstruct(out char t0) => t0 = Value; 603 public readonly bool Equals(in @char other) => this == other; 604 public override readonly bool Equals(object? _) => false; 605 public override readonly int GetHashCode() => 0; 606 public readonly Unit Hash<THasher>(ref THasher hasher) where THasher: notnull, IHasher => hasher.WriteUnsafe(this); 607 public readonly @char Into() => this; 608 public readonly string IntoString() => ToString(); 609 readonly string IInto<string>.Into() => IntoString(); 610 public readonly Maybe<Ordering> PartialCmp(in @char other) => Some(Cmp(in other)); 611 public override readonly string ToString() => Value.ToString(); 612 readonly Result<@char, Bottom> ITryInto<@char, Bottom>.TryInto() => new(this); 613 readonly Result<string, Bottom> ITryInto<string, Bottom>.TryInto() => new(ToString()); 614 #endregion 615 616 #region Operators 617 public static bool operator !=(@char val0, @char val1) => !(val0 == val1); 618 public static bool operator <(@char val0, @char val1) => val0.Value < val1.Value; 619 public static bool operator <=(@char val0, @char val1) => !(val0 > val1); 620 public static bool operator ==(@char val0, @char val1) => val0 == val1; 621 public static bool operator >(@char val0, @char val1) => val0.Value > val1.Value; 622 public static bool operator >=(@char val0, @char val1) => !(val0 < val1); 623 public static implicit operator @char(char val) => new(val); 624 public static implicit operator char(@char val) => val.Value; 625 #endregion 626 627 #region Types 628 #endregion 629 } 630 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 0)] 631 public struct @string: IProduct<string>, IClone<@string>, IEquality<@string>, IHashable, IInto<@string>, IInto<string>, IOrd<@string> { 632 633 #region Type-level Constructors 634 #endregion 635 636 #region Instance Constructors 637 public @string() => Value = string.Empty; 638 public @string(string val) => Value = val; 639 #endregion 640 641 #region Type-level Fields 642 #endregion 643 644 #region Instance Fields 645 public string Value; 646 #endregion 647 648 #region Type-level Properties 649 #endregion 650 651 #region Instance Properties 652 public readonly string Field0 => Value; 653 #endregion 654 655 #region Type-level Functions 656 #endregion 657 658 #region Instance Functions 659 public readonly @string Clone() => this; 660 public readonly Ordering Cmp(in @string other) => string.CompareOrdinal(Value, other.Value) switch { 661 662 < 0 => Less, 663 > 0 => Greater, 664 0 => Equivalent, 665 }; 666 public readonly void Deconstruct(out string t0) => t0 = Value; 667 public readonly bool Equals(in @string other) => this == other; 668 public override readonly bool Equals(object? _) => false; 669 public override readonly int GetHashCode() => 0; 670 public readonly Unit Hash<THasher>(ref THasher hasher) where THasher: notnull, IHasher => hasher.WriteSliceUnsafe(Value.AsSpan()); 671 public readonly @string Into() => this; 672 public readonly string IntoString() => ToString(); 673 readonly string IInto<string>.Into() => IntoString(); 674 public readonly Maybe<Ordering> PartialCmp(in @string other) => Some(Cmp(in other)); 675 public override readonly string ToString() => Value; 676 readonly Result<@string, Bottom> ITryInto<@string, Bottom>.TryInto() => new(this); 677 readonly Result<string, Bottom> ITryInto<string, Bottom>.TryInto() => new(ToString()); 678 #endregion 679 680 #region Operators 681 public static bool operator !=(@string val0, @string val1) => !(val0 == val1); 682 public static bool operator <(@string val0, @string val1) => string.CompareOrdinal(val0.Value, val1.Value) < 0; 683 public static bool operator <=(@string val0, @string val1) => !(val0 > val1); 684 public static bool operator ==(@string val0, @string val1) => val0 == val1; 685 public static bool operator >(@string val0, @string val1) => string.CompareOrdinal(val0.Value, val1.Value) > 0; 686 public static bool operator >=(@string val0, @string val1) => !(val0 < val1); 687 public static implicit operator @string(string val) => new(val); 688 public static implicit operator string(@string val) => val.Value; 689 #endregion 690 691 #region Types 692 #endregion 693 } 694 #endregion 695 696 #region Namespaces 697 namespace SortedDictionary { 698 #region Types 699 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 0)] 700 readonly struct Comparer<TKey>: System.Collections.Generic.IComparer<TKey> where TKey: notnull, IOrd<TKey> { 701 702 #region Type-level Constructors 703 #endregion 704 705 #region Instance Constructors 706 public Comparer(){} 707 #endregion 708 709 #region Type-level Fields 710 #endregion 711 712 #region Instance Fields 713 #endregion 714 715 #region Type-level Properties 716 #endregion 717 718 #region Instance Properties 719 #endregion 720 721 #region Type-level Functions 722 #endregion 723 724 #region Instance Functions 725 public readonly int Compare(TKey? x, TKey? y) => x!.Cmp(in y!).Var switch { 726 Ord.Less => -1, 727 Ord.Equivalent => 0, 728 _ => 1, 729 }; 730 public override readonly bool Equals(object? _) => false; 731 public override readonly int GetHashCode() => 0; 732 public override readonly string ToString() => string.Empty; 733 #endregion 734 735 #region Operators 736 #endregion 737 738 #region Types 739 #endregion 740 } 741 // This is a TEMPORARY solution. 742 // A true ground-up implementation of a B-tree based on Rust's std::collections::BTreeMap is the goal. 743 // At which point this type should be made obsolete. 744 // This is also why this type is in Std.Wrappers.SortedDictionary and not Std.Collections. 745 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 0)] 746 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix", Justification = "Want to convey this is a wrapper around System.Collections.Generic.SortedDictionary<TKey, TValue>.")] 747 public readonly struct SortedDictionary<TKey, TValue>: IInto<SortedDictionary<TKey, TValue>>, IIntoIterator<Prod<TKey, TValue>, IntoIter<TKey, TValue>> where TKey: notnull, IOrd<TKey> where TValue: notnull { 748 749 #region Type-level Constructors 750 #endregion 751 752 #region Instance Constructors 753 public SortedDictionary() => Value = new(new Comparer<TKey>()); 754 SortedDictionary(System.Collections.Generic.SortedDictionary<TKey, TValue> dict) => Value = dict; 755 #endregion 756 757 #region Type-level Fields 758 #endregion 759 760 #region Instance Fields 761 readonly System.Collections.Generic.SortedDictionary<TKey, TValue> Value; 762 #endregion 763 764 #region Type-level Properties 765 #endregion 766 767 #region Instance Properties 768 public readonly TValue this[TKey key] => Value[key]; 769 public readonly bool IsEmpty => Len == uint.MinValue; 770 public readonly uint Len => (uint)Value.Count; 771 #endregion 772 773 #region Type-level Functions 774 public static SortedDictionary<TKey, TValue> New() => new(); 775 #endregion 776 777 #region Instance Functions 778 public readonly Unit Append(SortedDictionary<TKey, TValue> other) { 779 780 using var enumer = other.Value.GetEnumerator(); 781 System.Collections.Generic.KeyValuePair<TKey, TValue> kvp; 782 while (enumer.MoveNext()) { 783 kvp = enumer.Current; 784 _ = Insert(kvp.Key, kvp.Value); 785 } 786 return other.Clear(); 787 } 788 public readonly Unit Clear() { 789 790 Value.Clear(); 791 return new Unit(); 792 } 793 public readonly bool ContainsKey(in TKey key) => Value.ContainsKey(key); 794 public override readonly bool Equals(object? _) => false; 795 public readonly Maybe<TValue> Get(in TKey key) => Value.TryGetValue(key, out var val) ? new(val) : Maybe<TValue>.None(); 796 public override readonly int GetHashCode() => 0; 797 public readonly Maybe<Prod<TKey, TValue>> GetKeyValue(in TKey key) => Value.TryGetValue(key, out var val) ? new(new(key, val)) : Maybe<Prod<TKey, TValue>>.None(); 798 public readonly TValue GetOrInsert(TKey key, TValue value) { 799 800 var val = Get(in key); 801 if (val.IsSome) { 802 return val.Unwrap(); 803 } else { 804 _ = Insert(key, value); 805 return value; 806 } 807 } 808 public readonly TValue GetOrInsertWith(TKey key, Fn<TValue> f) { 809 810 var val = Get(in key); 811 if (val.IsSome) { 812 return val.Unwrap(); 813 } else { 814 var v = f(); 815 _ = Insert(key, v); 816 return v; 817 } 818 } 819 public readonly Maybe<TValue> Insert(TKey key, TValue value) { 820 821 var val = Remove(in key); 822 Value.Add(key, value); 823 return val; 824 } 825 public readonly SortedDictionary<TKey, TValue> Into() => this; 826 public readonly IntoKeys<TKey, TValue> IntoKeys() => new(IntoIter()); 827 public readonly IntoIter<TKey, TValue> IntoIter() => new(Value); 828 public readonly IntoValues<TKey, TValue> IntoValues() => new(IntoIter()); 829 public readonly Maybe<TValue> Remove(in TKey key) { 830 831 Maybe<TValue> val; 832 if ((val = Get(in key)).IsSome) { _ = Value.Remove(key); } 833 return val; 834 } 835 public override readonly string ToString() => string.Empty; 836 readonly Result<SortedDictionary<TKey, TValue>, Bottom> ITryInto<SortedDictionary<TKey, TValue>, Bottom>.TryInto() => new(this); 837 #endregion 838 839 #region Operators 840 #endregion 841 842 #region Types 843 #endregion 844 } 845 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 0)] 846 public struct IntoIter<TKey, TValue>: IDisposable, IExactSizeIterator<Prod<TKey, TValue>>, IFusedIterator<Prod<TKey, TValue>>, IInto<IntoIter<TKey, TValue>> where TKey: notnull, IOrd<TKey> where TValue: notnull { 847 848 #region Type-level Constructors 849 #endregion 850 851 #region Instance Constructors 852 public IntoIter() => throw new InvalidOperationException("Parameterless constructor is not allowed to be called!"); 853 internal IntoIter(System.Collections.Generic.SortedDictionary<TKey, TValue> dict) => (_enumer, _index, _count) = (dict.GetEnumerator(), uint.MinValue, (uint)dict.Count); 854 #endregion 855 856 #region Type-level Fields 857 #endregion 858 859 #region Instance Fields 860 System.Collections.Generic.SortedDictionary<TKey, TValue>.Enumerator _enumer; 861 uint _index; 862 readonly uint _count; 863 #endregion 864 865 #region Type-level Properties 866 #endregion 867 868 #region Instance Properties 869 #endregion 870 871 #region Type-level Functions 872 #endregion 873 874 #region Instance Functions 875 public void Dispose() => _enumer.Dispose(); 876 public Result<Unit, ulong> AdvanceBy(ulong n) { 877 878 if (n == ulong.MinValue) { 879 return new(new Unit()); 880 } else { 881 var val = Len(); 882 883 if (n > val) { 884 _index = _count; 885 return new(val); 886 } else { 887 _index += (uint)n; 888 for (var i = uint.MinValue; i < (uint)n; i++) { _ = _enumer.MoveNext(); } 889 return new(new Unit()); 890 } 891 } 892 } 893 public readonly ulong Count() => Len(); 894 public override readonly bool Equals(object? _) => false; 895 public TInit Fold<TInit>(TInit init, Fn<TInit, Prod<TKey, TValue>, TInit> f) where TInit: notnull { 896 897 System.Collections.Generic.KeyValuePair<TKey, TValue> kvp; 898 while (_index < _count) { 899 _index++; 900 _ = _enumer.MoveNext(); 901 kvp = _enumer.Current; 902 init = f(init, new(kvp.Key, kvp.Value)); 903 } 904 return init; 905 } 906 public override readonly int GetHashCode() => 0; 907 public readonly IntoIter<TKey, TValue> Into() => this; 908 public readonly bool IsEmpty() => Len() == ulong.MinValue; 909 public Maybe<Prod<TKey, TValue>> Last() => IIterator<Prod<TKey, TValue>>.LastDefault<IntoIter<TKey, TValue>>(ref this); 910 public readonly ulong Len() => _count - _index; 911 public Maybe<Prod<TKey, TValue>> Next() { 912 913 if (_index < _count) { 914 _index++; 915 _ = _enumer.MoveNext(); 916 var cur = _enumer.Current; 917 return new(new(cur.Key, cur.Value)); 918 } else { 919 return Maybe<Prod<TKey, TValue>>.None(); 920 } 921 } 922 public readonly Prod<ulong, Maybe<ulong>> SizeHint() => new(Len(), new(Len())); 923 public override readonly string ToString() => string.Empty; 924 public Result<TInit, TErr> TryFold<TInit, TErr>(TInit init, Fn<TInit, Prod<TKey, TValue>, Result<TInit, TErr>> f) where TInit: notnull where TErr: notnull { 925 926 System.Collections.Generic.KeyValuePair<TKey, TValue> kvp; 927 Result<TInit, TErr> res; 928 929 while (_index < _count) { 930 _index++; 931 _ = _enumer.MoveNext(); 932 kvp = _enumer.Current; 933 res = f(init, new(kvp.Key, kvp.Value)); 934 935 if (res.IsErr) { 936 return res; 937 } else { 938 init = res._ok; 939 } 940 } 941 return new(init); 942 } 943 readonly Result<IntoIter<TKey, TValue>, Bottom> ITryInto<IntoIter<TKey, TValue>, Bottom>.TryInto() => new(this); 944 #endregion 945 946 #region Operators 947 #endregion 948 949 #region Types 950 #endregion 951 } 952 public struct IntoKeys<TKey, TValue>: IDisposable, IInto<IntoKeys<TKey, TValue>>, IExactSizeIterator<TKey>, IFusedIterator<TKey> where TKey: notnull, IOrd<TKey> where TValue: notnull { 953 954 #region Type-level Constructors 955 #endregion 956 957 #region Instance Constructors 958 public IntoKeys() => throw new InvalidOperationException("Parameterless constructor is not allowed to be called!"); 959 internal IntoKeys(IntoIter<TKey, TValue> inner) => _inner = inner; 960 #endregion 961 962 #region Type-level Fields 963 #endregion 964 965 #region Instance Fields 966 IntoIter<TKey, TValue> _inner; 967 #endregion 968 969 #region Type-level Properties 970 #endregion 971 972 #region Instance Properties 973 #endregion 974 975 #region Type-level Functions 976 #endregion 977 978 #region Instance Functions 979 public void Dispose() => _inner.Dispose(); 980 public Result<Unit, ulong> AdvanceBy(ulong n) => IIterator<TKey>.AdvanceByDefault(ref this, n); 981 public ulong Count() => IIterator<TKey>.CountDefault(ref this); 982 public TInit Fold<TInit>(TInit init, Fn<TInit, TKey, TInit> f) where TInit: notnull => IIterator<TKey>.FoldDefault(ref this, init, f); 983 public override readonly bool Equals(object? _) => false; 984 public override readonly int GetHashCode() => 0; 985 public readonly IntoKeys<TKey, TValue> Into() => this; 986 public readonly bool IsEmpty() => _inner.IsEmpty(); 987 public Maybe<TKey> Last() => IIterator<TKey>.LastDefault(ref this); 988 public readonly ulong Len() => _inner.Len(); 989 public Maybe<TKey> Next() => _inner.Next().Map((tup) => tup.Item0); 990 public readonly Prod<ulong, Maybe<ulong>> SizeHint() => _inner.SizeHint(); 991 public override readonly string ToString() => string.Empty; 992 public Result<TInit, TErr> TryFold<TInit, TErr>(TInit init, Fn<TInit, TKey, Result<TInit, TErr>> f) where TInit: notnull where TErr: notnull => IIterator<TKey>.TryFoldDefault(ref this, init, f); 993 readonly Result<IntoKeys<TKey, TValue>, Bottom> ITryInto<IntoKeys<TKey, TValue>, Bottom>.TryInto() => new(this); 994 #endregion 995 996 #region Operators 997 #endregion 998 999 #region Types 1000 #endregion 1001 } 1002 public struct IntoValues<TKey, TValue>: IDisposable, IInto<IntoValues<TKey, TValue>>, IExactSizeIterator<TValue>, IFusedIterator<TValue> where TKey: notnull, IOrd<TKey> where TValue: notnull { 1003 1004 #region Type-level Constructors 1005 #endregion 1006 1007 #region Instance Constructors 1008 public IntoValues() => throw new InvalidOperationException("Parameterless constructor is not allowed to be called!"); 1009 internal IntoValues(IntoIter<TKey, TValue> inner) => _inner = inner; 1010 #endregion 1011 1012 #region Type-level Fields 1013 #endregion 1014 1015 #region Instance Fields 1016 IntoIter<TKey, TValue> _inner; 1017 #endregion 1018 1019 #region Type-level Properties 1020 #endregion 1021 1022 #region Instance Properties 1023 #endregion 1024 1025 #region Type-level Functions 1026 #endregion 1027 1028 #region Instance Functions 1029 public void Dispose() => _inner.Dispose(); 1030 public Result<Unit, ulong> AdvanceBy(ulong n) => IIterator<TValue>.AdvanceByDefault(ref this, n); 1031 public ulong Count() => IIterator<TValue>.CountDefault(ref this); 1032 public TInit Fold<TInit>(TInit init, Fn<TInit, TValue, TInit> f) where TInit: notnull => IIterator<TValue>.FoldDefault(ref this, init, f); 1033 public override readonly bool Equals(object? _) => false; 1034 public override readonly int GetHashCode() => 0; 1035 public readonly IntoValues<TKey, TValue> Into() => this; 1036 public readonly bool IsEmpty() => _inner.IsEmpty(); 1037 public Maybe<TValue> Last() => IIterator<TValue>.LastDefault(ref this); 1038 public readonly ulong Len() => _inner.Len(); 1039 public Maybe<TValue> Next() => _inner.Next().Map((tup) => tup.Item1); 1040 public readonly Prod<ulong, Maybe<ulong>> SizeHint() => _inner.SizeHint(); 1041 public override readonly string ToString() => string.Empty; 1042 public Result<TInit, TErr> TryFold<TInit, TErr>(TInit init, Fn<TInit, TValue, Result<TInit, TErr>> f) where TInit: notnull where TErr: notnull => IIterator<TValue>.TryFoldDefault(ref this, init, f); 1043 readonly Result<IntoValues<TKey, TValue>, Bottom> ITryInto<IntoValues<TKey, TValue>, Bottom>.TryInto() => new(this); 1044 #endregion 1045 1046 #region Operators 1047 #endregion 1048 1049 #region Types 1050 #endregion 1051 } 1052 #endregion 1053 1054 #region Namespaces 1055 #endregion 1056 } 1057 namespace SortedSet { 1058 #region Types 1059 // This is a TEMPORARY solution. 1060 // A true ground-up implementation of a B-tree based on Rust's std::collections::BTreeSet is the goal. 1061 // At which point this type should be made obsolete. 1062 // This is also why this type is in Std.Wrappers.SortedSet and not Std.Collections. 1063 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 0)] 1064 public readonly struct SortedSet<TKey>: IInto<SortedSet<TKey>>, IIntoIterator<TKey, IntoIter<TKey>> where TKey: notnull, IOrd<TKey> { 1065 1066 #region Type-level Constructors 1067 #endregion 1068 1069 #region Instance Constructors 1070 public SortedSet() => Value = new(new SortedDictionary.Comparer<TKey>()); 1071 SortedSet(System.Collections.Generic.SortedSet<TKey> set) => Value = set; 1072 #endregion 1073 1074 #region Type-level Fields 1075 #endregion 1076 1077 #region Instance Fields 1078 readonly System.Collections.Generic.SortedSet<TKey> Value; 1079 #endregion 1080 1081 #region Type-level Properties 1082 #endregion 1083 1084 #region Instance Properties 1085 public readonly bool IsEmpty => Len == uint.MinValue; 1086 public readonly uint Len => (uint)Value.Count; 1087 #endregion 1088 1089 #region Type-level Functions 1090 public static SortedSet<TKey> New() => new(); 1091 #endregion 1092 1093 #region Instance Functions 1094 public readonly Unit Append(SortedSet<TKey> other) { 1095 1096 using var enumer = other.Value.GetEnumerator(); 1097 TKey key; 1098 while (enumer.MoveNext()) { 1099 key = enumer.Current; 1100 _ = Insert(key); 1101 } 1102 return other.Clear(); 1103 } 1104 public readonly Unit Clear() { 1105 1106 Value.Clear(); 1107 return new Unit(); 1108 } 1109 public readonly bool Contains(in TKey key) => Value.Contains(key); 1110 public override readonly bool Equals(object? _) => false; 1111 public readonly Maybe<TKey> Get(in TKey key) => Value.TryGetValue(key, out var val) ? new(val) : Maybe<TKey>.None(); 1112 public readonly TKey GetOrInsert(TKey key) { 1113 1114 var val = Get(in key); 1115 if (val.IsSome) { 1116 return val.Unwrap(); 1117 } else { 1118 _ = Insert(key); 1119 return key; 1120 } 1121 } 1122 public readonly TKey GetOrInsertWith(TKey key, Fn<TKey> f) { 1123 1124 var val = Get(in key); 1125 if (val.IsSome) { 1126 return val.Unwrap(); 1127 } else { 1128 var v = f(); 1129 _ = Insert(v); 1130 return v; 1131 } 1132 } 1133 public override readonly int GetHashCode() => 0; 1134 public readonly bool Insert(TKey key) => Value.Add(key); 1135 public readonly SortedSet<TKey> Into() => this; 1136 public readonly IntoIter<TKey> IntoIter() => new(Value); 1137 public readonly bool Remove(in TKey key) => Value.Remove(key); 1138 public readonly Maybe<TKey> Replace(TKey key) { 1139 1140 var val = Get(in key); 1141 _ = Remove(in key); 1142 return Insert(key) ? val : throw new InvalidOperationException($"Unable to replace {key.ToString()}."); 1143 } 1144 public override readonly string ToString() => string.Empty; 1145 readonly Result<SortedSet<TKey>, Bottom> ITryInto<SortedSet<TKey>, Bottom>.TryInto() => new(this); 1146 #endregion 1147 1148 #region Operators 1149 #endregion 1150 1151 #region Types 1152 #endregion 1153 } 1154 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 0)] 1155 public struct IntoIter<TKey>: IDisposable, IExactSizeIterator<TKey>, IFusedIterator<TKey>, IInto<IntoIter<TKey>> where TKey: notnull, IOrd<TKey> { 1156 1157 #region Type-level Constructors 1158 #endregion 1159 1160 #region Instance Constructors 1161 public IntoIter() => throw new InvalidOperationException("Parameterless constructor is not allowed to be called!"); 1162 internal IntoIter(System.Collections.Generic.SortedSet<TKey> set) => (_enumer, _index, _count) = (set.GetEnumerator(), uint.MinValue, (uint)set.Count); 1163 #endregion 1164 1165 #region Type-level Fields 1166 #endregion 1167 1168 #region Instance Fields 1169 System.Collections.Generic.SortedSet<TKey>.Enumerator _enumer; 1170 uint _index; 1171 readonly uint _count; 1172 #endregion 1173 1174 #region Type-level Properties 1175 #endregion 1176 1177 #region Instance Properties 1178 #endregion 1179 1180 #region Type-level Functions 1181 #endregion 1182 1183 #region Instance Functions 1184 public void Dispose() => _enumer.Dispose(); 1185 public Result<Unit, ulong> AdvanceBy(ulong n) { 1186 1187 if (n == ulong.MinValue) { 1188 return new(new Unit()); 1189 } else { 1190 var val = Len(); 1191 1192 if (n > val) { 1193 _index = _count; 1194 return new(val); 1195 } else { 1196 _index += (uint)n; 1197 for (var i = uint.MinValue; i < (uint)n; i++) { _ = _enumer.MoveNext(); } 1198 return new(new Unit()); 1199 } 1200 } 1201 } 1202 public readonly ulong Count() => Len(); 1203 public override readonly bool Equals(object? _) => false; 1204 public TInit Fold<TInit>(TInit init, Fn<TInit, TKey, TInit> f) where TInit: notnull { 1205 1206 TKey key; 1207 while (_index < _count) { 1208 _index++; 1209 _ = _enumer.MoveNext(); 1210 key = _enumer.Current; 1211 init = f(init, key); 1212 } 1213 return init; 1214 } 1215 public override readonly int GetHashCode() => 0; 1216 public readonly IntoIter<TKey> Into() => this; 1217 public readonly bool IsEmpty() => Len() == ulong.MinValue; 1218 public Maybe<TKey> Last() => IIterator<TKey>.LastDefault<IntoIter<TKey>>(ref this); 1219 public readonly ulong Len() => _count - _index; 1220 public Maybe<TKey> Next() { 1221 1222 if (_index < _count) { 1223 _index++; 1224 _ = _enumer.MoveNext(); 1225 var cur = _enumer.Current; 1226 return new(cur); 1227 } else { 1228 return Maybe<TKey>.None(); 1229 } 1230 } 1231 public readonly Prod<ulong, Maybe<ulong>> SizeHint() => new(Len(), new(Len())); 1232 public override readonly string ToString() => string.Empty; 1233 public Result<TInit, TErr> TryFold<TInit, TErr>(TInit init, Fn<TInit, TKey, Result<TInit, TErr>> f) where TInit: notnull where TErr: notnull { 1234 1235 TKey key; 1236 Result<TInit, TErr> res; 1237 1238 while (_index < _count) { 1239 _index++; 1240 _ = _enumer.MoveNext(); 1241 key = _enumer.Current; 1242 res = f(init, key); 1243 1244 if (res.IsErr) { 1245 return res; 1246 } else { 1247 init = res._ok; 1248 } 1249 } 1250 return new(init); 1251 } 1252 readonly Result<IntoIter<TKey>, Bottom> ITryInto<IntoIter<TKey>, Bottom>.TryInto() => new(this); 1253 #endregion 1254 1255 #region Operators 1256 #endregion 1257 1258 #region Types 1259 #endregion 1260 } 1261 #endregion 1262 1263 #region Namespaces 1264 #endregion 1265 } 1266 #endregion 1267 } 1268 #endregion