|
|
|
|
@ -17,6 +17,7 @@ function input(): string;
|
|
|
|
|
|
|
|
|
|
function input(s: string): string;
|
|
|
|
|
|
|
|
|
|
///-
|
|
|
|
|
type kwargs_gen<T> = class
|
|
|
|
|
public !kwargs: Dictionary<string, T>
|
|
|
|
|
:= new Dictionary<string, T>();
|
|
|
|
|
@ -50,10 +51,6 @@ function filter<T>(cond: T -> boolean; s: sequence of T): sequence of T;
|
|
|
|
|
function sorted<T>(s: sequence of T; reverse: boolean := false): sequence of T;
|
|
|
|
|
function sorted<T,T1>(s: sequence of T; key: T -> T1; reverse: boolean := false): sequence of T;
|
|
|
|
|
|
|
|
|
|
function __NewSetCreatorInternal<T>(params a: array of T): NewSet<T>;
|
|
|
|
|
|
|
|
|
|
procedure clear<T>(var st: set of T);
|
|
|
|
|
|
|
|
|
|
function int(val: string): integer;
|
|
|
|
|
|
|
|
|
|
function int(val: real): integer;
|
|
|
|
|
@ -102,18 +99,395 @@ function abs(x: real): real;
|
|
|
|
|
|
|
|
|
|
// function floor(x: real): real;
|
|
|
|
|
|
|
|
|
|
type list<T> = class(IEnumerable<T>)
|
|
|
|
|
private
|
|
|
|
|
wrappee : PABCSystem.List<T>;
|
|
|
|
|
|
|
|
|
|
constructor Create(l : PABCSystem.List<T>) := wrappee := l;
|
|
|
|
|
|
|
|
|
|
function GetItem(ind : integer) : T := wrappee[ind];
|
|
|
|
|
|
|
|
|
|
procedure SetItem(ind : integer; newItem : T) := wrappee[ind] := newItem;
|
|
|
|
|
|
|
|
|
|
public
|
|
|
|
|
|
|
|
|
|
static function operator implicit(l : PABCSystem.List<T>) : list<T> := new list<T>(l);
|
|
|
|
|
|
|
|
|
|
constructor Create() := wrappee := new PABCSystem.List<T>();
|
|
|
|
|
|
|
|
|
|
constructor Create(capacity : integer) := wrappee := new PABCSystem.List<T>(capacity);
|
|
|
|
|
|
|
|
|
|
constructor Create(collection : sequence of T) := wrappee := new PABCSystem.List<T>(collection);
|
|
|
|
|
|
|
|
|
|
property ByIndex[ind : integer] : T read GetItem write SetItem; default;
|
|
|
|
|
|
|
|
|
|
///--
|
|
|
|
|
property !count : integer read wrappee.Count;
|
|
|
|
|
|
|
|
|
|
procedure append(item : T) := wrappee.Add(item);
|
|
|
|
|
|
|
|
|
|
procedure extend(seq : sequence of T) := wrappee.AddRange(seq);
|
|
|
|
|
|
|
|
|
|
procedure clear() := wrappee.Clear();
|
|
|
|
|
|
|
|
|
|
procedure insert(index : integer; item : T) := wrappee.Insert(index, item);
|
|
|
|
|
|
|
|
|
|
procedure remove(item : T);
|
|
|
|
|
begin
|
|
|
|
|
if not wrappee.Remove(item) then
|
|
|
|
|
raise new System.ArgumentException($'ValueError: {item} is not in list');
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function pop() : T;
|
|
|
|
|
begin
|
|
|
|
|
var lastIndex := wrappee.Count - 1;
|
|
|
|
|
Result := wrappee[lastIndex];
|
|
|
|
|
wrappee.RemoveAt(lastIndex);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function pop(index : integer) : T;
|
|
|
|
|
begin
|
|
|
|
|
Result := wrappee[index];
|
|
|
|
|
wrappee.RemoveAt(index);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function index(item : T) : integer := index(item, 0, wrappee.Count);
|
|
|
|
|
|
|
|
|
|
function index(item : T; start : integer) : integer := index(item, start, wrappee.Count);
|
|
|
|
|
|
|
|
|
|
function index(item : T; start : integer; &end : integer) : integer;
|
|
|
|
|
begin
|
|
|
|
|
Result := wrappee.IndexOf(item, start, &end - start);
|
|
|
|
|
if Result = -1 then
|
|
|
|
|
raise new System.ArgumentException($'ValueError: {item} is not in list');
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function count(item : T) : integer;
|
|
|
|
|
begin
|
|
|
|
|
var comparer := System.Collections.Generic.EqualityComparer&<T>.Default;
|
|
|
|
|
|
|
|
|
|
Result := 0;
|
|
|
|
|
for var i := 0 to wrappee.Count - 1 do
|
|
|
|
|
begin
|
|
|
|
|
if comparer.Equals(wrappee[i], item) then
|
|
|
|
|
Result += 1;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure sort() := wrappee.Sort();
|
|
|
|
|
|
|
|
|
|
procedure sort(reverse : boolean) := wrappee.OrderByDescending(x -> x);
|
|
|
|
|
|
|
|
|
|
procedure sort<TKey>(key : T -> TKey) := wrappee.OrderBy(key);
|
|
|
|
|
|
|
|
|
|
procedure sort<TKey>(key : T -> TKey; reverse : boolean) := wrappee.OrderByDescending(key);
|
|
|
|
|
|
|
|
|
|
procedure reverse() := wrappee.Reverse();
|
|
|
|
|
|
|
|
|
|
function copy() : list<T> := new list<T>(wrappee.ToList());
|
|
|
|
|
|
|
|
|
|
function GetEnumerator() : IEnumerator<T> := wrappee.GetEnumerator();
|
|
|
|
|
|
|
|
|
|
function System.Collections.IEnumerable.GetEnumerator() : System.Collections.IEnumerator := GetEnumerator();
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
type &set<T> = record(IEnumerable<T>)
|
|
|
|
|
private
|
|
|
|
|
wrappee : PABCSystem.HashSet<T>;
|
|
|
|
|
|
|
|
|
|
constructor Create(h : PABCSystem.HashSet<T>) := wrappee := h;
|
|
|
|
|
|
|
|
|
|
public
|
|
|
|
|
|
|
|
|
|
constructor Create() := wrappee := new PABCSystem.HashSet<T>();
|
|
|
|
|
|
|
|
|
|
constructor Create(collection : sequence of T) := wrappee := new PABCSystem.HashSet<T>(collection);
|
|
|
|
|
|
|
|
|
|
constructor Create(collection : sequence of T; comparer : PABCSystem.IEqualityComparer<T>) := wrappee := new PABCSystem.HashSet<T>(collection, comparer);
|
|
|
|
|
|
|
|
|
|
constructor Create(comparer : PABCSystem.IEqualityComparer<T>) := wrappee := new PABCSystem.HashSet<T>(comparer);
|
|
|
|
|
|
|
|
|
|
///--
|
|
|
|
|
property !count : integer read wrappee.Count;
|
|
|
|
|
|
|
|
|
|
procedure add(elem : T) := wrappee.Add(elem);
|
|
|
|
|
|
|
|
|
|
procedure remove(elem : T);
|
|
|
|
|
begin
|
|
|
|
|
if not wrappee.Remove(elem) then
|
|
|
|
|
raise new System.Collections.Generic.KeyNotFoundException('KeyError: ' + elem.ToString());
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure discard(elem : T) := wrappee.Remove(elem);
|
|
|
|
|
|
|
|
|
|
function pop() : T;
|
|
|
|
|
begin
|
|
|
|
|
if wrappee.Count = 0 then
|
|
|
|
|
raise new System.Collections.Generic.KeyNotFoundException('KeyError: ''pop from an empty set''');
|
|
|
|
|
|
|
|
|
|
Result := wrappee.First();
|
|
|
|
|
wrappee.Remove(Result);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure clear() := wrappee.Clear();
|
|
|
|
|
|
|
|
|
|
function copy() : &set<T> := new &set<T>(wrappee.ToHashSet());
|
|
|
|
|
|
|
|
|
|
static function operator in(elem: T; Self: &set<T>): boolean;
|
|
|
|
|
begin
|
|
|
|
|
Result := Self.wrappee.Contains(elem);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
function setOperation1(op : (HashSet<T>, sequence of T) -> (); params others : array of sequence of T) : &set<T>;
|
|
|
|
|
begin
|
|
|
|
|
Result.wrappee := wrappee.ToHashSet();
|
|
|
|
|
foreach var seq in others do
|
|
|
|
|
op(Result.wrappee, seq);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure setOperation2(op : (HashSet<T>, sequence of T) -> (); params others : array of sequence of T);
|
|
|
|
|
begin
|
|
|
|
|
foreach var seq in others do
|
|
|
|
|
op(wrappee, seq);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
public
|
|
|
|
|
function intersection(params others : array of sequence of T) : &set<T> := setOperation1((h1, h2) -> h1.IntersectWith(h2), others);
|
|
|
|
|
|
|
|
|
|
function union(params others : array of sequence of T) : &set<T> := setOperation1((h1, h2) -> h1.UnionWith(h2), others);
|
|
|
|
|
|
|
|
|
|
function difference(params others : array of sequence of T) : &set<T> := setOperation1((h1, h2) -> h1.ExceptWith(h2), others);
|
|
|
|
|
|
|
|
|
|
function symmetric_difference(params others : array of sequence of T) : &set<T> := setOperation1((h1, h2) -> h1.SymmetricExceptWith(h2), others);
|
|
|
|
|
|
|
|
|
|
procedure update(params others : array of sequence of T) := setOperation2((h1, h2) -> h1.UnionWith(h2), others);
|
|
|
|
|
|
|
|
|
|
procedure update(other : sequence of T) := wrappee.UnionWith(other);
|
|
|
|
|
|
|
|
|
|
procedure intersection_update(params others : array of sequence of T) := setOperation2((h1, h2) -> h1.IntersectWith(h2), others);
|
|
|
|
|
|
|
|
|
|
procedure intersection_update(other : sequence of T) := wrappee.IntersectWith(other);
|
|
|
|
|
|
|
|
|
|
procedure difference_update(params others : array of sequence of T) := setOperation2((h1, h2) -> h1.ExceptWith(h2), others);
|
|
|
|
|
|
|
|
|
|
procedure difference_update(other : sequence of T) := wrappee.ExceptWith(other);
|
|
|
|
|
|
|
|
|
|
procedure symmetric_difference_update(params others : array of sequence of T) := setOperation2((h1, h2) -> h1.SymmetricExceptWith(h2), others);
|
|
|
|
|
|
|
|
|
|
procedure symmetric_difference_update(other : sequence of T) := wrappee.SymmetricExceptWith(other);
|
|
|
|
|
|
|
|
|
|
function isdisjoint(other : sequence of T) : boolean;
|
|
|
|
|
|
|
|
|
|
function issubset(other : sequence of T) : boolean := wrappee.IsSubsetOf(other);
|
|
|
|
|
|
|
|
|
|
function issuperset(other : sequence of T) : boolean := wrappee.IsSupersetOf(other);
|
|
|
|
|
|
|
|
|
|
static function operator=(s1 : &set<T>; s2 : &set<T>) : boolean := s1.wrappee.SetEquals(s2.wrappee);
|
|
|
|
|
|
|
|
|
|
static function operator<>(s1 : &set<T>; s2 : &set<T>) : boolean := not (s1 = s2);
|
|
|
|
|
|
|
|
|
|
static function operator<=(s1 : &set<T>; s2 : &set<T>) : boolean := s1.issubset(s2);
|
|
|
|
|
|
|
|
|
|
static function operator<(s1 : &set<T>; s2 : &set<T>) : boolean := (s1 <= s2) and (s1 <> s2);
|
|
|
|
|
|
|
|
|
|
static function operator>=(s1 : &set<T>; s2 : &set<T>) : boolean := s1.issuperset(s2);
|
|
|
|
|
|
|
|
|
|
static function operator>(s1 : &set<T>; s2 : &set<T>) : boolean := (s1 >= s2) and (s1 <> s2);
|
|
|
|
|
|
|
|
|
|
static function operator or(s1 : &set<T>; s2 : &set<T>) : &set<T> := s1.union(s2);
|
|
|
|
|
|
|
|
|
|
///-
|
|
|
|
|
function !orEqual(other : &set<T>) : &set<T>;
|
|
|
|
|
begin
|
|
|
|
|
update(other);
|
|
|
|
|
Result := Self;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
static function operator and(s1 : &set<T>; s2 : &set<T>) : &set<T> := s1.intersection(s2);
|
|
|
|
|
|
|
|
|
|
///-
|
|
|
|
|
function !andEqual(other : &set<T>) : &set<T>;
|
|
|
|
|
begin
|
|
|
|
|
intersection_update(other);
|
|
|
|
|
Result := Self;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
static function operator-(s1 : &set<T>; s2 : &set<T>) : &set<T> := s1.difference(s2);
|
|
|
|
|
|
|
|
|
|
static function operator -=(var s1 : &set<T>; s2 : &set<T>) : &set<T>;
|
|
|
|
|
begin
|
|
|
|
|
s1.difference_update(s2);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
static function operator xor(s1 : &set<T>; s2 : &set<T>) : &set<T> := s1.symmetric_difference(s2);
|
|
|
|
|
|
|
|
|
|
///-
|
|
|
|
|
function !xorEqual(other : &set<T>) : &set<T>;
|
|
|
|
|
begin
|
|
|
|
|
symmetric_difference_update(other);
|
|
|
|
|
Result := Self;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
// static function operator:=(var s1: &set<T>; s2: &set<T>): &set<T>;
|
|
|
|
|
// begin
|
|
|
|
|
// s1.wrappee := s2.wrappee.ToHashSet();
|
|
|
|
|
// end;
|
|
|
|
|
|
|
|
|
|
static function operator implicit(s : HashSet<T>) : &set<T> := new &set<T>(s);
|
|
|
|
|
|
|
|
|
|
function GetEnumerator() : IEnumerator<T> := wrappee.GetEnumerator();
|
|
|
|
|
|
|
|
|
|
function System.Collections.IEnumerable.GetEnumerator() : System.Collections.IEnumerator := GetEnumerator();
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
type dict<K, V> = class(IEnumerable<PABCSystem.KeyValuePair<K, V>>)
|
|
|
|
|
private
|
|
|
|
|
wrappee : PABCSystem.Dictionary<K, V>;
|
|
|
|
|
|
|
|
|
|
constructor Create(d : PABCSystem.Dictionary<K, V>) := wrappee := d;
|
|
|
|
|
|
|
|
|
|
function GetValue(key : K) : V := wrappee[key];
|
|
|
|
|
|
|
|
|
|
procedure SetValue(key : K; val : V) := wrappee[key] := val;
|
|
|
|
|
|
|
|
|
|
public
|
|
|
|
|
|
|
|
|
|
constructor Create() := wrappee := new PABCSystem.Dictionary<K, V>();
|
|
|
|
|
|
|
|
|
|
constructor Create(capacity : integer) := wrappee := new PABCSystem.Dictionary<K, V>(capacity);
|
|
|
|
|
|
|
|
|
|
constructor Create(comparer : PABCSystem.IEqualityComparer<K>) := wrappee := new PABCSystem.Dictionary<K, V>(comparer);
|
|
|
|
|
|
|
|
|
|
constructor Create(capacity : integer; comparer : PABCSystem.IEqualityComparer<K>) := wrappee := new PABCSystem.Dictionary<K, V>(capacity, comparer);
|
|
|
|
|
|
|
|
|
|
constructor Create(params pairs: array of (K, V));
|
|
|
|
|
begin
|
|
|
|
|
wrappee := new PABCSystem.Dictionary<K, V>();
|
|
|
|
|
|
|
|
|
|
for var i := 0 to pairs.Length - 1 do
|
|
|
|
|
wrappee[pairs[i].Item1] := pairs[i].Item2;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
constructor Create(seqOfPairs : sequence of (K, V));
|
|
|
|
|
begin
|
|
|
|
|
wrappee := new PABCSystem.Dictionary<K, V>();
|
|
|
|
|
|
|
|
|
|
foreach var p in seqOfPairs do
|
|
|
|
|
wrappee[p.Item1] := p.Item2;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
///--
|
|
|
|
|
property !count : integer read wrappee.Count;
|
|
|
|
|
|
|
|
|
|
property ByKey[key : K] : V read GetValue write SetValue; default;
|
|
|
|
|
|
|
|
|
|
static function operator in(key: K; Self: dict<K, V>): boolean;
|
|
|
|
|
begin
|
|
|
|
|
Result := Self.wrappee.ContainsKey(key);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure clear() := wrappee.Clear();
|
|
|
|
|
|
|
|
|
|
function copy() : dict<K, V> := new dict<K, V>(new Dictionary<K,V>(wrappee));
|
|
|
|
|
|
|
|
|
|
static function fromkeys(sq : sequence of K; val : V := default(V)) : dict<K, V>;
|
|
|
|
|
begin
|
|
|
|
|
Result := new dict<K, V>();
|
|
|
|
|
|
|
|
|
|
foreach var key in sq do
|
|
|
|
|
Result[key] := val;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function get(key : K; &default : V := default(V)) : V;
|
|
|
|
|
begin
|
|
|
|
|
var val : V;
|
|
|
|
|
if wrappee.TryGetValue(key, val) then
|
|
|
|
|
Result := val
|
|
|
|
|
else
|
|
|
|
|
Result := &default;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function items() : sequence of KeyValuePair<K, V> := wrappee;
|
|
|
|
|
|
|
|
|
|
function keys() := wrappee.Keys;
|
|
|
|
|
|
|
|
|
|
function pop(key : K) : V;
|
|
|
|
|
begin
|
|
|
|
|
Result := wrappee[key];
|
|
|
|
|
wrappee.Remove(key);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function pop(key : K; &default : V) : V;
|
|
|
|
|
begin
|
|
|
|
|
var val : V;
|
|
|
|
|
if wrappee.TryGetValue(key, val) then
|
|
|
|
|
begin
|
|
|
|
|
Result := val;
|
|
|
|
|
wrappee.Remove(key);
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
Result := &default;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function popitem() : KeyValuePair<K, V>;
|
|
|
|
|
begin
|
|
|
|
|
Result := wrappee.Last();
|
|
|
|
|
wrappee.Remove(Result.Key);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function setdefault(key : K; &default : V := default(V)) : V;
|
|
|
|
|
begin
|
|
|
|
|
var val : V;
|
|
|
|
|
if wrappee.TryGetValue(key, val) then
|
|
|
|
|
Result := val
|
|
|
|
|
else
|
|
|
|
|
begin
|
|
|
|
|
wrappee[key] := &default;
|
|
|
|
|
Result := &default;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure update(params pairs: array of (K, V));
|
|
|
|
|
begin
|
|
|
|
|
for var i := 0 to pairs.Length - 1 do
|
|
|
|
|
wrappee[pairs[i].Item1] := pairs[i].Item2;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure update(seqOfPairs : sequence of (K, V));
|
|
|
|
|
begin
|
|
|
|
|
foreach var p in seqOfPairs do
|
|
|
|
|
wrappee[p.Item1] := p.Item2;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function values() := wrappee.Values;
|
|
|
|
|
|
|
|
|
|
static function operator or(d1 : dict<K, V>; d2 : dict<K, V>) : dict<K, V>;
|
|
|
|
|
begin
|
|
|
|
|
Result := new dict<K, V>(d1.wrappee);
|
|
|
|
|
|
|
|
|
|
foreach var p in d2.wrappee do
|
|
|
|
|
Result[p.Key] := p.Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
static function operator implicit(d : PABCSystem.Dictionary<K, V>) : dict<K, V> := new dict<K, V>(d);
|
|
|
|
|
|
|
|
|
|
function GetEnumerator() : IEnumerator<KeyValuePair<K, V>> := wrappee.GetEnumerator();
|
|
|
|
|
|
|
|
|
|
function System.Collections.IEnumerable.GetEnumerator() : System.Collections.IEnumerator := GetEnumerator();
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
//Standard functions with Lists
|
|
|
|
|
|
|
|
|
|
function len<T>(lst: PABCSystem.List<T>): integer;
|
|
|
|
|
function len<T>(st: set of T): integer;
|
|
|
|
|
function len<K, V>(dct: PABCSystem.Dictionary<K, V>): integer;
|
|
|
|
|
function len<T>(lst: list<T>): integer;
|
|
|
|
|
function len<T>(st: &set<T>): integer;
|
|
|
|
|
function len<K, V>(dct: dict<K, V>): integer;
|
|
|
|
|
function len<T>(arr: array of T): integer;
|
|
|
|
|
function len(s: string): integer;
|
|
|
|
|
|
|
|
|
|
function &set<T>(sq: sequence of T): set of T;
|
|
|
|
|
function &list<T>(sq: sequence of T): PABCSystem.List<T>;
|
|
|
|
|
// function &set<T>(sq: sequence of T): &set<T>;
|
|
|
|
|
|
|
|
|
|
function sorted<T>(lst: PABCSystem.List<T>): PABCSystem.List<T>;
|
|
|
|
|
function sorted<T>(lst: list<T>): list<T>;
|
|
|
|
|
|
|
|
|
|
function sum(lst: sequence of integer): integer;
|
|
|
|
|
|
|
|
|
|
@ -162,14 +536,8 @@ function CreateTuple<T1, T2, T3, T4, T5, T6, T7>(
|
|
|
|
|
|
|
|
|
|
// TUPLES END
|
|
|
|
|
|
|
|
|
|
function Dict<TKey, TVal>(params pairs: array of (TKey, TVal)): Dictionary<TKey, TVal>;
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
biginteger = PABCSystem.BigInteger;
|
|
|
|
|
!list<T> = PABCSystem.List<T>;
|
|
|
|
|
!dict<K, V> = PABCSystem.Dictionary<K, V>;
|
|
|
|
|
dct<K, V> = PABCSystem.Dictionary<K, V>;
|
|
|
|
|
!set<T> = set of T;
|
|
|
|
|
tuple2<T1, T2> = System.Tuple<T1, T2>;
|
|
|
|
|
tuple3<T1, T2, T3> = System.Tuple<T1, T2, T3>;
|
|
|
|
|
tuple4<T1, T2, T3, T4> = System.Tuple<T1, T2, T3, T4>;
|
|
|
|
|
@ -178,30 +546,30 @@ type
|
|
|
|
|
tuple7<T1, T2, T3, T4, T5, T6, T7> = System.Tuple<T1, T2, T3, T4, T5, T6, T7>;
|
|
|
|
|
|
|
|
|
|
empty_list = class
|
|
|
|
|
class function operator implicit<T>(x: empty_list): !list<T>;
|
|
|
|
|
class function operator implicit<T>(x: empty_list): list<T>;
|
|
|
|
|
begin
|
|
|
|
|
Result := new !list<T>();
|
|
|
|
|
Result := new list<T>();
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
empty_set = class
|
|
|
|
|
class function operator implicit<T>(x: empty_set): !set<T>;
|
|
|
|
|
class function operator implicit<T>(x: empty_set): &set<T>;
|
|
|
|
|
begin
|
|
|
|
|
Result := new !set<T>;
|
|
|
|
|
Result := new &set<T>();
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
empty_dict = class
|
|
|
|
|
class function operator implicit<K, V>(x: empty_dict): !dict<K, V>;
|
|
|
|
|
class function operator implicit<K, V>(x: empty_dict): dict<K, V>;
|
|
|
|
|
begin
|
|
|
|
|
Result := new !dict<K, V>();
|
|
|
|
|
Result := new dict<K, V>();
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function !empty_list(): empty_list;
|
|
|
|
|
function !empty_dict(): empty_dict;
|
|
|
|
|
function &set(): empty_set;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
@ -246,8 +614,6 @@ begin
|
|
|
|
|
Result := TypeName(obj)
|
|
|
|
|
.Replace('<', '[')
|
|
|
|
|
.Replace('>', ']')
|
|
|
|
|
.Replace('List', 'list')
|
|
|
|
|
.Replace('Dictionary', 'dict')
|
|
|
|
|
.Replace('empty_list', 'list[anytype]')
|
|
|
|
|
.Replace('empty_set', 'set[anytype]')
|
|
|
|
|
.Replace('empty_dict', 'dict[anytype]')
|
|
|
|
|
@ -289,17 +655,17 @@ function abs(x: integer): integer := if x >= 0 then x else -x;
|
|
|
|
|
|
|
|
|
|
function abs(x: real): real := PABCSystem.Abs(x);
|
|
|
|
|
|
|
|
|
|
function len<T>(lst: PABCSystem.List<T>): integer := lst.Count();
|
|
|
|
|
function len<T>(st: set of T): integer := st.Count();
|
|
|
|
|
function len<K, V>(dct: PABCSystem.Dictionary<K, V>): integer := dct.Count();
|
|
|
|
|
function len<T>(arr: array of T): integer := arr.Count();
|
|
|
|
|
function len<T>(lst: list<T>): integer := lst.!count;
|
|
|
|
|
function len<T>(st: &set<T>): integer := st.!count;
|
|
|
|
|
function len<K, V>(dct: dict<K, V>): integer := dct.!count;
|
|
|
|
|
function len<T>(arr: array of T): integer := arr.Length;
|
|
|
|
|
function len(s: string): integer := s.Length;
|
|
|
|
|
|
|
|
|
|
function sorted<T>(lst: PABCSystem.List<T>): PABCSystem.List<T>;
|
|
|
|
|
function sorted<T>(lst: list<T>): list<T>;
|
|
|
|
|
begin
|
|
|
|
|
var new_list := new PABCSystem.List<T>(lst);
|
|
|
|
|
new_list.sort();
|
|
|
|
|
Result := new_list;
|
|
|
|
|
var newList := lst.copy();
|
|
|
|
|
newList.sort();
|
|
|
|
|
Result := newList;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function sum(lst: sequence of integer): integer := lst.sum();
|
|
|
|
|
@ -360,49 +726,32 @@ begin
|
|
|
|
|
Result := x;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function !count<T>(Self: PABCSystem.List<T>; val: T): integer; extensionmethod;
|
|
|
|
|
function &set<T>.isdisjoint(other : sequence of T) : boolean;
|
|
|
|
|
begin
|
|
|
|
|
Result := 0;
|
|
|
|
|
for var i := 0 to Self.Count - 1 do
|
|
|
|
|
if val = Self[i] then
|
|
|
|
|
Result += 1;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function pop<T>(Self: PABCSystem.List<T>; ind: integer): T; extensionmethod;
|
|
|
|
|
begin
|
|
|
|
|
Result := Self[ind];
|
|
|
|
|
Self.RemoveAt(ind);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure add<T>(Self: set of T; val: T); extensionmethod;
|
|
|
|
|
begin
|
|
|
|
|
Self += val;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure remove<T>(Self: set of T; val: T); extensionmethod;
|
|
|
|
|
begin
|
|
|
|
|
Self -= val;
|
|
|
|
|
if other = nil then
|
|
|
|
|
raise new System.ArgumentNullException('other', 'Null object is not iterable');
|
|
|
|
|
|
|
|
|
|
var c1 := wrappee.Count;
|
|
|
|
|
var c2 := other.Count();
|
|
|
|
|
|
|
|
|
|
if (c1 = 0) or (c2 = 0) then
|
|
|
|
|
Result := true
|
|
|
|
|
else
|
|
|
|
|
begin
|
|
|
|
|
if c1 >= c2 then
|
|
|
|
|
Result := other.All(elem -> not wrappee.Contains(elem))
|
|
|
|
|
else
|
|
|
|
|
begin
|
|
|
|
|
var otherSet := new HashSet<T>(other);
|
|
|
|
|
Result := wrappee.All(elem -> not otherSet.Contains(elem));
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function get_keys<K, V>(dct: Dictionary<K, V>):= dct.keys;
|
|
|
|
|
function get_values<K, V>(dct: Dictionary<K, V>):= dct.values;
|
|
|
|
|
|
|
|
|
|
function copy<T>(Self: set of T): set of T; extensionmethod;
|
|
|
|
|
begin
|
|
|
|
|
Result := Self;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure clear<T>(var st: set of T);
|
|
|
|
|
begin
|
|
|
|
|
st := [];
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function __NewSetCreatorInternal<T>(params a: array of T): NewSet<T>;
|
|
|
|
|
begin
|
|
|
|
|
//Result._hs := new HashSet<T>;
|
|
|
|
|
Result._hs.UnionWith(a);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
// TUPLES BEGIN
|
|
|
|
|
function CreateTuple<T1, T2>(
|
|
|
|
|
v1: T1; v2: T2
|
|
|
|
|
@ -436,20 +785,10 @@ function CreateTuple<T1, T2, T3, T4, T5, T6, T7>(
|
|
|
|
|
|
|
|
|
|
// TUPLES END
|
|
|
|
|
|
|
|
|
|
function Dict<TKey, TVal>(params pairs: array of (TKey, TVal)): Dictionary<TKey, TVal>;
|
|
|
|
|
begin
|
|
|
|
|
Result := new Dictionary<TKey, TVal>();
|
|
|
|
|
for var i := 0 to pairs.Length - 1 do
|
|
|
|
|
Result.Add(pairs[i][0], pairs[i][1]);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function &set<T>(sq: sequence of T): set of T;
|
|
|
|
|
begin
|
|
|
|
|
foreach var e in sq do
|
|
|
|
|
Result.Add(e);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function &list<T>(sq: sequence of T): PABCSystem.List<T> := sq.ToList();
|
|
|
|
|
//function &set<T>(sq: sequence of T): &set<T>;
|
|
|
|
|
//begin
|
|
|
|
|
// Result := new &set<T>(sq);
|
|
|
|
|
//end;
|
|
|
|
|
|
|
|
|
|
function all(s: sequence of boolean): boolean;
|
|
|
|
|
begin
|
|
|
|
|
@ -473,14 +812,15 @@ begin
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function ToDictionary<T, U>(Self: sequence of System.tuple<T, U>): Dictionary<T, U>; extensionmethod;
|
|
|
|
|
///-
|
|
|
|
|
function ToDictionary<T, U>(Self: sequence of System.Tuple<T, U>): dict<T, U>; extensionmethod;
|
|
|
|
|
begin
|
|
|
|
|
Result := Self.ToDictionary(x->x[0],x->x[1]);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function !empty_list(): empty_list := new empty_list();
|
|
|
|
|
function !empty_dict(): empty_dict := new empty_dict();
|
|
|
|
|
function &set(): empty_set := new empty_set;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function round(val: real): integer := PABCSystem.round(val);
|
|
|
|
|
|
|
|
|
|
|