亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? fts1_hash.c

?? sqlite 3.3.8 支持加密的版本
?? C
字號:
/*
** 2001 September 22
**
** The author disclaims copyright to this source code.  In place of
** a legal notice, here is a blessing:
**
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This is the implementation of generic hash-tables used in SQLite.
** We've modified it slightly to serve as a standalone hash table
** implementation for the full-text indexing module.
*/
#include <assert.h>
#include <stdlib.h>
#include <string.h>

/*
** The code in this file is only compiled if:
**
**     * The FTS1 module is being built as an extension
**       (in which case SQLITE_CORE is not defined), or
**
**     * The FTS1 module is being built into the core of
**       SQLite (in which case SQLITE_ENABLE_FTS1 is defined).
*/
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS1)


#include "fts1_hash.h"

static void *malloc_and_zero(int n){
  void *p = malloc(n);
  if( p ){
    memset(p, 0, n);
  }
  return p;
}

/* Turn bulk memory into a hash table object by initializing the
** fields of the Hash structure.
**
** "pNew" is a pointer to the hash table that is to be initialized.
** keyClass is one of the constants 
** FTS1_HASH_BINARY or FTS1_HASH_STRING.  The value of keyClass 
** determines what kind of key the hash table will use.  "copyKey" is
** true if the hash table should make its own private copy of keys and
** false if it should just use the supplied pointer.
*/
void sqlite3Fts1HashInit(fts1Hash *pNew, int keyClass, int copyKey){
  assert( pNew!=0 );
  assert( keyClass>=FTS1_HASH_STRING && keyClass<=FTS1_HASH_BINARY );
  pNew->keyClass = keyClass;
  pNew->copyKey = copyKey;
  pNew->first = 0;
  pNew->count = 0;
  pNew->htsize = 0;
  pNew->ht = 0;
  pNew->xMalloc = malloc_and_zero;
  pNew->xFree = free;
}

/* Remove all entries from a hash table.  Reclaim all memory.
** Call this routine to delete a hash table or to reset a hash table
** to the empty state.
*/
void sqlite3Fts1HashClear(fts1Hash *pH){
  fts1HashElem *elem;         /* For looping over all elements of the table */

  assert( pH!=0 );
  elem = pH->first;
  pH->first = 0;
  if( pH->ht ) pH->xFree(pH->ht);
  pH->ht = 0;
  pH->htsize = 0;
  while( elem ){
    fts1HashElem *next_elem = elem->next;
    if( pH->copyKey && elem->pKey ){
      pH->xFree(elem->pKey);
    }
    pH->xFree(elem);
    elem = next_elem;
  }
  pH->count = 0;
}

/*
** Hash and comparison functions when the mode is FTS1_HASH_STRING
*/
static int strHash(const void *pKey, int nKey){
  const char *z = (const char *)pKey;
  int h = 0;
  if( nKey<=0 ) nKey = (int) strlen(z);
  while( nKey > 0  ){
    h = (h<<3) ^ h ^ *z++;
    nKey--;
  }
  return h & 0x7fffffff;
}
static int strCompare(const void *pKey1, int n1, const void *pKey2, int n2){
  if( n1!=n2 ) return 1;
  return strncmp((const char*)pKey1,(const char*)pKey2,n1);
}

/*
** Hash and comparison functions when the mode is FTS1_HASH_BINARY
*/
static int binHash(const void *pKey, int nKey){
  int h = 0;
  const char *z = (const char *)pKey;
  while( nKey-- > 0 ){
    h = (h<<3) ^ h ^ *(z++);
  }
  return h & 0x7fffffff;
}
static int binCompare(const void *pKey1, int n1, const void *pKey2, int n2){
  if( n1!=n2 ) return 1;
  return memcmp(pKey1,pKey2,n1);
}

/*
** Return a pointer to the appropriate hash function given the key class.
**
** The C syntax in this function definition may be unfamilar to some 
** programmers, so we provide the following additional explanation:
**
** The name of the function is "hashFunction".  The function takes a
** single parameter "keyClass".  The return value of hashFunction()
** is a pointer to another function.  Specifically, the return value
** of hashFunction() is a pointer to a function that takes two parameters
** with types "const void*" and "int" and returns an "int".
*/
static int (*hashFunction(int keyClass))(const void*,int){
  if( keyClass==FTS1_HASH_STRING ){
    return &strHash;
  }else{
    assert( keyClass==FTS1_HASH_BINARY );
    return &binHash;
  }
}

/*
** Return a pointer to the appropriate hash function given the key class.
**
** For help in interpreted the obscure C code in the function definition,
** see the header comment on the previous function.
*/
static int (*compareFunction(int keyClass))(const void*,int,const void*,int){
  if( keyClass==FTS1_HASH_STRING ){
    return &strCompare;
  }else{
    assert( keyClass==FTS1_HASH_BINARY );
    return &binCompare;
  }
}

