예제 #1
0
        // does NOT do any checking!
        public int AddRef(NomadData data, long ptr)
        {
            var index = m_Refs.Count;

            m_Refs.Add(data);
            m_Ptrs.Add(ptr);

            return(index);
        }
예제 #2
0
        public long GetPtr(NomadData data)
        {
            var idx = GetIdx(data);

            if (idx != -1)
            {
                return(m_Ptrs[idx]);
            }

            return(-1);
        }
예제 #3
0
        public static int Register(NomadData data, out long hash)
        {
            hash = GenerateHashKey(data);

            var idx = -1;

            if (Keys.Contains(hash))
            {
                idx = Keys.IndexOf(hash);
            }
            else
            {
                idx = Keys.Count;

                Keys.Add(hash);
                Refs.Add(data);
            }

            return(idx);
        }
예제 #4
0
        static long GenerateHashKey(NomadData data)
        {
            var id   = data.Id;
            var hash = (long)id.GetHashCode();

            if (data.IsAttribute)
            {
                var attrData = ((NomadValue)data).Data;

                hash *= attrData.GetHashCode();
                hash ^= attrData.Size;
            }

            if (data.IsObject)
            {
                var obj = ((NomadObject)data);

                var key  = 12345L;
                var size = 0;

                foreach (var attr in obj.Attributes)
                {
                    var attrData = attr.Data;

                    key  += attrData.GetHashCode();
                    size += attrData.Size;
                }

                foreach (var child in obj.Children)
                {
                    key ^= GenerateHashKey(child);
                }

                hash *= key;
                hash ^= (size * obj.Children.Count);
            }

            return(hash);
        }
예제 #5
0
        public static int Find(NomadData data)
        {
            var hash = GenerateHashKey(data);

            return(Keys.IndexOf(hash));
        }
예제 #6
0
 public NomadReference(NomadData data)
 {
     Index = NomadCache.Register(data, out long hash);
     Hash  = hash;
 }
예제 #7
0
 public int GetIdx(NomadData data)
 {
     return(m_Refs.IndexOf(data));
 }