Example #1
0
        string GetExistingStringImpl(char[] buffer, int start, int length, StringHash hash)
        {
            var cursor = GetSearchCursor(hash);

            while (cursor.MightHaveMore)
            {
                var value = cursor.NextString();
                if (value != null && UnsafeStringComparer.AreEqual(value, buffer, start, length))
                {
                    return(value);
                }
            }

            return(null);
        }
Example #2
0
        /// <summary>
        /// Uses the characters from a buffer to check whether a string exists in the set, and retrieve it if so.
        /// </summary>
        /// <param name="chars">A pointer to the string to search for.</param>
        /// <param name="count">The length of the string (in chars).</param>
        /// <param name="knownHashValue">(optional) If the StringHash has already been calculated, you can provide it here to save re-calculation.</param>
        /// <returns>If found in the set, the existing string is returned. If not found, null is returned.</returns>
        public unsafe string GetExistingString(char *chars, int count, StringHash knownHashValue = default(StringHash))
        {
            if (knownHashValue == default(StringHash))
            {
                knownHashValue = StringHash.GetHash(chars, count);
            }

            var cursor = GetSearchCursor(knownHashValue);

            while (cursor.MightHaveMore)
            {
                var value = cursor.NextString();
                if (value != null && UnsafeStringComparer.AreEqual(value, chars, count))
                {
                    return(value);
                }
            }

            return(null);
        }