コード例 #1
0
void assoc_delete(const char *key, const size_t nkey, const uint32_t hv) {
	//得到前驱结点的h_next成员地址
    item **before = _hashitem_before(key, nkey, hv);

    if (*before) {//查找成功
        item *nxt;
        hash_items--;
        /* The DTrace probe cannot be triggered as the last instruction
         * due to possible tail-optimization by the compiler
         */
        MEMCACHED_ASSOC_DELETE(key, nkey, hash_items);

		//因为before是一个二级指针,其值为所查找item的前驱item的h_next成员地址
		//所以*before指向的是所查找的item。因为before是一个二级指针,所以*before
		//作为左值时,可以给h_next成员变量赋值。所以下面三行代码是
		//使得删除中间的item后,前后的item还能连接起来。
		
        nxt = (*before)->h_next;
        (*before)->h_next = 0;   /* probably pointless, but whatever. */
        *before = nxt;
        return;
    }
    /* Note:  we never actually get here.  the callers don't delete things
       they can't find. */
    assert(*before != 0);
}
コード例 #2
0
ファイル: assoc.c プロジェクト: jdi-tagged/memcached
void assoc_delete(const char *key, const size_t nkey, const uint32_t hv) {
    item **before = _hashitem_before(key, nkey, hv);

    if (*before) {
        item *nxt;
        hash_items--;
        /* The DTrace probe cannot be triggered as the last instruction
         * due to possible tail-optimization by the compiler
         */
        MEMCACHED_ASSOC_DELETE(key, nkey, hash_items);
        nxt = (*before)->h_next;
        (*before)->h_next = 0;   /* probably pointless, but whatever. */
        *before = nxt;
        return;
    }
    /* Note:  we never actually get here.  the callers don't delete things
       they can't find. */
    assert(*before != 0);
}