コード例 #1
0
ファイル: HashTable.cs プロジェクト: alexshvalev/ContactAppQ
        public void Get(string strFilter, ref CBook lpCBook)
        {
            for (int i = 0; i < lpCBook.Count(); i++)
            {
                if (HashTable.hasFilter(lpCBook[i].SName, strFilter) || HashTable.hasFilter(lpCBook[i].Name, strFilter))
                {
                    this.vecItems.Add(new HashTableItem(i, lpCBook[i].SName));
                }
            }

            UInt64 iMin;
            int    iMinPos;
            int    iCount = this.vecItems.Count();

            for (int i = 0; i < iCount - 1; i++)
            {
                iMin    = this.vecItems[i].iCashedString;
                iMinPos = i;
                for (int j = i + 1; j < iCount; j++)
                {
                    if (this.vecItems[j].iCashedString <= iMin)
                    {
                        iMin    = this.vecItems[j].iCashedString;
                        iMinPos = j;
                    }
                }
                HashTableItem temp = this.vecItems[i];
                this.vecItems[i]       = this.vecItems[iMinPos];
                this.vecItems[iMinPos] = temp;
            }
        }
コード例 #2
0
ファイル: HashTable.cs プロジェクト: alexshvalev/ContactAppQ
        public HashTableItem(int iIndex, string strString)
        {
            this.iIndex        = iIndex;
            this.iCashedString = 0;
            int iStrlen = strString.Length;
            int iNum    = 0;

            for (int i = 0; i < 10; i++)
            {
                if (i < iStrlen)
                {
                    if (strString[i] >= 'а' && strString[i] <= 'я')
                    {
                        iNum = (int)(strString[i] - 'а' + 1);
                    }
                    else if (strString[i] >= 'А' && strString[i] <= 'Я')
                    {
                        iNum = (int)(strString[i] - 'А' + 1);
                    }
                    else
                    {
                        iNum = 0;
                    }
                }
                else
                {
                    iNum = 0;
                }
                this.iCashedString += (UInt64)iNum * HashTableItem.pow((UInt64)(33), (UInt64)(9 - i));
            }
        }