ScrewTurn.Wiki.Tools.HashDocumentNameForTemporaryIndex C# (CSharp) Method

HashDocumentNameForTemporaryIndex() public static method

Computes the hash value of a string that is value across application instances and versions.
public static HashDocumentNameForTemporaryIndex ( string value ) : uint
value string The string to compute the hash of.
return uint
        public static uint HashDocumentNameForTemporaryIndex(string value)
        {
            if(value == null) throw new ArgumentNullException("value");

            // sdbm algorithm, borrowed from http://www.cse.yorku.ca/~oz/hash.html
            uint hash = 0;

            foreach(char c in value) {
                // hash(i) = hash(i - 1) * 65599 + str[i]
                hash = c + (hash << 6) + (hash << 16) - hash;
            }

            return hash;
        }

Usage Example

示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:FileDocument" /> class.
        /// </summary>
        /// <param name="fullName">The file full name.</param>
        /// <param name="provider">The file provider.</param>
        /// <param name="dateTime">The modification date/time.</param>
        public FileDocument(string fullName, string provider, DateTime dateTime)
        {
            if (fullName == null)
            {
                throw new ArgumentNullException("fullName");
            }
            if (fullName.Length == 0)
            {
                throw new ArgumentException("Full Name cannot be empty", "fullName");
            }
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (provider.Length == 0)
            {
                throw new ArgumentException("Provider cannot be empty", "provider");
            }

            id            = Tools.HashDocumentNameForTemporaryIndex(fullName);
            name          = provider + "|" + fullName;
            title         = fullName.Substring(Tools.GetDirectoryName(fullName).Length);
            this.dateTime = dateTime;
            this.provider = provider;
        }
All Usage Examples Of ScrewTurn.Wiki.Tools::HashDocumentNameForTemporaryIndex