Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
对原来的SearchCoreTest进行修改,将部分int换成NSIntger,以支持64位
****************************华丽丽的分隔线*************************************
SearchCoreTest
==============
Author: kewenya
Expand Down
55 changes: 27 additions & 28 deletions SearchCore/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
============================================================================
*/


#include <stdio.h>
#include <stdlib.h>

Expand All @@ -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
64 changes: 32 additions & 32 deletions SearchCore/Array.mm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Array.h"

int sizeof_int = sizeof(int);
NSInteger sizeof_int = sizeof(NSInteger);

void ArrayInit(struct Array* A)
{
Expand All @@ -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 )
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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));
Expand All @@ -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 ++;
Expand All @@ -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)
{
Expand All @@ -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 )
{
Expand All @@ -214,20 +214,20 @@ 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);

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;
}
42 changes: 21 additions & 21 deletions SearchCore/SearchCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -122,21 +122,21 @@ 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);

/*
* 修改数据源信息
* aID: 数据索引ID
* 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 );

/*
* 搜索数据
Expand All @@ -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 ==============================================
Expand All @@ -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编码
Expand All @@ -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);
Expand Down
Loading