diff --git a/Tools.cs b/Tools.cs index 8f1bea8..b6ecd1e 100644 --- a/Tools.cs +++ b/Tools.cs @@ -212,6 +212,21 @@ namespace LibZNI } } + public static class LinqExtensions + { + public static string ReplaceAtIndex(this string a, int b, string c) + { + string sSplice = ""; + if(b == 0) + { + sSplice = $"{c}{a.Substring(1)}"; + }else + { + sSplice = $"{a.Substring(0,b)}{c}{a.Substring(b+1)}"; + } + return sSplice; + } + } public static class ZNILSLTools { diff --git a/ZMap.cs b/ZMap.cs new file mode 100644 index 0000000..1dfee7f --- /dev/null +++ b/ZMap.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LibZNI +{ + public class VectorList : IComparable + { + public T Key { get; set; } + public T2 Key2 { get; set; } + public V Value { get; set; } + + public VectorList(T x, T2 b, V c) + { + Key = x; + Key2 = b; + Value = c; + } + + public int CompareTo(object obj) + { + if(obj == null) + { + return -1; + } + VectorList _other = obj as VectorList; + if (Key.Equals(_other.Key)) + { + if (Key2.Equals(_other.Key2)) + { + if (Value.Equals(_other.Value)) + { + return 0; + } + } + } + return 1; + } + } + public class ZMap : IEnumerable> + { + public List> _list = new List>(); + public void Add(VectorList item) + { + if(!_list.Contains(item)) + _list.Add(item); + } + public void Remove(VectorList item) + { + _list.Remove(item); + } + + public V GetEntry(T a, T2 b) + { + try + { + return _list.First(x => x.Key.Equals(a) && x.Key2.Equals(b)).Value; + + } + catch + { + return default(V); + } + } + + public T2 GetK2(T a , V b) + { + try + { + return _list.First(x => x.Key.Equals(a) && x.Value.Equals(b)).Key2; + }catch + { + return default(T2); + } + } + + public IEnumerator> GetEnumerator() + { + return _list.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } +}