• 大小: 309KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-07-22
  • 语言: 其他
  • 标签:

资源简介

memcached最新服务器源代码,分析memcached最好的源代码分析材料

资源截图

代码片段和文件信息

/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
 * Hash table
 *
 * The hash function used here is by Bob Jenkins 1996:
 *    
 *       “By Bob Jenkins 1996.  bob_jenkins@burtleburtle.net.
 *       You may use this code any way you wish private educational
 *       or commercial.  It‘s free.“
 *
 * The rest of the file is licensed under the BSD license.  See LICENSE.
 */

#include “memcached.h“
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

static pthread_cond_t maintenance_cond = PTHREAD_COND_INITIALIZER;


typedef  unsigned long  int  ub4;   /* unsigned 4-byte quantities */
typedef  unsigned       char ub1;   /* unsigned 1-byte quantities */

/* how many powers of 2‘s worth of buckets we use */
static unsigned int hashpower = 16;

#define hashsize(n) ((ub4)1<<(n))
#define hashmask(n) (hashsize(n)-1)

/* Main hash table. This is where we look except during expansion. */
static item** primary_hashtable = 0;

/*
 * Previous hash table. During expansion we look here for keys that haven‘t
 * been moved over to the primary yet.
 */
static item** old_hashtable = 0;

/* Number of items in the hash table. */
static unsigned int hash_items = 0;

/* Flag: Are we in the middle of expanding now? */
static bool expanding = false;

/*
 * During expansion we migrate values with bucket granularity; this is how
 * far we‘ve gotten so far. Ranges from 0 .. hashsize(hashpower - 1) - 1.
 */
static unsigned int expand_bucket = 0;

void assoc_init(void) {
    primary_hashtable = calloc(hashsize(hashpower) sizeof(void *));
    if (! primary_hashtable) {
        fprintf(stderr “Failed to init hashtable.\n“);
        exit(EXIT_FAILURE);
    }
}

item *assoc_find(const char *key const size_t nkey) {
    uint32_t hv = hash(key nkey 0);
    item *it;
    unsigned int oldbucket;

    if (expanding &&
        (oldbucket = (hv & hashmask(hashpower - 1))) >= expand_bucket)
    {
        it = old_hashtable[oldbucket];
    } else {
        it = primary_hashtable[hv & hashmask(hashpower)];
    }

    item *ret = NULL;
    int depth = 0;
    while (it) {
        if ((nkey == it->nkey) && (memcmp(key ITEM_key(it) nkey) == 0)) {
            ret = it;
            break;
        }
        it = it->h_next;
        ++depth;
    }
    MEMCACHED_ASSOC_FIND(key nkey depth);
    return ret;
}

/* returns the address of the item pointer before the key.  if *item == 0
   the item wasn‘t found */

static item** _hashitem_before (const char *key const size_t nkey) {
    uint32_t hv = hash(key nkey 0);
    item **pos;
    unsigned int oldbucket;

    if (expanding &&
        (oldbucket = (hv & hashmask(hashpower - 1))) >= expand_bucket)
    {
        pos = &old_hashtable[oldbucket];
    } els

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      34189  2010-04-04 05:26  memcached-1.4.5\memcached-1.4.5\aclocal.m4

     文件       7482  2010-04-03 15:07  memcached-1.4.5\memcached-1.4.5\assoc.c

     文件        309  2010-04-03 15:07  memcached-1.4.5\memcached-1.4.5\assoc.h

     文件         69  2009-08-30 07:00  memcached-1.4.5\memcached-1.4.5\AUTHORS

     文件       3742  2009-11-25 08:40  memcached-1.4.5\memcached-1.4.5\cache.c

     文件       4304  2009-08-30 07:00  memcached-1.4.5\memcached-1.4.5\cache.h

     文件      19404  2009-08-30 07:00  memcached-1.4.5\memcached-1.4.5\ChangeLog

     文件       3707  2009-08-22 10:09  memcached-1.4.5\memcached-1.4.5\compile

     文件      46561  2010-01-07 14:56  memcached-1.4.5\memcached-1.4.5\config.guess

     文件       3103  2010-04-04 05:26  memcached-1.4.5\memcached-1.4.5\config.h.in

     文件      34179  2010-01-07 14:56  memcached-1.4.5\memcached-1.4.5\config.sub

     文件     265031  2010-04-04 05:26  memcached-1.4.5\memcached-1.4.5\configure

     文件      13893  2010-04-03 15:07  memcached-1.4.5\memcached-1.4.5\configure.ac

     文件       1503  2009-08-30 07:00  memcached-1.4.5\memcached-1.4.5\COPYING

     文件       3082  2009-08-30 07:00  memcached-1.4.5\memcached-1.4.5\daemon.c

     文件      17867  2009-08-22 10:09  memcached-1.4.5\memcached-1.4.5\depcomp

     文件       1504  2009-08-30 07:00  memcached-1.4.5\memcached-1.4.5\doc\CONTRIBUTORS

     文件      51535  2009-10-24 04:38  memcached-1.4.5\memcached-1.4.5\doc\Doxyfile

     文件      11657  2010-04-04 05:26  memcached-1.4.5\memcached-1.4.5\doc\Makefile

     文件        424  2010-04-03 15:07  memcached-1.4.5\memcached-1.4.5\doc\Makefile.am

     文件      11118  2010-04-04 05:26  memcached-1.4.5\memcached-1.4.5\doc\Makefile.in

     文件       5304  2009-10-30 09:23  memcached-1.4.5\memcached-1.4.5\doc\memcached.1

     文件       9408  2009-08-30 07:00  memcached-1.4.5\memcached-1.4.5\doc\protocol-binary-range.xml

     文件      62759  2009-11-02 15:18  memcached-1.4.5\memcached-1.4.5\doc\protocol-binary.xml

     文件      30098  2010-04-03 15:07  memcached-1.4.5\memcached-1.4.5\doc\protocol.txt

     文件         74  2009-08-30 07:00  memcached-1.4.5\memcached-1.4.5\doc\readme.txt

     文件       3556  2009-08-30 07:00  memcached-1.4.5\memcached-1.4.5\doc\threads.txt

     文件        704  2009-08-30 07:00  memcached-1.4.5\memcached-1.4.5\doc\xml2rfc\reference.RFC.0768.xml

     文件       3193  2009-08-30 07:00  memcached-1.4.5\memcached-1.4.5\doc\xml2rfc\rfc2629-noinc.xsl

     文件       3756  2009-08-30 07:00  memcached-1.4.5\memcached-1.4.5\doc\xml2rfc\rfc2629-other.ent

............此处省略95个文件信息

评论

共有 条评论

相关资源