Ejemplo n.º 1
0
        public static HashMap <A, HashMap <B, V> > TrySetItemT <A, B, V>(this HashMap <A, HashMap <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)));
        }
Ejemplo n.º 2
0
        public static HashMap <A, HashMap <B, HashMap <C, HashMap <D, V> > > > TrySetItemT <A, B, C, D, V>(
            this HashMap <A, HashMap <B, HashMap <C, HashMap <D, V> > > > map, A aKey, B bKey, C cKey, D dKey, 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, dKey, Some)));
        }
Ejemplo n.º 3
0
        public static HashMap <A, HashMap <B, HashMap <C, HashMap <D, V> > > > SetItemT <A, B, C, D, V>(
            this HashMap <A, HashMap <B, HashMap <C, HashMap <D, V> > > > map, A aKey, B bKey, C cKey, D dKey, 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, dKey, Some)));
        }
Ejemplo n.º 4
0
        public static HashMap <A, HashMap <B, V> > SetItemT <A, B, V>(this HashMap <A, HashMap <B, V> > map, A aKey, B bKey,
                                                                      V value)
        {
            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.SetItem(bKey, value)));
        }
Ejemplo n.º 5
0
        public static HashMap <A, HashMap <B, HashMap <C, T> > > Remove <A, B, C, T>(
            this HashMap <A, HashMap <B, HashMap <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);
            }
        }
Ejemplo n.º 6
0
        public static HashMap <A, HashMap <B, T> > Remove <A, B, T>(this HashMap <A, HashMap <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);
            }
        }
Ejemplo n.º 7
0
        static HashMap <long, RefState> CommitWrites(Transaction t, HashMap <long, RefState> s)
        {
            // Check if something else wrote to what we were writing
            foreach (var write in t.writes)
            {
                var newState = t.state[write];

                if (!newState.Validator(newState.Value))
                {
                    throw new RefValidationFailedException();
                }

                if (s[write].Version == newState.Version)
                {
                    s = s.SetItem(write, new RefState(newState.Version + 1, newState.Value, newState.Validator));
                }
                else
                {
                    throw new ConflictException();
                }
            }

            return(s);
        }