public static HMap <A, HMap <B, HMap <C, T> > > AddOrUpdate <A, B, C, T>(this HMap <A, HMap <B, HMap <C, T> > > self, A aKey, B bKey, C cKey, Func <T, T> Some, Func <T> None) => self.AddOrUpdate( aKey, bKey, c => c.AddOrUpdate(cKey, Some, None), () => Prelude.HashMap(Tuple(cKey, None())) );
public static HMap <A, HMap <B, HMap <C, T> > > AddOrUpdate <A, B, C, T>(this HMap <A, HMap <B, HMap <C, T> > > self, A aKey, B bKey, C cKey, T value) => self.AddOrUpdate( aKey, bKey, c => c.AddOrUpdate(cKey, _ => value, value), () => Prelude.HashMap(Tuple(cKey, value)) );
public void SaveValue(EndianIO IO, int parentOffset) { //Go to the required offset IO.Out.BaseStream.Position = (parentOffset + IdentData.Offset) - 12; //Get new ident-tag index if (cmbxName.Text != "<<null>>") { //Get the index using the tagname and class int index = HMap.GetTagIndexByClassAndName(cmbxClass.Text, cmbxName.Text); //If the index is null... if (index == -1) { goto WriteNullIdent; } //Write the tagref IO.Out.WriteAsciiString(HMap.IndexItems[index].Class, 4); //Skip the 8 byte gap. IO.Out.BaseStream.Position += 8; //Write the ident IO.Out.Write(HMap.IndexItems[index].Ident); //Returned return; } //Otherwise... WriteNullIdent: ; //Jump to the ident offset IO.Out.BaseStream.Position += 12; //Write the ident IO.Out.Write(-1); }
public static R Find <A, B, C, D, T, R>(this HMap <A, HMap <B, HMap <C, HMap <D, T> > > > self, A aKey, B bKey, C cKey, D dKey, Func <T, R> Some, Func <R> None) => self.Find(aKey, b => b.Find(bKey, c => c.Find(cKey, d => d.Find(dKey, Some, None), None), None), None);
/// <summary> /// Atomically iterate through all key/value pairs in the map (in order) and execute an /// action on each /// </summary> /// <param name="action">Action to execute</param> /// <returns>Unit</returns> public static Unit Iter <K, V>(this HMap <K, V> self, Action <KeyValuePair <K, V> > action) { foreach (var item in self) { action(new KeyValuePair <K, V>(item.Key, item.Value)); } return(unit); }
/// <summary> /// Atomically iterate through all values in the map (in order) and execute an /// action on each /// </summary> /// <param name="action">Action to execute</param> /// <returns>Unit</returns> public static Unit Iter <K, V>(this HMap <K, V> self, Action <V> action) { foreach (var item in self) { action(item.Value); } return(unit); }
public virtual void PaintMap(string map) { _paints.Clear(); _rows = HMap.Adjust(map).Split(new[] { '\r' }, StringSplitOptions.RemoveEmptyEntries); Invalidate(); }
/// <summary> /// Return true if *any* items in the map return true when the predicate is applied /// </summary> /// <param name="pred">Predicate</param> /// <returns>True if all items in the map return true when the predicate is applied</returns> public static bool Exists <K, V>(this HMap <K, V> self, Func <K, V, bool> pred) { foreach (var item in self.AsEnumerable()) { if (pred(item.Key, item.Value)) { return(true); } } return(false); }
public static HMap <A, HMap <B, HMap <C, V> > > TrySetItemT <A, B, C, V>(this HMap <A, HMap <B, HMap <C, V> > > map, A aKey, B bKey, C cKey, Func <V, V> Some) { var a = map.Find(aKey); if (a.IsNone) { return(map); } var av = a.Value; return(map.SetItem(aKey, av.TrySetItemT(bKey, cKey, Some))); }
public static HMap <A, HMap <B, V> > TrySetItemT <A, B, V>(this HMap <A, HMap <B, V> > map, A aKey, B bKey, V value) { var a = map.Find(aKey); if (a.IsNone) { return(map); } var av = a.Value; return(map.SetItem(aKey, av.TrySetItem(bKey, value))); }
public static HMap <A, HMap <B, HMap <C, V> > > SetItemT <A, B, C, V>(this HMap <A, HMap <B, HMap <C, V> > > map, A aKey, B bKey, C cKey, Func <V, V> Some) { var a = map.Find(aKey); if (a.IsNone) { throw new ArgumentException("Key not found in Map"); } var av = a.Value; return(map.SetItem(aKey, av.SetItemT(bKey, cKey, Some))); }
public PrgState Execute(PrgState state) { Stack <MyIDictionary <MyMap> > symTbl = state.GetSymTable(); IHeap <HMap> heap = state.GetHeap(); int address = symTbl.ElementAt(0).Lookup(this.var); try { HMap h = (HMap)heap.Gett(address); h.SetAddr(address); h.SetCont(exp.Eval(symTbl, heap)); } catch (MissingMemberException e) { } return(null); }
public static HMap <A, HMap <B, T> > Remove <A, B, T>(this HMap <A, HMap <B, T> > self, A outerKey, B innerKey) { var b = self.Find(outerKey); if (b.IsSome) { var bv = b.Value.Remove(innerKey); if (bv.Count() == 0) { return(self.Remove(outerKey)); } else { return(self.SetItem(outerKey, bv)); } } else { return(self); } }
public static HMap <A, HMap <B, HMap <C, T> > > Remove <A, B, C, T>(this HMap <A, HMap <B, HMap <C, T> > > self, A aKey, B bKey, C cKey) { var b = self.Find(aKey); if (b.IsSome) { var c = b.Value.Find(bKey); if (c.IsSome) { var cv = c.Value.Remove(cKey); if (cv.Count() == 0) { var bv = b.Value.Remove(bKey); if (b.Value.Count() == 0) { return(self.Remove(aKey)); } else { return(self.SetItem(aKey, bv)); } } else { return(self.SetItem(aKey, b.Value.SetItem(bKey, cv))); } } else { return(self); } } else { return(self); } }
public RTHData.RTHDataBlock ReturnRTHDataBlock(int parentMemoryOffset) { //Initialize our RTH Data Block RTHData.RTHDataBlock RTH_Data_Block = new RTHData.RTHDataBlock(); //Set our memory offset RTH_Data_Block.Memory_Offset = (uint)(parentMemoryOffset + IdentData.Offset) - 12; //Get our class data byte[] classData = ExtraFunctions.StringToBytes(cmbxClass.Text); //Get our blank data byte[] blankData = new byte[8]; //Create our identData array byte[] identData = null; //If the value isn't null if (cmbxName.Text != "<<null>>") { //Assign our ident identData = ExtraFunctions.HexStringToBytes( HMap.IndexItems[HMap.GetTagIndexByClassAndName(cmbxClass.Text, cmbxName.Text)].Ident.ToString("X")); } else { //Otherwise, if it is, we assign a null value identData = new byte[4] { 0xFF, 0xFF, 0xFF, 0xFF }; } RTH_Data_Block.Data_Block = ExtraFunctions.HexStringToBytes(ExtraFunctions.BytesToHexString(classData) + ExtraFunctions.BytesToHexString(blankData) + ExtraFunctions.BytesToHexString(identData)); //Set our block size RTH_Data_Block.Block_Size = 16; //Return the RTH Data Block instance return(RTH_Data_Block); }
public static Map <K, V> SelectMany <K, T, U, V>(this HMap <K, T> self, Func <T, Map <K, U> > binder, Func <T, U, V> project) => failwith <Map <K, V> >("Map<K,V> doesn't support Bind or SelectMany.");
public static Map <K, U> Bind <K, T, U>(this HMap <K, T> self, Func <T, Map <K, U> > binder) => failwith <Map <K, U> >("Map<K,V> doesn't support Bind.");
public static HMap <A, HMap <B, T> > AddOrUpdate <A, B, T>(this HMap <A, HMap <B, T> > self, A outerKey, B innerKey, T value) => self.AddOrUpdate( outerKey, b => b.AddOrUpdate(innerKey, _ => value, value), () => Prelude.HashMap(Tuple(innerKey, value)) );
public static HMap <A, HMap <B, T> > AddOrUpdate <A, B, T>(this HMap <A, HMap <B, T> > self, A outerKey, B innerKey, Func <T, T> Some, Func <T> None) => self.AddOrUpdate( outerKey, b => b.AddOrUpdate(innerKey, Some, None), () => Prelude.HashMap(Tuple(innerKey, None())) );
public static HMap <A, HMap <B, V> > MapRemoveT <A, B, T, V>(this HMap <A, HMap <B, T> > self, Func <HMap <B, T>, HMap <B, V> > map) { return(self.Map((ka, va) => map(va)) .Filter((ka, va) => va.Count > 0)); }
public static HMap <A, HMap <B, HMap <C, HMap <D, T> > > > FilterRemoveT <A, B, C, D, T>(this HMap <A, HMap <B, HMap <C, HMap <D, T> > > > self, Func <T, bool> pred) { return(self.MapRemoveT(v => v.Filter(pred))); }
public static HMap <A, HMap <B, HMap <C, HMap <D, V> > > > MapT <A, B, C, D, T, V>(this HMap <A, HMap <B, HMap <C, HMap <D, T> > > > self, Func <T, V> map) { return(self.Map((ka, va) => va.MapT(map))); }
public static HMap <A, HMap <B, HMap <C, HMap <D, T> > > > Remove <A, B, C, D, T>(this HMap <A, HMap <B, HMap <C, HMap <D, T> > > > self, A aKey, B bKey, C cKey, D dKey) { var res = self.Find(aKey, bKey, cKey); if (res.IsSome && res.CountT() > 1) { return(self.SetItemT(aKey, bKey, cKey, res.Lift().Remove(dKey))); } else { if (res.IsSome) { if (res.MapT(d => d.ContainsKey(dKey)).Lift()) { return(Remove(self, aKey, bKey, cKey)); } else { return(self); } } else { return(Remove(self, aKey, bKey, cKey)); } } }
public static int Sum <K>(this HMap <K, int> self) => self.Values.Sum();
public static HMap <A, HMap <B, HMap <C, HMap <D, V> > > > MapRemoveT <A, B, C, D, T, V>(this HMap <A, HMap <B, HMap <C, HMap <D, T> > > > self, Func <HMap <D, T>, HMap <D, V> > map) { return(self.Map((ka, va) => va.Map((kb, vb) => vb.Map((kc, vc) => map(vc)) .Filter((kc, vc) => vc.Count > 0)) .Filter((kb, vb) => vb.Count > 0)) .Filter((ka, va) => va.Count > 0)); }
public static Option <T> Find <A, B, T>(this HMap <A, HMap <B, T> > self, A outerKey, B innerKey) => self.Find(outerKey, b => b.Find(innerKey), () => None);
public static HMap <A, HMap <B, HMap <C, HMap <D, T> > > > FilterT <A, B, C, D, T>(this HMap <A, HMap <B, HMap <C, HMap <D, T> > > > self, Func <T, bool> pred) { return(self.Map((ka, va) => va.FilterT(pred))); }
public static Option <T> Find <A, B, C, T>(this HMap <A, HMap <B, HMap <C, T> > > self, A aKey, B bKey, C cKey) => self.Find(aKey, b => b.Find(bKey, c => c.Find(cKey), () => None), () => None);
public static bool Exists <A, B, T>(this HMap <A, HMap <B, T> > self, Func <T, bool> pred) { return(self.Exists((k, v) => v.Exists(pred))); }
public static R Find <A, B, T, R>(this HMap <A, HMap <B, T> > self, A outerKey, B innerKey, Func <T, R> Some, Func <R> None) => self.Find(outerKey, b => b.Find(innerKey, Some, None), None);