// 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); }
public long GetPtr(NomadData data) { var idx = GetIdx(data); if (idx != -1) { return(m_Ptrs[idx]); } return(-1); }
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); }
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); }
public static int Find(NomadData data) { var hash = GenerateHashKey(data); return(Keys.IndexOf(hash)); }
public NomadReference(NomadData data) { Index = NomadCache.Register(data, out long hash); Hash = hash; }
public int GetIdx(NomadData data) { return(m_Refs.IndexOf(data)); }