Beispiel #1
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);
        }
Beispiel #2
0
 public static bool ForAll <A, B, C, D, T>(this HashMap <A, HashMap <B, HashMap <C, HashMap <D, T> > > > self,
                                           Func <T, bool> pred)
 {
     return(self.ForAll((k, v) => v.ForAll(pred)));
 }
Beispiel #3
0
 public static bool Exists <A, B, C, D, T>(this HashMap <A, HashMap <B, HashMap <C, HashMap <D, T> > > > self,
                                           Func <T, bool> pred)
 {
     return(self.Exists((k, v) => v.Exists(pred)));
 }
Beispiel #4
0
 public static Option <T> Find <A, B, C, T>(this HashMap <A, HashMap <B, HashMap <C, T> > > self, A aKey, B bKey,
                                            C cKey) =>
 self.Find(aKey, b => b.Find(bKey, c => c.Find(cKey), () => None), () => None);
Beispiel #5
0
 public static HashMap <A, HashMap <B, HashMap <C, HashMap <D, T> > > > FilterRemoveT <A, B, C, D, T>(
     this HashMap <A, HashMap <B, HashMap <C, HashMap <D, T> > > > self, Func <T, bool> pred)
 {
     return(self.MapRemoveT(v => v.Filter(pred)));
 }
Beispiel #6
0
 public static int hash <EqK, K, V>(HashMap <EqK, K, V> xs) where EqK : struct, Eq <K> =>
 xs.GetHashCode();
Beispiel #7
0
 public static HashMap <K, V> clear <K, V>(HashMap <K, V> map) =>
 HashMap <K, V> .Empty;
 public static int Count <EqK, K, V>(this HashMap <EqK, K, V> self) where EqK : struct, Eq <K> =>
 self.Count;
Beispiel #9
0
 public static int Sum <K>(this HashMap <K, int> self) =>
 self.Values.Sum();
Beispiel #10
0
 public static HashMap <A, HashMap <B, V> > MapRemoveT <A, B, T, V>(this HashMap <A, HashMap <B, T> > self,
                                                                    Func <HashMap <B, T>, HashMap <B, V> > map)
 {
     return(self.Map((ka, va) => map(va))
            .Filter((ka, va) => va.Count > 0));
 }
Beispiel #11
0
 public static int Count <K, V>(this HashMap <K, V> self) =>
 self.Count;
Beispiel #12
0
 public static HashMap <EqK, K, V> clear <EqK, K, V>(HashMap <EqK, K, V> map) where EqK : struct, Eq <K> =>
 HashMap <EqK, K, V> .Empty;
 public static HashMap <K, V> append <K, V>(HashMap <K, V> x, HashMap <K, V> y) =>
 MHashMap <K, V> .Inst.Append(x, y);
Beispiel #14
0
 public static AtomHashMap <EqK, K, V> ToAtom <EqK, K, V>(this HashMap <EqK, K, V> self) where EqK : struct, Eq <K> =>
 new AtomHashMap <EqK, K, V>(self);
Beispiel #15
0
 public static R Find <A, B, T, R>(this HashMap <A, HashMap <B, T> > self, A outerKey, B innerKey, Func <T, R> Some,
                                   Func <R> None) =>
 self.Find(outerKey, b => b.Find(innerKey, Some, None), None);
Beispiel #16
0
 public static HashMap <A, HashMap <B, HashMap <C, HashMap <D, V> > > > MapT <A, B, C, D, T, V>(
     this HashMap <A, HashMap <B, HashMap <C, HashMap <D, T> > > > self, Func <T, V> map)
 {
     return(self.Map((ka, va) => va.MapT(map)));
 }
Beispiel #17
0
 public static S FoldT <A, B, C, D, S, V>(this HashMap <A, HashMap <B, HashMap <C, HashMap <D, V> > > > map, S state,
                                          Func <S, V, S> folder)
 {
     return(map.Fold(state, (s, x) => x.FoldT(s, folder)));
 }
Beispiel #18
0
 public static Option <T> Find <A, B, T>(this HashMap <A, HashMap <B, T> > self, A outerKey, B innerKey) =>
 self.Find(outerKey, b => b.Find(innerKey), () => None);
 public static int Sum <EqK, K>(this HashMap <EqK, K, int> self) where EqK : struct, Eq <K> =>
 self.Values.Sum();
Beispiel #20
0
 public static HashMap <A, HashMap <B, HashMap <C, HashMap <D, T> > > > FilterT <A, B, C, D, T>(
     this HashMap <A, HashMap <B, HashMap <C, HashMap <D, T> > > > self, Func <T, bool> pred)
 {
     return(self.Map((ka, va) => va.FilterT(pred)));
 }
 public static AtomHashMap <K, V> ToAtom <K, V>(this HashMap <K, V> self) =>
 new AtomHashMap <K, V>(self);
Beispiel #22
0
 public static int hash <K, V>(HashMap <K, V> xs) =>
 xs.GetHashCode();