/* Link an element into the hash table
*/
static void insertElement(
  fts1Hash *pH,            /* The complete hash table */
  struct _fts1ht *pEntry,  /* The entry into which pNew is inserted */
  fts1HashElem *pNew       /* The element to be inserted */
){
  fts1HashElem *pHead;     /* First element already in pEntry */
  pHead = pEntry->chain;
  if( pHead ){
    pNew->next = pHead;
    pNew->prev = pHead->prev;
    if( pHead->prev ){ pHead->prev->next = pNew; }
    else             { pH->first = pNew; }
    pHead->prev = pNew;
  }else{
    pNew->next = pH->first;
    if( pH->first ){ pH->first->prev = pNew; }
    pNew->prev = 0;
    pH->first = pNew;
  }
  pEntry->count++;
  pEntry->chain = pNew;
}


/* Resize the hash table so that it cantains "new_size" buckets.
** "new_size" must be a power of 2.  The hash table might fail 
** to resize if sqliteMalloc() fails.
*/
static void rehash(fts1Hash *pH, int new_size){
  struct _fts1ht *new_ht;          /* The new hash table */
  fts1HashElem *elem, *next_elem;  /* For looping over existing elements */
  int (*xHash)(const void*,int);   /* The hash function */

  assert( (new_size & (new_size-1))==0 );
  new_ht = (struct _fts1ht *)pH->xMalloc( new_size*sizeof(struct _fts1ht) );
  if( new_ht==0 ) return;
  if( pH->ht ) pH->xFree(pH->ht);
  pH->ht = new_ht;
  pH->htsize = new_size;
  xHash = hashFunction(pH->keyClass);
  for(elem=pH->first, pH->first=0; elem; elem = next_elem){
    int h = (*xHash)(elem->pKey, elem->nKey) & (new_size-1);
    next_elem = elem->next;
    insertElement(pH, &new_ht[h], elem);
  }
}

/* This function (for internal use only) locates an element in an
** hash table that matches the given key.  The hash for this key has
** already been computed and is passed as the 4th parameter.
*/
static fts1HashElem *findElementGivenHash(
  const fts1Hash *pH, /* The pH to be searched */
  const void *pKey,   /* The key we are searching for */
  int nKey,
  int h               /* The hash for this key. */
){
  fts1HashElem *elem;            /* Used to loop thru the element list */
  int count;                     /* Number of elements left to test */
  int (*xCompare)(const void*,int,const void*,int);  /* comparison function */

  if( pH->ht ){
    struct _fts1ht *pEntry = &pH->ht[h];
    elem = pEntry->chain;
    count = pEntry->count;
    xCompare = compareFunction(pH->keyClass);
    while( count-- && elem ){
      if( (*xCompare)(elem->pKey,elem->nKey,pKey,nKey)==0 ){ 
        return elem;
      }
      elem = elem->next;
    }
  }
  return 0;
}

/* Remove a single entry from the hash table given a pointer to that
** element and a hash on the element's key.
*/
static void removeElementGivenHash(
  fts1Hash *pH,         /* The pH containing "elem" */
  fts1HashElem* elem,   /* The element to be removed from the pH */
  int h                 /* Hash value for the element */
){
  struct _fts1ht *pEntry;
  if( elem->prev ){
    elem->prev->next = elem->next; 
  }else{
    pH->first = elem->next;
  }
  if( elem->next ){
    elem->next->prev = elem->prev;
  }
  pEntry = &pH->ht[h];
  if( pEntry->chain==elem ){
    pEntry->chain = elem->next;
  }
  pEntry->count--;
  if( pEntry->count<=0 ){
    pEntry->chain = 0;
  }
  if( pH->copyKey && elem->pKey ){
    pH->xFree(elem->pKey);
  }
  pH->xFree( elem );
  pH->count--;
  if( pH->count<=0 ){
    assert( pH->first==0 );
    assert( pH->count==0 );
    fts1HashClear(pH);
  }
}

/* Attempt to locate an element of the hash table pH with a key
** that matches pKey,nKey.  Return the data for this element if it is
** found, or NULL if there is no match.
*/
void *sqlite3Fts1HashFind(const fts1Hash *pH, const void *pKey, int nKey){
  int h;                 /* A hash on key */
  fts1HashElem *elem;    /* The element that matches key */
  int (*xHash)(const void*,int);  /* The hash function */

  if( pH==0 || pH->ht==0 ) return 0;
  xHash = hashFunction(pH->keyClass);
  assert( xHash!=0 );
  h = (*xHash)(pKey,nKey);
  assert( (pH->htsize & (pH->htsize-1))==0 );
  elem = findElementGivenHash(pH,pKey,nKey, h & (pH->htsize-1));
  return elem ? elem->data : 0;
}

/* Insert an element into the hash table pH.  The key is pKey,nKey
** and the data is "data".
**
** If no element exists with a matching key, then a new
** element is created.  A copy of the key is made if the copyKey
** flag is set.  NULL is returned.
**
** If another element already exists with the same key, then the
** new data replaces the old data and the old data is returned.
** The key is not copied in this instance.  If a malloc fails, then
** the new data is returned and the hash table is unchanged.
**
** If the "data" parameter to this function is NULL, then the
** element corresponding to "key" is removed from the hash table.
*/
void *sqlite3Fts1HashInsert(
  fts1Hash *pH,        /* The hash table to insert into */
  const void *pKey,    /* The key */
  int nKey,            /* Number of bytes in the key */
  void *data           /* The data */
){
  int hraw;                 /* Raw hash value of the key */
  int h;                    /* the hash of the key modulo hash table size */
  fts1HashElem *elem;       /* Used to loop thru the element list */
  fts1HashElem *new_elem;   /* New element added to the pH */
  int (*xHash)(const void*,int);  /* The hash function */

  assert( pH!=0 );
  xHash = hashFunction(pH->keyClass);
  assert( xHash!=0 );
  hraw = (*xHash)(pKey, nKey);
  assert( (pH->htsize & (pH->htsize-1))==0 );
  h = hraw & (pH->htsize-1);
  elem = findElementGivenHash(pH,pKey,nKey,h);
  if( elem ){
    void *old_data = elem->data;
    if( data==0 ){
      removeElementGivenHash(pH,elem,h);
    }else{
      elem->data = data;
    }
    return old_data;
  }
  if( data==0 ) return 0;
  new_elem = (fts1HashElem*)pH->xMalloc( sizeof(fts1HashElem) );
  if( new_elem==0 ) return data;
  if( pH->copyKey && pKey!=0 ){
    new_elem->pKey = pH->xMalloc( nKey );
    if( new_elem->pKey==0 ){
      pH->xFree(new_elem);
      return data;
    }
    memcpy((void*)new_elem->pKey, pKey, nKey);
  }else{
    new_elem->pKey = (void*)pKey;
  }
  new_elem->nKey = nKey;
  pH->count++;
  if( pH->htsize==0 ){
    rehash(pH,8);
    if( pH->htsize==0 ){
      pH->count = 0;
      pH->xFree(new_elem);
      return data;
    }
  }
  if( pH->count > pH->htsize ){
    rehash(pH,pH->htsize*2);
  }
  assert( pH->htsize>0 );
  assert( (pH->htsize & (pH->htsize-1))==0 );
  h = hraw & (pH->htsize-1);
  insertElement(pH, &pH->ht[h], new_elem);
  new_elem->data = data;
  return 0;
}

#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS1) */

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
色系网站成人免费| 成人免费高清在线观看| 91麻豆高清视频| 日韩免费观看高清完整版| 亚洲欧美日韩精品久久久久| 激情六月婷婷久久| 91精品国产91久久久久久最新毛片| 国产精品久线观看视频| 国产成人在线免费| 久久久久久日产精品| 日本中文字幕一区二区视频| 欧美亚洲日本国产| 亚洲免费电影在线| 色婷婷av久久久久久久| 中文字幕在线观看一区二区| 波多野洁衣一区| 日本一区二区不卡视频| 丁香天五香天堂综合| 久久你懂得1024| 国产精品亚洲专一区二区三区 | 久久蜜桃香蕉精品一区二区三区| 调教+趴+乳夹+国产+精品| 欧美日韩一区高清| 蜜臀久久99精品久久久久久9| 欧美一区二视频| 国产综合成人久久大片91| 久久亚洲一级片| 不卡一区二区三区四区| 亚洲免费三区一区二区| 欧美精品v日韩精品v韩国精品v| 日韩高清中文字幕一区| 欧美成人艳星乳罩| 成人国产在线观看| 亚洲成人av资源| 久久婷婷综合激情| 91美女蜜桃在线| 美女看a上一区| 国产精品麻豆网站| 6080日韩午夜伦伦午夜伦| 国产在线不卡一区| 亚洲福利视频导航| 精品国产乱码久久久久久久久| 国产91清纯白嫩初高中在线观看| 亚洲久草在线视频| 欧美不卡123| 在线亚洲一区二区| 久久97超碰色| 亚洲一区在线观看免费观看电影高清| 欧美一区二区黄色| 色94色欧美sute亚洲13| 国产一区二区电影| 亚洲国产精品一区二区久久恐怖片 | 国产欧美久久久精品影院| 欧美中文字幕一二三区视频| 久久国产综合精品| 亚洲大片免费看| 亚洲欧美在线aaa| 国产日韩欧美不卡在线| 欧美一级夜夜爽| 色视频欧美一区二区三区| 国产成人在线视频网站| 蜜臀久久久99精品久久久久久| 一区二区三区日韩精品| 国产精品麻豆久久久| 国产香蕉久久精品综合网| 日韩欧美国产一二三区| 欧美精品日韩精品| 欧美日韩二区三区| 欧美吞精做爰啪啪高潮| 日本韩国精品在线| 欧美性受xxxx| 欧美三级韩国三级日本一级| 欧美性生活久久| 欧美影视一区二区三区| 在线观看日韩高清av| 91在线看国产| 欧美在线啊v一区| 欧美性极品少妇| 51午夜精品国产| 精品国产自在久精品国产| 久久久久99精品一区| 久久精品一区二区三区不卡牛牛| 国产亚洲女人久久久久毛片| 国产精品色婷婷久久58| 亚洲男人的天堂在线aⅴ视频| 亚洲色图20p| 视频在线观看国产精品| 精品一区二区久久| fc2成人免费人成在线观看播放| 色综合天天综合| 777午夜精品免费视频| 久久蜜桃av一区二区天堂| 亚洲手机成人高清视频| 亚洲一区免费观看| 久久99久久99小草精品免视看| 国产成人激情av| 欧美日韩久久久一区| 日韩一区二区免费视频| 国产精品美女久久久久aⅴ| 亚洲一级二级三级在线免费观看| 美国三级日本三级久久99| 成人理论电影网| 欧美电影免费观看高清完整版 | 国产一区视频导航| 在线视频观看一区| 精品av久久707| 亚洲一区电影777| 高清在线观看日韩| 日韩精品一区二区三区三区免费| 99久久综合精品| 经典一区二区三区| 成人精品高清在线| 日韩精品一区二区三区在线观看 | 中文字幕精品—区二区四季| 亚洲国产成人tv| 色呦呦日韩精品| 日本一区二区三区视频视频| 久久精品国产77777蜜臀| 在线视频一区二区免费| 亚洲少妇最新在线视频| 国产成人精品亚洲777人妖 | 欧美综合亚洲图片综合区| 国产精品传媒入口麻豆| 国产经典欧美精品| 日韩美女天天操| 美女mm1313爽爽久久久蜜臀| 欧美男女性生活在线直播观看| 亚洲免费在线看| 色诱视频网站一区| 玉米视频成人免费看| 91久久精品网| 日韩国产在线观看| 日韩一区二区三区电影在线观看| 日韩精品电影在线观看| 日韩欧美一区在线| 激情成人综合网| 亚洲国产电影在线观看| 成人av手机在线观看| √…a在线天堂一区| 色综合久久久久久久久久久| 亚洲一区二区三区四区的| 欧洲av一区二区嗯嗯嗯啊| 免费在线观看精品| 精品电影一区二区| 99久久久精品免费观看国产蜜| 亚洲精品国产a久久久久久| 欧美丰满美乳xxx高潮www| 九九久久精品视频| 亚洲图片另类小说| 7777精品伊人久久久大香线蕉经典版下载 | 精品国产伦一区二区三区观看体验| 国产综合色产在线精品| 亚洲图片你懂的| 欧美一区二区精美| www.欧美.com| 麻豆精品国产91久久久久久| 国产精品久久久爽爽爽麻豆色哟哟 | 欧美色手机在线观看| 国产一区二区三区电影在线观看| 中文字幕亚洲视频| 精品国一区二区三区| 91美女在线视频| 国产精品18久久久| 日韩不卡一区二区| 亚洲欧美日韩综合aⅴ视频| 日韩一区二区视频| 日本高清免费不卡视频| 精品一二三四区| 日韩高清不卡一区| 亚洲综合免费观看高清完整版在线| 欧美精品第一页| 91蜜桃免费观看视频| 大胆亚洲人体视频| 国产真实乱偷精品视频免| 午夜私人影院久久久久| 亚洲图片欧美激情| 成人欧美一区二区三区视频网页| 精品福利av导航| 日韩一区二区免费视频| 宅男在线国产精品| 欧美日韩免费在线视频| 91国偷自产一区二区开放时间| 成人午夜av电影| 高清beeg欧美| 成人a级免费电影| 北岛玲一区二区三区四区| 懂色av噜噜一区二区三区av | 精品国产免费一区二区三区四区| 欧美在线观看视频一区二区| 色猫猫国产区一区二在线视频| 成人高清av在线| 91小视频在线免费看| 在线视频你懂得一区| 欧美日韩精品一区二区三区蜜桃| 欧美艳星brazzers| 91麻豆精品国产| 精品国产一区二区亚洲人成毛片 | 日韩午夜在线影院| 精品国产凹凸成av人网站| 久久精品欧美日韩精品|