diff --git a/.DS_Store b/.DS_Store index e60488f..2bc8c57 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/README b/README index 462854e..6dc56e5 100644 --- a/README +++ b/README @@ -1,3 +1,5 @@ +对原来的SearchCoreTest进行修改,将部分int换成NSIntger,以支持64位 +****************************华丽丽的分隔线************************************* SearchCoreTest ============== Author: kewenya diff --git a/SearchCore/Array.h b/SearchCore/Array.h index c5a661a..d589391 100644 --- a/SearchCore/Array.h +++ b/SearchCore/Array.h @@ -13,7 +13,6 @@ ============================================================================ */ - #include #include @@ -25,62 +24,62 @@ -#define MallocIndexByte (INDEX_NUM_MAX*sizeof(int)) -#define MallocByte (MALLOC_SIZE*sizeof(int)) +#define MallocIndexByte (INDEX_NUM_MAX*sizeof(NSInteger)) +#define MallocByte (MALLOC_SIZE*sizeof(NSInteger)) typedef struct ArrayData { - int* pData; + NSInteger* pData; struct ArrayData* next; }ArrayData; typedef struct Array { - int size; - int mallocsize; //数据域个数 + NSInteger size; + NSInteger mallocsize; //数据域个数 - int** pIndexData; //索引空间首地址 - int pIndexNum; //索引空间个数 + NSInteger** pIndexData; //索引空间首地址 + NSInteger pIndexNum; //索引空间个数 - int* pDataEnd; + NSInteger* pDataEnd; - void (*Append)(struct Array* A,int value); - void (*Insert)(struct Array* A,int value,int pos); - void (*Remove)(struct Array* A,int index); + void (*Append)(struct Array* A,NSInteger value); + void (*Insert)(struct Array* A,NSInteger value,NSInteger pos); + void (*Remove)(struct Array* A,NSInteger index); void (*Reset)(struct Array* A); - int (*GetValue)(struct Array* A,int index); + NSInteger (*GetValue)(struct Array* A,NSInteger index); }Array; void ArrayInit(struct Array* A); -void ArrayAppend(Array* A,int value); -void ArrayInsert(Array* A,int value,int pos); -void ArrayRemove(Array* A,int index); +void ArrayAppend(Array* A,NSInteger value); +void ArrayInsert(Array* A,NSInteger value,NSInteger pos); +void ArrayRemove(Array* A,NSInteger index); void ArrayReset(Array* A); -int ArrayReSize(Array* A); -int ArrayGetValue(Array* A,int index); +NSInteger ArrayReSize(Array* A); +NSInteger ArrayGetValue(Array* A,NSInteger index); typedef struct ArrayC { - int size; - int pDataSize; //数据域个数 - int *pData; //空间首地址 + NSInteger size; + NSInteger pDataSize; //数据域个数 + NSInteger *pData; //空间首地址 - int* pDataEnd; + NSInteger* pDataEnd; - void (*Append)(struct ArrayC* A,int value); + void (*Append)(struct ArrayC* A,NSInteger value); void (*Reset)(struct ArrayC* A); - void (*SetSize)(struct ArrayC* A,int size); - int (*GetValue)(struct ArrayC* A,int index); + void (*SetSize)(struct ArrayC* A,NSInteger size); + NSInteger (*GetValue)(struct ArrayC* A,NSInteger index); }ArrayC; void ArrayCInit(struct ArrayC* A); -void ArrayCAppend(ArrayC* A,int value); +void ArrayCAppend(ArrayC* A,NSInteger value); void ArrayCReset(ArrayC* A); -int ArrayCGetValue(ArrayC* A,int index); -void ArrayCSetSize(struct ArrayC* A,int size); +NSInteger ArrayCGetValue(ArrayC* A,NSInteger index); +void ArrayCSetSize(struct ArrayC* A,NSInteger size); #endif diff --git a/SearchCore/Array.mm b/SearchCore/Array.mm index 0d4f492..04703f2 100644 --- a/SearchCore/Array.mm +++ b/SearchCore/Array.mm @@ -1,6 +1,6 @@ #include "Array.h" -int sizeof_int = sizeof(int); +NSInteger sizeof_int = sizeof(NSInteger); void ArrayInit(struct Array* A) { @@ -20,7 +20,7 @@ void ArrayInit(struct Array* A) return; } -void ArrayAppend(Array* A,int value) +void ArrayAppend(Array* A,NSInteger value) { if( A->size < A->mallocsize || ArrayReSize( A ) > 0 ) { @@ -33,13 +33,13 @@ void ArrayAppend(Array* A,int value) return; } -void ArrayInsert(Array* A,int value,int pos) +void ArrayInsert(Array* A,NSInteger value,NSInteger pos) { - int size = A->size; - int i = 0; - int* ptr = 0; - int* ptr0 = 0; - int** ptr_index = 0; + NSInteger size = A->size; + NSInteger i = 0; + NSInteger* ptr = 0; + NSInteger* ptr0 = 0; + NSInteger** ptr_index = 0; if(pos >= 0 && pos <= size) { @@ -77,15 +77,15 @@ void ArrayInsert(Array* A,int value,int pos) return; } -void ArrayRemove(Array* A,int index) +void ArrayRemove(Array* A,NSInteger index) { - int size = A->size; - int i; - int* ptr0 = 0; - int* ptr = 0; - int* ptr_temp = 0; - int** ptr_index = 0; - int pIndex = 0; + NSInteger size = A->size; + NSInteger i; + NSInteger* ptr0 = 0; + NSInteger* ptr = 0; + NSInteger* ptr_temp = 0; + NSInteger** ptr_index = 0; + NSInteger pIndex = 0; if(index >= 0 && index < size) { @@ -124,7 +124,7 @@ void ArrayRemove(Array* A,int index) } void ArrayReset(Array* A) { - int i = 0; + NSInteger i = 0; for(i = 0;i < A->pIndexNum;i ++) free(*(A->pIndexData+i)); @@ -136,22 +136,22 @@ void ArrayReset(Array* A) ArrayInit(A); } -int ArrayReSize(Array* A) +NSInteger ArrayReSize(Array* A) { - int newsize; - int* desData; - int mallocsize = MallocByte; - int mallocindexsize = MallocIndexByte; + NSInteger newsize; + NSInteger* desData; + NSInteger mallocsize = MallocByte; + NSInteger mallocindexsize = MallocIndexByte; //内存不够 if(A->pIndexNum + 1 >= INDEX_NUM_MAX ) return 0; if( !A->pIndexData ) - A->pIndexData = (int**)malloc(mallocindexsize); + A->pIndexData = (NSInteger**)malloc(mallocindexsize); newsize = A->mallocsize + MALLOC_SIZE; - desData = (int*)malloc(mallocsize); + desData = (NSInteger*)malloc(mallocsize); *(A->pIndexData+A->pIndexNum) = desData; A->pIndexNum ++; @@ -162,11 +162,11 @@ int ArrayReSize(Array* A) return 1; } -int ArrayGetValue(Array* A,int index) +NSInteger ArrayGetValue(Array* A,NSInteger index) { - int* ptr = 0; - int* ptr_index = 0; - int pIndex = 0; + NSInteger* ptr = 0; + NSInteger* ptr_index = 0; + NSInteger pIndex = 0; if(index >= 0 && index < A->size) { @@ -193,7 +193,7 @@ void ArrayCInit(struct ArrayC* A) A->SetSize = &ArrayCSetSize; return; } -void ArrayCAppend(ArrayC* A,int value) +void ArrayCAppend(ArrayC* A,NSInteger value) { if( A->size < A->pDataSize ) { @@ -214,7 +214,7 @@ void ArrayCReset(ArrayC* A) ArrayCInit(A); } -int ArrayCGetValue(ArrayC* A,int index) +NSInteger ArrayCGetValue(ArrayC* A,NSInteger index) { if( index >= 0 && index < A->size ) return *(A->pData + index); @@ -222,12 +222,12 @@ int ArrayCGetValue(ArrayC* A,int index) return -1; } -void ArrayCSetSize(struct ArrayC* A,int size) +void ArrayCSetSize(struct ArrayC* A,NSInteger size) { if( A->pDataSize > 0 ) return; A->pDataSize = size; - A->pData = (int*)malloc(size*sizeof_int); + A->pData = (NSInteger*)malloc(size*sizeof_int); A->pDataEnd = A->pData; } diff --git a/SearchCore/SearchCore.h b/SearchCore/SearchCore.h index 8c18792..8059bfe 100644 --- a/SearchCore/SearchCore.h +++ b/SearchCore/SearchCore.h @@ -28,7 +28,7 @@ BOOL Tree_GetPhoneNum #include "string.h" -//typedef int BOOL; +//typedef NSInteger BOOL; typedef unsigned short u2char; #define TRUE 1 #define FALSE 0 @@ -50,24 +50,24 @@ typedef unsigned short u2char; typedef struct WordCode { u2char Word; //原始unicode码 -int PyCodeNum; // 拼音码个数 -int* PyCodeIndex; // 拼音码值(支持多拼音) +NSInteger PyCodeNum; // 拼音码个数 +NSInteger* PyCodeIndex; // 拼音码值(支持多拼音) }WordCode; typedef struct SearchData { - int id; //唯一标志ID + NSInteger id; //唯一标志ID u2char* iPhoneNum; //电话号码,用于号码匹配 - int WordCodeNum; + NSInteger WordCodeNum; u2char *WordCodeArray; }SearchData; typedef struct SearchPos { - int pos; //(第几个字:18bit) + (第几个拼音码:3bit) + (第几个字母:3bit) - int step; //步长:当前匹配到第几个字 + NSInteger pos; //(第几个字:18bit) + (第几个拼音码:3bit) + (第几个字母:3bit) + NSInteger step; //步长:当前匹配到第几个字 struct SearchPos * iFather; //father }SearchPos; @@ -95,7 +95,7 @@ typedef struct SearchSort }SearchSort; //============================================== BEGIN ================================================ //供外部调用的函数 -int u2slen(const u2char* str); +NSInteger u2slen(const u2char* str); void u2scpy(u2char* des,const u2char* src); int u2scmp(const u2char* str1,const u2char* str2); @@ -122,7 +122,7 @@ void ReleaseMultiPYinWords(); * aText: 名字 * aPhoneNum:号码 */ -void Tree_AddData(SearchTree* tree, int aID, const u2char* aText,const u2char* aPhoneNum); +void Tree_AddData(SearchTree* tree, NSInteger aID, const u2char* aText,const u2char* aPhoneNum); /* * 修改数据源信息 @@ -130,13 +130,13 @@ void Tree_AddData(SearchTree* tree, int aID, const u2char* aText,const u2char* a * aText: 名字 * aPhoneNum:号码 */ -void Tree_ReplaceData(SearchTree* tree, int aID, const u2char* aText,const u2char* aPhoneNum ); +void Tree_ReplaceData(SearchTree* tree, NSInteger aID, const u2char* aText,const u2char* aPhoneNum ); /* * 删除数据源信息 * aID: 数据索引ID */ -void Tree_DeleteData(SearchTree* tree, int aID ); +void Tree_DeleteData(SearchTree* tree, NSInteger aID ); /* * 搜索数据 @@ -157,12 +157,12 @@ void Tree_SetMatchFunction(SearchTree* tree,const u2char* aMatchFunc); * aText 拼音 * iMatchPosInPinYin 匹配位置 */ -BOOL Tree_GetPinYin(SearchTree* tree,int aID, u2char* aText, Array* iMatchPosInPinYin); +BOOL Tree_GetPinYin(SearchTree* tree,NSInteger aID, u2char* aText, Array* iMatchPosInPinYin); /* * 获取号码匹配的号码、匹配位置 */ -BOOL Tree_GetPhoneNum(SearchTree* tree,int aID, u2char* aText, Array* iMatchPosInPhoneNum); +BOOL Tree_GetPhoneNum(SearchTree* tree,NSInteger aID, u2char* aText, Array* iMatchPosInPhoneNum); //================================================ END ============================================== @@ -189,13 +189,13 @@ void AddToCachedHitSingle(SearchTree* tree,SearchData *aData, Array* aCacheArray BOOL IsMatchByKmp(const u2char* aText,const u2char* wordInput,Array* iMatchPosInPinYin); //aID 的索引index < 0为不存在 -int FindSearchDataIndex(Array* ptr,int aID,SearchData** data); +NSInteger FindSearchDataIndex(Array* ptr,NSInteger aID,SearchData** data); /* * < 0 已存在 * > 0 需插入位置 */ -int FindSearchDataInsertIndex(Array* ptr,int aID); +NSInteger FindSearchDataInsertIndex(Array* ptr,NSInteger aID); /* * aText GBK编码 @@ -209,20 +209,20 @@ BOOL SearchCachedHit(SearchTree* tree, u2char word, Array **aHits); /* * 确定某一搜索集是否匹配搜索串 return匹配的权值,<0为不匹配 */ -int IsHit(SearchTree* tree,SearchData* aData, SearchData* aSearchWordData,BOOL iIsLogTrace); +NSInteger IsHit(SearchTree* tree,SearchData* aData, SearchData* aSearchWordData,BOOL iIsLogTrace); /* * 确定aWordCode串的aPos位置,是否和aWord相匹配 */ -BOOL IsMatch(SearchTree* tree,WordCode* aWordCode,int nPyCode,int nchar, unsigned int aWord ); +BOOL IsMatch(SearchTree* tree,WordCode* aWordCode,NSInteger nPyCode,NSInteger nchar, NSUInteger aWord ); -unsigned int ChangeWordToDigit(SearchTree* tree,unsigned int Word); +NSUInteger ChangeWordToDigit(SearchTree* tree,NSUInteger Word); -BOOL CompareWord(SearchTree* tree,unsigned int Word,unsigned int WordInput); +BOOL CompareWord(SearchTree* tree,NSUInteger Word,NSUInteger WordInput); -int FindIndexInMultiPYin(unsigned int key); +NSInteger FindIndexInMultiPYin(NSUInteger key); -SearchPos* GetSearchPos(int index); +SearchPos* GetSearchPos(NSInteger index); void FreeWordCode(WordCode* word); void FreeSearchData(SearchData* data); diff --git a/SearchCore/SearchCore.mm b/SearchCore/SearchCore.mm index 7402f1b..05f1eee 100644 --- a/SearchCore/SearchCore.mm +++ b/SearchCore/SearchCore.mm @@ -1,31 +1,32 @@ #include "SearchCore.h" #include +#include "stdio.h" //#include "MrUtilDebug.h" Array iMultiPyCodeSorted; BOOL iIsMultiPYinWordsLoaded = FALSE; -int SIZEOF_INT = sizeof(int); -int SIZEOF_U2Char = sizeof(u2char); -int SIZEOF_WordCode = sizeof(WordCode); -int SIZEOF_SearchData = sizeof(SearchData); -int SIZEOF_SearchPos = sizeof(SearchPos); -int SIZEOF_SearchSort = sizeof(SearchSort); +NSInteger SIZEOF_INT = sizeof(NSInteger); +NSInteger SIZEOF_U2Char = sizeof(u2char); +NSInteger SIZEOF_WordCode = sizeof(WordCode); +NSInteger SIZEOF_SearchData = sizeof(SearchData); +NSInteger SIZEOF_SearchPos = sizeof(SearchPos); +NSInteger SIZEOF_SearchSort = sizeof(SearchSort); //kmp比较需缓存 -int iKmpBuf[128]; +NSInteger iKmpBuf[128]; -int searchPosMallocSize = 0; +NSInteger searchPosMallocSize = 0; SearchPos *searchPosMalloc = NULL; -int searchPosPtrMallocSize = 0; +NSInteger searchPosPtrMallocSize = 0; SearchPos **searchPosPtrArray = NULL; Array searchPosMallocArray; //enum {ID_Ascii = 0,ID_PinYinCode = 1,ID_CharIndex = 2,ID_CharIndex2 = 3,ID_CannotSpell = 4}; BOOL isPinYinCodeIndexSorted = FALSE; -int PinYinCodeIndexSort[KPyCodeNum]; -int PinYinNum[KPyCodeNum]; +NSInteger PinYinCodeIndexSort[KPyCodeNum]; +NSInteger PinYinNum[KPyCodeNum]; //汉字基本发音表 const char *PinYinCode[KPyCodeNum] = @@ -178,9 +179,9 @@ }; -int u2slen(const u2char* str) { +NSInteger u2slen(const u2char* str) { const u2char* ptr = str; - int len = 0; + NSInteger len = 0; while (ptr && *ptr) { ptr ++; @@ -230,9 +231,9 @@ int u2scmp(const u2char* str1,const u2char* str2) { void getSortString(SearchSort *node) { u2char sortString[256]; - int pos = 0; - int lenmax = 127; - int i; + NSInteger pos = 0; + NSInteger lenmax = 127; + NSInteger i; WordCode code; // 提取字符码部分组成字符串,用于排序比较 @@ -287,15 +288,15 @@ int SearchSortCmp(void const* item1,void const* item2) //PinYinCode 按拼音排序后存入PinYinCodeIndexSort void SortPinYinCodeIndex(){ - int low = 0; - int mid = 0; - int high = 0; - int i = 0; - int j = 0; - int val = 0; + NSInteger low = 0; + NSInteger mid = 0; + NSInteger high = 0; + NSInteger i = 0; + NSInteger j = 0; + NSInteger val = 0; BOOL exist = FALSE; - int midIndex = 0; - int sort[KPyCodeNum]; + NSInteger midIndex = 0; + NSInteger sort[KPyCodeNum]; for (i = 0; i < KPyCodeNum ; i ++) { low = 0; @@ -321,14 +322,14 @@ void SortPinYinCodeIndex(){ sort[j] = i; } - for (int i = 0; i < KPyCodeNum; i ++) + for (NSInteger i = 0; i < KPyCodeNum; i ++) PinYinCodeIndexSort[sort[i]] = i; } void SearchTreeInit(SearchTree* tree) { - int i = 0; + NSInteger i = 0; ArrayInit(&tree->SearchDataArray); for(i = 0;i < KCachedHitNum;i ++) @@ -346,18 +347,18 @@ void SearchTreeInit(SearchTree* tree) ArrayInit(&searchPosMallocArray); - for (int i = 0; i < KPyCodeNum; i ++) { + for (NSInteger i = 0; i < KPyCodeNum; i ++) { PinYinNum[i] = i; } } -void Tree_AddData(SearchTree* tree, int aID, const u2char* aText,const u2char* aPhoneNum) +void Tree_AddData(SearchTree* tree, NSInteger aID, const u2char* aText,const u2char* aPhoneNum) { SearchData* data = 0; - int len = 0; - int size = 0; + NSInteger len = 0; + NSInteger size = 0; - int pos = FindSearchDataInsertIndex(&tree->SearchDataArray,aID); + NSInteger pos = FindSearchDataInsertIndex(&tree->SearchDataArray,aID); if( pos < 0 ) //已存在 return; @@ -368,7 +369,7 @@ void Tree_AddData(SearchTree* tree, int aID, const u2char* aText,const u2char* a data->WordCodeArray = NULL; Text2SearchData( aText, data ); - tree->SearchDataArray.Insert(&tree->SearchDataArray,(int)data,pos); + tree->SearchDataArray.Insert(&tree->SearchDataArray,(NSInteger)data,pos); //首字母预处理 AddToCachedHit(tree,data); @@ -386,7 +387,7 @@ void Tree_AddData(SearchTree* tree, int aID, const u2char* aText,const u2char* a return; } -void Tree_ReplaceData(SearchTree* tree, int aID, const u2char* aText,const u2char* aPhoneNum ) +void Tree_ReplaceData(SearchTree* tree, NSInteger aID, const u2char* aText,const u2char* aPhoneNum ) { Tree_DeleteData(tree,aID); @@ -395,10 +396,10 @@ void Tree_ReplaceData(SearchTree* tree, int aID, const u2char* aText,const u2cha return; } -void Tree_DeleteData(SearchTree* tree, int aID ) +void Tree_DeleteData(SearchTree* tree, NSInteger aID ) { - int i = 0; - int pos = 0; + NSInteger i = 0; + NSInteger pos = 0; Array* cache = NULL; SearchData *data = NULL; @@ -427,8 +428,8 @@ void Tree_DeleteData(SearchTree* tree, int aID ) void Tree_SetMatchFunction(SearchTree* tree,const u2char* aMatchFunc) { - int len = 0; - int size = 0; + NSInteger len = 0; + NSInteger size = 0; if (tree->iMatchFunc) { free(tree->iMatchFunc); tree->iMatchFunc = NULL; @@ -453,11 +454,11 @@ void LoadMultiPYinWords(const char* multiPYinPath) FILE* file = NULL; FILE* fp = NULL; - int size = 0; - int i = 0; + NSInteger size = 0; + NSInteger i = 0; unsigned digital_10 = 0; unsigned digital_16 = 0; - int index = 0; + NSInteger index = 0; char* buf = NULL; unsigned char word = 0; unsigned char word1 = 0; @@ -506,7 +507,7 @@ void LoadMultiPYinWords(const char* multiPYinPath) cur = (WordCode*)malloc(SIZEOF_WordCode); cur->Word = digital_16; cur->PyCodeNum = 0; - cur->PyCodeIndex = (int*)malloc(SIZEOF_INT*KMaxPyCode); + cur->PyCodeIndex = (NSInteger*)malloc(SIZEOF_INT*KMaxPyCode); //DP1("cur->Word %d",cur->Word) index = FindIndexInMultiPYin(cur->Word); if( index >= 0 ) @@ -515,7 +516,7 @@ void LoadMultiPYinWords(const char* multiPYinPath) cur = NULL; } else - iMultiPyCodeSorted.Insert(&iMultiPyCodeSorted,(int)cur,-index-1); + iMultiPyCodeSorted.Insert(&iMultiPyCodeSorted,(NSInteger)cur,-index-1); } else if( digital_10 > 0 && cur ) { @@ -538,12 +539,12 @@ void LoadMultiPYinWords(const char* multiPYinPath) BOOL IsMatchByKmp(const u2char* aText,const u2char* wordInput,Array* iMatchPosInPinYin) { - int i,j; - int len1 = 0; - int len2 = 0; - int p1 = 0; - int p2 = 0; - int k = 0; + NSInteger i,j; + NSInteger len1 = 0; + NSInteger len2 = 0; + NSInteger p1 = 0; + NSInteger p2 = 0; + NSInteger k = 0; iKmpBuf[0] = 0; j = 0; @@ -587,11 +588,11 @@ BOOL IsMatchByKmp(const u2char* aText,const u2char* wordInput,Array* iMatchPosIn return FALSE; } -int FindSearchDataIndex(Array* ptr,int aID,SearchData** data) +NSInteger FindSearchDataIndex(Array* ptr,NSInteger aID,SearchData** data) { - int low = 0; - int high = ptr->size - 1; - int mid; + NSInteger low = 0; + NSInteger high = ptr->size - 1; + NSInteger mid; SearchData* temp; while (low <= high) { @@ -613,10 +614,10 @@ int FindSearchDataIndex(Array* ptr,int aID,SearchData** data) return -(low+1); } -int FindSearchDataInsertIndex(Array* ptr,int aID) +NSInteger FindSearchDataInsertIndex(Array* ptr,NSInteger aID) { SearchData* data = 0; - int pos = FindSearchDataIndex(ptr,aID,&data); + NSInteger pos = FindSearchDataIndex(ptr,aID,&data); if( pos < 0 ) return - pos - 1; else @@ -627,7 +628,7 @@ void Text2SearchData(const u2char* aText,SearchData *data) { const u2char* ptr = aText; u2char character; - int count = u2slen(aText); + NSInteger count = u2slen(aText); // 遍历各个字符,转换为WordCode数组后保存 data->WordCodeArray = NULL; @@ -653,9 +654,9 @@ BOOL Word2Code( u2char aWord, WordCode *code ) { unsigned char t1 = (aWord >> 8) & 0xFF; unsigned char t2 = aWord & 0xFF; - int PyIndex; + NSInteger PyIndex; u2char word = 0; - int index; + NSInteger index; code->Word = aWord; code->PyCodeNum = 0; @@ -689,7 +690,7 @@ BOOL Word2Code( u2char aWord, WordCode *code ) // 添加到WordCode code->PyCodeNum = 1; index = PyCodeIndex[t1-78][t2] - 1; - code->PyCodeIndex = (int*)&PinYinNum[index]; + code->PyCodeIndex = (NSInteger*)&PinYinNum[index]; } } } @@ -698,16 +699,16 @@ BOOL Word2Code( u2char aWord, WordCode *code ) return TRUE; } -int FindIndexInMultiPYin(unsigned int key) +NSInteger FindIndexInMultiPYin(NSUInteger key) { // 二分法查找确定 - int low = 0; - int high = iMultiPyCodeSorted.size - 1; + NSInteger low = 0; + NSInteger high = iMultiPyCodeSorted.size - 1; WordCode *midVal; while(low <= high) { - int mid = (low + high) >> 1; + NSInteger mid = (low + high) >> 1; midVal = (WordCode *)iMultiPyCodeSorted.GetValue(&iMultiPyCodeSorted,mid); if( midVal->Word < key ) @@ -724,9 +725,9 @@ int FindIndexInMultiPYin(unsigned int key) void AddToCachedHit(SearchTree* tree, SearchData *aData) { - int i = 0; - int j = 0; - int capticalIndex = 0; + NSInteger i = 0; + NSInteger j = 0; + NSInteger capticalIndex = 0; WordCode code; u2char word; @@ -773,12 +774,12 @@ void AddToCachedHit(SearchTree* tree, SearchData *aData) void AddToCachedHitSingle(SearchTree* tree,SearchData *aData, Array* aCacheArray) { - int pos = FindSearchDataInsertIndex(aCacheArray, aData->id); + NSInteger pos = FindSearchDataInsertIndex(aCacheArray, aData->id); if( pos >= 0 ) { // 不存在 //NSLog(@"pos %d",pos); - aCacheArray->Insert(aCacheArray,(int)aData, pos); + aCacheArray->Insert(aCacheArray,(NSInteger)aData, pos); } return; } @@ -787,23 +788,23 @@ void AddToCachedHitSingle(SearchTree* tree,SearchData *aData, Array* aCacheArray void Tree_Search(SearchTree* tree, u2char* aText, Array* aSearchedArray,Array* aNameMatchArray, Array* aPhoneMatchArray) { - int i = 0; - int value = 0; - int count = 0; - int len = 0; - int temp = 0; + NSInteger i = 0; + NSInteger value = 0; + NSInteger count = 0; + NSInteger len = 0; + NSInteger temp = 0; u2char* textPtr = 0; u2char* buf = 0; u2char* bufPtr = 0; - int pos = 0; - int curSearchWordNum = 0; + NSInteger pos = 0; + NSInteger curSearchWordNum = 0; // NSLog(@"Tree_Search begin 0"); SearchData* iCurSeachData = tree->iCurSeachData; SearchData *dataToSearch = 0; Array* cache = 0; SearchSort *searchSortPtr = 0; - int matchCount = 0; + NSInteger matchCount = 0; Array aNameMatchHits; Array aPhoneMatchHits; @@ -859,7 +860,7 @@ void Tree_Search(SearchTree* tree, u2char* aText, Array* aSearchedArray,Array* a node->matchAllInWord = value & 1; node->iSortString = NULL; - aNameMatchHits.Append(&aNameMatchHits, (int)dataToSearch); + aNameMatchHits.Append(&aNameMatchHits, (NSInteger)dataToSearch); //NSLog(@"%d %d %d %d %d %d",aID,node->matchStart,node->matchEnd,node->pos,node->matchAllInPy,node->matchAllInWord); } } @@ -923,7 +924,7 @@ void Tree_Search(SearchTree* tree, u2char* aText, Array* aSearchedArray,Array* a BOOL SearchCachedHit(SearchTree* tree, u2char word, Array **aHits) { BOOL isMakeSure = TRUE; - int capticalIndex; + NSInteger capticalIndex; WordCode code; // NSLog(@"SearchCachedHit 0"); @@ -995,7 +996,7 @@ BOOL SearchCachedHit(SearchTree* tree, u2char word, Array **aHits) if( pos >= 0 ) { //不存在 - aHits->Insert(aHits,(int)data,pos); + aHits->Insert(aHits,(NSInteger)data,pos); } } } @@ -1010,22 +1011,22 @@ BOOL SearchCachedHit(SearchTree* tree, u2char word, Array **aHits) /* * 确定某一搜索集是否匹配搜索串 return匹配的权值:初位置8bit+末位置8bit+全拼匹配8bit+全汉字匹配8bit,<0为不匹配 */ -int IsHit(SearchTree* tree,SearchData* aData, SearchData* aSearchWordData,BOOL iIsLogTrace) +NSInteger IsHit(SearchTree* tree,SearchData* aData, SearchData* aSearchWordData,BOOL iIsLogTrace) { - int j = 0; - int k = 0; - int count = 0; - int aSearchCount = aSearchWordData->WordCodeNum; - int aPYinNum = 0; - - int aPos = 0; - int nWord = 0; - int nPyCode = 0; - int nchar = 0; - int nextword = 0; - int value = -1; - int temp1 = 0; - int temp2 = 0; + NSInteger j = 0; + NSInteger k = 0; + NSInteger count = 0; + NSInteger aSearchCount = aSearchWordData->WordCodeNum; + NSInteger aPYinNum = 0; + + NSInteger aPos = 0; + NSInteger nWord = 0; + NSInteger nPyCode = 0; + NSInteger nchar = 0; + NSInteger nextword = 0; + NSInteger value = -1; + NSInteger temp1 = 0; + NSInteger temp2 = 0; bool isMatchAllPinYin = true; bool isMatchAllWord = true; @@ -1038,7 +1039,7 @@ int IsHit(SearchTree* tree,SearchData* aData, SearchData* aSearchWordData,BOOL i Array* iMatchTrace = &tree->iMatchTrace; - int searchPosUseCount = 0; + NSInteger searchPosUseCount = 0; if (aData->WordCodeNum<<2 > searchPosPtrMallocSize || searchPosPtrMallocSize== 0) { if (searchPosPtrArray) { free(searchPosPtrArray); @@ -1069,7 +1070,7 @@ int IsHit(SearchTree* tree,SearchData* aData, SearchData* aSearchWordData,BOOL i pos->iFather = NULL; pos->step = 1; searchPosPtrArray[count ++] = pos; - //printf("pos %d\n",pos->pos); + //prNSIntegerf("pos %d\n",pos->pos); if( aSearchCount <= 1 ) { @@ -1175,7 +1176,7 @@ int IsHit(SearchTree* tree,SearchData* aData, SearchData* aSearchWordData,BOOL i nextPos = (SearchPos*)malloc(SIZEOF_SearchPos); nextPos->pos = pos->pos; - iMatchTrace->Append(iMatchTrace,(int)nextPos); + iMatchTrace->Append(iMatchTrace,(NSInteger)nextPos); } temp1 = pos->pos; @@ -1219,7 +1220,7 @@ int IsHit(SearchTree* tree,SearchData* aData, SearchData* aSearchWordData,BOOL i /* * 确定aWordCode串的aPos位置,是否和aWord相匹配 */ -BOOL IsMatch(SearchTree* tree,WordCode* aWordCode,int nPyCode,int nchar, unsigned int aWord ) +BOOL IsMatch(SearchTree* tree,WordCode* aWordCode,NSInteger nPyCode,NSInteger nchar, NSUInteger aWord ) { WordCode* word = aWordCode; const char *pyCode = 0; @@ -1256,9 +1257,9 @@ BOOL IsMatch(SearchTree* tree,WordCode* aWordCode,int nPyCode,int nchar, unsigne } -unsigned int ChangeWordToDigit(SearchTree* tree,unsigned int Word) +NSUInteger ChangeWordToDigit(SearchTree* tree,NSUInteger Word) { - int index = 0; + NSInteger index = 0; ; if( Word >= 'A' && Word <= 'Z' ) Word = Word - 'A' + 'a'; @@ -1272,29 +1273,29 @@ unsigned int ChangeWordToDigit(SearchTree* tree,unsigned int Word) return Word; } -BOOL CompareWord(SearchTree* tree,unsigned int Word,unsigned int WordInput) +BOOL CompareWord(SearchTree* tree,NSUInteger Word,NSUInteger WordInput) { Word = ChangeWordToDigit(tree,Word); WordInput = ChangeWordToDigit(tree,WordInput); return Word == WordInput; } -BOOL Tree_GetPinYin(SearchTree* tree,int aID, u2char* aText, Array* iMatchPosInPinYin) +BOOL Tree_GetPinYin(SearchTree* tree,NSInteger aID, u2char* aText, Array* iMatchPosInPinYin) { - int i = 0; - int aPos = 0; - int nWord = 0; - int nPyCode = 0; - int nchar = 0; - int aPyCodeNum = 0; - int index = 0; - int k = 0; - - int len = 0; - int temp = 0; - int iMatchNum = 0; - int iMatchIndex = 0; - int count = 0; + NSInteger i = 0; + NSInteger aPos = 0; + NSInteger nWord = 0; + NSInteger nPyCode = 0; + NSInteger nchar = 0; + NSInteger aPyCodeNum = 0; + NSInteger index = 0; + NSInteger k = 0; + + NSInteger len = 0; + NSInteger temp = 0; + NSInteger iMatchNum = 0; + NSInteger iMatchIndex = 0; + NSInteger count = 0; WordCode code; const char *pyCode = NULL; @@ -1390,13 +1391,13 @@ BOOL Tree_GetPinYin(SearchTree* tree,int aID, u2char* aText, Array* iMatchPosInP return TRUE; } -BOOL Tree_GetPhoneNum(SearchTree* tree,int aID, u2char* aText, Array* iMatchPosInPhoneNum) +BOOL Tree_GetPhoneNum(SearchTree* tree,NSInteger aID, u2char* aText, Array* iMatchPosInPhoneNum) { - int i = 0; - int len = 0; + NSInteger i = 0; + NSInteger len = 0; u2char* buf = 0; u2char* ptr = 0; - unsigned int temp = 0; + NSUInteger temp = 0; SearchData *data = NULL; SearchData *iCurSeachData = tree->iCurSeachData; u2char word; @@ -1426,12 +1427,12 @@ BOOL Tree_GetPhoneNum(SearchTree* tree,int aID, u2char* aText, Array* iMatchPosI return TRUE; } -SearchPos* GetSearchPos(int index) +SearchPos* GetSearchPos(NSInteger index) { SearchPos *ptr = NULL; if (index > searchPosMallocSize || searchPosMallocSize == 0) { searchPosMalloc = (SearchPos*)malloc(SIZEOF_SearchPos*KSearchPosMalloc); - searchPosMallocArray.Append(&searchPosMallocArray,(int)searchPosMalloc); + searchPosMallocArray.Append(&searchPosMallocArray,(NSInteger)searchPosMalloc); searchPosMallocSize += KSearchPosMalloc; } @@ -1471,7 +1472,7 @@ void FreeSearchPos(SearchPos* data) void FreeSearchTree(SearchTree* tree) { - int i = 0; + NSInteger i = 0; Array* cache = 0; if( tree->iMatchFunc ) { free(tree->iMatchFunc); @@ -1518,7 +1519,7 @@ void ReleaseMultiPYinWords() //释放多音字 if( iIsMultiPYinWordsLoaded ) { - int i = 0; + NSInteger i = 0; for( i = 0;i < iMultiPyCodeSorted.size;i ++) FreeWordCode((WordCode*)iMultiPyCodeSorted.GetValue(&iMultiPyCodeSorted,i)); diff --git a/SearchCore/SearchCoreManager.mm b/SearchCore/SearchCoreManager.mm index c6adb94..447f393 100644 --- a/SearchCore/SearchCoreManager.mm +++ b/SearchCore/SearchCoreManager.mm @@ -26,7 +26,8 @@ - (id)init { SearchTreeInit(&iSearchTree); NSString *multiPYinpath = [[NSBundle mainBundle] pathForResource:@"multipy_unicode" ofType:@"dat"]; LoadMultiPYinWords([multiPYinpath UTF8String]); - separateWord = [[NSString stringWithFormat:@"%c",KSeparateWord] retain]; +// separateWord = [[NSString stringWithFormat:@"%c",KSeparateWord] retain]; + separateWord = [NSString stringWithFormat:@"%c",KSeparateWord]; } return self; } @@ -35,11 +36,11 @@ - (void)SetMatchFunction:(NSString*) matchFunc { if (matchFunction==matchFunc || [matchFunction isEqualToString:matchFunc]) { return; } - if (matchFunction) { - [matchFunction release]; - } - matchFunction = [matchFunc retain]; - +// if (matchFunction) { +// [matchFunction release]; +// } +// matchFunction = [matchFunc retain]; + matchFunction = matchFunc; u2char buf[256]; [self string_u2char:matchFunc u2char:buf]; @@ -50,7 +51,7 @@ - (void)SetMatchFunction:(NSString*) matchFunc { //string 转 u2char - (void)string_u2char:(NSString*)src u2char:(u2char*)des { u2char* ptr = des; - for (int i = 0; i < [src length]; i ++) { + for (NSInteger i = 0; i < [src length]; i ++) { unichar word = [src characterAtIndex:i]; *ptr = word; ptr ++; @@ -62,16 +63,16 @@ - (void)string_u2char:(NSString*)src u2char:(u2char*)des { - (void)ArrayToNSArray:(Array*)array NSArray:(NSMutableArray*)arrayDes { [arrayDes removeAllObjects]; - for (int i = 0; i < array->size; i ++) { - int aID = array->GetValue(array,i); - [arrayDes addObject:[NSNumber numberWithInt:aID]]; + for (NSInteger i = 0; i < array->size; i ++) { + NSInteger aID = array->GetValue(array,i); + [arrayDes addObject:[NSNumber numberWithInteger:aID]]; } } - (void)AddContact:(NSNumber*)localID name:(NSString*)name phone:(NSArray*)phoneArray { //将联系人的号码用分隔符拼接添加到搜索,不直接用Array,为了优化号码搜索(KMP复杂度M+N) NSMutableString *phoneStr = [[NSMutableString alloc] init]; - for (int i = 0; i < [phoneArray count]; i ++) { + for (NSInteger i = 0; i < [phoneArray count]; i ++) { NSString *phone = [phoneArray objectAtIndex:i]; [phoneStr appendString:phone]; [phoneStr appendString:separateWord]; @@ -85,13 +86,13 @@ - (void)AddContact:(NSNumber*)localID name:(NSString*)name phone:(NSArray*)phone Tree_AddData(&iSearchTree,[localID intValue],nameBuf,phoneBuf); - [phoneStr release]; +// [phoneStr release]; } - (void)ReplaceContact:(NSNumber*)localID name:(NSString*)name phone:(NSArray*)phoneArray { NSMutableString *phoneStr = [[NSMutableString alloc] init]; - for (int i = 0; i < [phoneArray count]; i ++) { + for (NSInteger i = 0; i < [phoneArray count]; i ++) { NSString *phone = [phoneArray objectAtIndex:i]; [phoneStr appendString:phone]; [phoneStr appendString:separateWord]; @@ -105,7 +106,7 @@ - (void)ReplaceContact:(NSNumber*)localID name:(NSString*)name phone:(NSArray*)p Tree_ReplaceData(&iSearchTree,[localID intValue],nameBuf,phoneBuf); - [phoneStr release]; +// [phoneStr release]; } - (void)DeleteContact:(NSNumber*)localID { @@ -124,7 +125,7 @@ - (void)SearchDefault:(NSString*)searchText searchArray:(NSArray*)aSearchedArray searchedArray = new Array; ArrayInit(searchedArray); - for (int i = 0; i < [aSearchedArray count]; i ++) { + for (NSInteger i = 0; i < [aSearchedArray count]; i ++) { NSNumber *number = [aSearchedArray objectAtIndex:i]; searchedArray->Append(searchedArray,[number intValue]); } @@ -189,7 +190,7 @@ - (BOOL)GetPinYin:(NSNumber*)localID pinYin:(NSMutableString*)pinyinDes matchPos BOOL result = Tree_GetPinYin(&iSearchTree,[localID intValue],pinyinBuf,aMatchPosInPinYin); - int length = u2slen(pinyinBuf); + NSInteger length = u2slen(pinyinBuf); [pinyinDes appendString:[NSString stringWithCharacters:(unichar*)pinyinBuf length:length]]; if (aMatchPosInPinYin) { @@ -204,7 +205,7 @@ - (BOOL)GetPinYin:(NSNumber*)localID pinYin:(NSMutableString*)pinyinDes matchPos //用分隔符拼接的号码,转换到原有的样式,提取匹配的号码及匹配位置 - (void) ChangeToOranagePhones:(NSString*)phones matchPos:(NSArray*)matchPos phoneArray:(NSMutableArray*)phoneArray matchPosArray:(NSMutableArray*)matchPosArray { - int start = [[matchPos objectAtIndex:0] intValue]; + NSInteger start = [[matchPos objectAtIndex:0] intValue]; while (start >= 0) { unichar word = [phones characterAtIndex:start]; if (word == KSeparateWord) { @@ -214,7 +215,7 @@ - (void) ChangeToOranagePhones:(NSString*)phones matchPos:(NSArray*)matchPos pho } start ++; - int end = [[matchPos objectAtIndex:matchPos.count-1] intValue]; + NSInteger end = [[matchPos objectAtIndex:matchPos.count-1] intValue]; while (end < [phones length]) { unichar word = [phones characterAtIndex:end]; if (word == KSeparateWord) { @@ -226,14 +227,14 @@ - (void) ChangeToOranagePhones:(NSString*)phones matchPos:(NSArray*)matchPos pho NSString *phone = [phones substringWithRange:range]; NSMutableArray *matchPosDes = [[NSMutableArray alloc] init]; - for (int i = 0; i < [matchPos count]; i ++) { - int pos = [[matchPos objectAtIndex:i] intValue]; + for (NSInteger i = 0; i < [matchPos count]; i ++) { + NSInteger pos = [[matchPos objectAtIndex:i] intValue]; pos -= start; - [matchPosDes addObject:[NSNumber numberWithInt:pos]]; + [matchPosDes addObject:[NSNumber numberWithInteger:pos]]; } [phoneArray addObject:phone]; [matchPosArray addObject:matchPosDes]; - [matchPosDes release]; +// [matchPosDes release]; } - (BOOL)GetPhoneNum:(NSNumber*)localID phone:(NSMutableArray*)phoneArray matchPos:(NSMutableArray*)matchPosArray { @@ -251,7 +252,7 @@ - (BOOL)GetPhoneNum:(NSNumber*)localID phone:(NSMutableArray*)phoneArray matchPo NSMutableString *phoneDes = [[NSMutableString alloc] init]; NSMutableArray *matchPos = [[NSMutableArray alloc] init]; BOOL result = Tree_GetPhoneNum(&iSearchTree,[localID intValue],(u2char*)phoneBuf,aMatchPosInPhoneNum); - int length = u2slen(phoneBuf); + NSInteger length = u2slen(phoneBuf); [phoneDes appendString:[NSString stringWithCharacters:(unichar*)phoneBuf length:length]]; if (aMatchPosInPhoneNum) { [self ArrayToNSArray:aMatchPosInPhoneNum NSArray:matchPos]; @@ -261,15 +262,15 @@ - (BOOL)GetPhoneNum:(NSNumber*)localID phone:(NSMutableArray*)phoneArray matchPo [self ChangeToOranagePhones:phoneDes matchPos:matchPos phoneArray:phoneArray matchPosArray:matchPosArray]; - [phoneDes release]; - [matchPos release]; +// [phoneDes release]; +// [matchPos release]; return result; } - (void)Reset { - if (matchFunction) { - [matchFunction release]; - } +// if (matchFunction) { +// [matchFunction release]; +// } FreeSearchTree(&iSearchTree); SearchTreeInit(&iSearchTree); @@ -281,13 +282,13 @@ - (void)dealloc { //释放搜索库 FreeSearchTree(&iSearchTree); - if (separateWord) { - [separateWord release]; - } - if (matchFunction) { - [matchFunction release]; - } +// if (separateWord) { +// [separateWord release]; +// } +// if (matchFunction) { +// [matchFunction release]; +// } - [super dealloc]; +// [super dealloc]; } -@end \ No newline at end of file +@end diff --git a/SearchCoreTest.xcodeproj/project.pbxproj b/SearchCoreTest.xcodeproj/project.pbxproj index 11aa1a2..24c6540 100644 --- a/SearchCoreTest.xcodeproj/project.pbxproj +++ b/SearchCoreTest.xcodeproj/project.pbxproj @@ -164,7 +164,7 @@ 9AF539F516B65398008510DF /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0450; + LastUpgradeCheck = 0730; ORGANIZATIONNAME = kewenya; }; buildConfigurationList = 9AF539F816B65398008510DF /* Build configuration list for PBXProject "SearchCoreTest" */; @@ -247,6 +247,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; @@ -259,6 +260,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 6.0; + ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; }; name = Debug; @@ -287,9 +289,11 @@ 9AF53A2316B65398008510DF /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_ARC = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "SearchCoreTest/SearchCoreTest-Prefix.pch"; INFOPLIST_FILE = "SearchCoreTest/SearchCoreTest-Info.plist"; + PRODUCT_BUNDLE_IDENTIFIER = "kewenya.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; @@ -298,9 +302,11 @@ 9AF53A2416B65398008510DF /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_ARC = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "SearchCoreTest/SearchCoreTest-Prefix.pch"; INFOPLIST_FILE = "SearchCoreTest/SearchCoreTest-Info.plist"; + PRODUCT_BUNDLE_IDENTIFIER = "kewenya.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; diff --git a/SearchCoreTest.xcodeproj/project.xcworkspace/xcuserdata/Mathisonz.xcuserdatad/UserInterfaceState.xcuserstate b/SearchCoreTest.xcodeproj/project.xcworkspace/xcuserdata/Mathisonz.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..6ab015f Binary files /dev/null and b/SearchCoreTest.xcodeproj/project.xcworkspace/xcuserdata/Mathisonz.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/SearchCoreTest.xcodeproj/xcuserdata/Mathisonz.xcuserdatad/xcschemes/SearchCoreTest.xcscheme b/SearchCoreTest.xcodeproj/xcuserdata/Mathisonz.xcuserdatad/xcschemes/SearchCoreTest.xcscheme new file mode 100644 index 0000000..a013875 --- /dev/null +++ b/SearchCoreTest.xcodeproj/xcuserdata/Mathisonz.xcuserdatad/xcschemes/SearchCoreTest.xcscheme @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SearchCoreTest.xcodeproj/xcuserdata/Mathisonz.xcuserdatad/xcschemes/xcschememanagement.plist b/SearchCoreTest.xcodeproj/xcuserdata/Mathisonz.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..6cdc761 --- /dev/null +++ b/SearchCoreTest.xcodeproj/xcuserdata/Mathisonz.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,22 @@ + + + + + SchemeUserState + + SearchCoreTest.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + 9AF539FD16B65398008510DF + + primary + + + + + diff --git a/SearchCoreTest/AppDelegate.m b/SearchCoreTest/AppDelegate.m index 53bacd0..cd132e6 100644 --- a/SearchCoreTest/AppDelegate.m +++ b/SearchCoreTest/AppDelegate.m @@ -12,18 +12,23 @@ @implementation AppDelegate -- (void)dealloc -{ - [_window release]; - [_viewController release]; - [super dealloc]; -} +//- (void)dealloc +//{ +// [_window release]; +// [_viewController release]; +// [super dealloc]; +//} - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; +// self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; +// // Override point for customization after application launch. +// self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease]; + + self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. - self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease]; + self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; + self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; return YES; diff --git a/SearchCoreTest/ContactPeople.m b/SearchCoreTest/ContactPeople.m index 9eb135c..9800e02 100644 --- a/SearchCoreTest/ContactPeople.m +++ b/SearchCoreTest/ContactPeople.m @@ -13,13 +13,13 @@ @implementation ContactPeople @synthesize name; @synthesize phoneArray; -- (void)dealloc -{ - self.localID = nil; - self.name = nil; - self.phoneArray = nil; - - [super dealloc]; -} +//- (void)dealloc +//{ +// self.localID = nil; +// self.name = nil; +// self.phoneArray = nil; +// +// [super dealloc]; +//} @end diff --git a/SearchCoreTest/SearchCoreTest-Info.plist b/SearchCoreTest/SearchCoreTest-Info.plist index a4fc633..5860c3f 100644 --- a/SearchCoreTest/SearchCoreTest-Info.plist +++ b/SearchCoreTest/SearchCoreTest-Info.plist @@ -9,7 +9,7 @@ CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier - kewenya.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/SearchCoreTest/ViewController.m b/SearchCoreTest/ViewController.m index 4700565..0a593c4 100644 --- a/SearchCoreTest/ViewController.m +++ b/SearchCoreTest/ViewController.m @@ -22,14 +22,16 @@ @implementation ViewController @synthesize searchByPhone; - (void)tableViewInit { - self.tableView = [[[UITableView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f-44.0f)] autorelease]; +// self.tableView = [[[UITableView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f-44.0f)] autorelease]; + self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f-44.0f)]; self.tableView.dataSource=self; self.tableView.delegate=self; self.tableView.backgroundColor=[UIColor clearColor]; [self.view addSubview:self.tableView]; } - (void)searchBarInit { - self.searchBar = [[[UISearchBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 310.0f, 44.0f)] autorelease]; +// self.searchBar = [[[UISearchBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 310.0f, 44.0f)] autorelease]; + self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 310.0f, 44.0f)]; self.searchBar.autocorrectionType = UITextAutocorrectionTypeNo; self.searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone; @@ -53,34 +55,34 @@ - (void)viewDidLoad NSMutableDictionary *dic = [[NSMutableDictionary alloc] init]; self.contactDic = dic; - [dic release]; +// [dic release]; NSMutableArray *nameIDArray = [[NSMutableArray alloc] init]; self.searchByName = nameIDArray; - [nameIDArray release]; +// [nameIDArray release]; NSMutableArray *phoneIDArray = [[NSMutableArray alloc] init]; self.searchByPhone = phoneIDArray; - [phoneIDArray release]; +// [phoneIDArray release]; ContactPeople *contact = [[ContactPeople alloc] init]; contact.localID = [NSNumber numberWithInt:0]; - contact.name = @"西藏"; + contact.name = @"长江"; NSMutableArray *phoneArray = [[NSMutableArray alloc] init]; [phoneArray addObject:@"13800138000"]; [phoneArray addObject:@"10086"]; contact.phoneArray = phoneArray; - [phoneArray release]; +// [phoneArray release]; [self.contactDic setObject:contact forKey:contact.localID]; //添加到搜索库 [[SearchCoreManager share] AddContact:contact.localID name:contact.name phone:contact.phoneArray]; - [contact release]; +// [contact release]; for (int i = 1; i < 20; i ++) { @@ -89,7 +91,7 @@ - (void)viewDidLoad contact.name = [NSString stringWithFormat:@"测试%d",i]; [[SearchCoreManager share] AddContact:contact.localID name:contact.name phone:contact.phoneArray]; [self.contactDic setObject:contact forKey:contact.localID]; - [contact release]; +// [contact release]; } } @@ -117,7 +119,8 @@ - (UITableViewCell *)tableView:(UITableView *)_tableView cellForRowAtIndexPath:( static NSString *indentifier = @"Cell"; UITableViewCell *cell = (UITableViewCell*)[_tableView dequeueReusableCellWithIdentifier:indentifier]; if (cell == nil) { - cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:indentifier] autorelease]; +// cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:indentifier] autorelease]; + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:indentifier]; cell.selectionStyle=UITableViewCellSelectionStyleBlue; }