/// <summary> /// /// </summary> /// <param name="h"></param> /// <param name="temp"></param> /// <returns></returns> public int GetIndex(int h, NativeStringView temp) { Assert.IsTrue(temp.Length <= kMaxCharsPerEntry); // about one printed page of text int itemIndex; NativeMultiHashMapIterator <int> iter; if (hash.TryGetFirstValue(h, out itemIndex, out iter)) { var l = length[itemIndex]; Assert.IsTrue(l <= kMaxCharsPerEntry); if (l == temp.Length) { var o = offset[itemIndex]; int matches; for (matches = 0; matches < l; ++matches) { if (temp[matches] != buffer[o + matches]) { break; } } if (matches == temp.Length) { return(itemIndex); } } } while (hash.TryGetNextValue(out itemIndex, ref iter)) { ; } return(-1); }
/// <summary> /// /// </summary> /// <param name="value"></param> /// <returns></returns> public int GetOrCreateIndex(NativeStringView value) { int h = value.GetHashCode(); var itemIndex = GetIndex(h, value); if (itemIndex != -1) { return(itemIndex); } Assert.IsTrue(entries < kMaxEntries); Assert.IsTrue(chars + value.Length <= kMaxChars); var o = chars; var l = (ushort)value.Length; for (var i = 0; i < l; ++i) { buffer[chars++] = value[i]; } offset[entries] = o; length[entries] = l; hash.Add(h, entries); return(entries++); }
/// <summary> /// /// </summary> /// <param name="value"></param> /// <returns></returns> public bool Contains(NativeStringView value) { int h = value.GetHashCode(); return(GetIndex(h, value) != -1); }