Exemple #1
0
        private SortedDictionary <int, Belief> getBeliefsFor(Belief.Key key)
        {
            SortedDictionary <int, Belief> beliefs;

            if (!beliefDictionary.TryGetValue(key, out beliefs))
            {
                beliefs = new SortedDictionary <int, Belief>();
                beliefDictionary[key] = beliefs;
            }
            return(beliefs);
        }
        public BeliefType Find <BeliefType>(Belief.Key key, int id) where BeliefType : Belief
        {
            CacheKey     cacheKey = new CacheKey(key, id);
            CachedBelief found    = null;

            beliefCache.TryGetValue(cacheKey, out found);
            if (found != null)
            {
                return(found.GetBelief() as BeliefType);
            }
            return(null);
        }
Exemple #3
0
        public RepositoryState deserialize(NetworkBuffer buffer)
        {
            int             revisionNumber = buffer.parseInt32(COMMIT_OFFSET);
            RepositoryState state          = new RepositoryState(revisionNumber);

            int numberOfBeliefs = buffer.parseInt32(NUM_BELIEFS_OFFSET);
            int baseOffset      = HEADER_SIZE;

            for (int i = 0; i < numberOfBeliefs; ++i, baseOffset += BELIEF_SIZE)
            {
                int typeVal            = buffer.readByte(baseOffset + TYPE_OFFSET);
                Belief.BeliefType type = Belief.BeliefType.INVALID;
                if (Enum.IsDefined(typeof(Belief.BeliefType), typeVal))
                {
                    type = (Belief.BeliefType)typeVal;
                }
                else
                {
                    Log.error("Invalid belief type: " + typeVal);
                }

                int    customType = buffer.parseInt32(baseOffset + CUSTOM_TYPE_OFFSET);
                int    id         = buffer.parseInt32(baseOffset + BELIEF_ID_OFFSET);
                byte[] digest     = buffer.readBytes(baseOffset + DIGEST_OFFSET, DIGEST_SIZE);
                Hash   hash       = new Hash(digest);

                Belief.Key key = null;
                if (type == Belief.BeliefType.CUSTOM)
                {
                    key = new Belief.Key(customType);
                }
                else
                {
                    key = new Belief.Key(type);
                }

                state.Add(new CacheKey(key, id), hash);
            }

            return(state);
        }
Exemple #4
0
 public CacheKey(Belief.Key key, int id)
 {
     this.key = key;
     this.id  = id;
 }