gist_htab.cc

来自「Libgist is an implementation of the Gene」· CC 代码 · 共 85 行

CC
85
字号
// gist_htab.cc// Copyright (c) 1997, Regents of the University of California// $Id: gist_htab.cc,v 1.4 1998/06/18 00:54:26 aoki Exp $#ifdef __GNUG__#pragma implementation "gist_htab.h"#endif#include "gist_htab.h"gist_htab::gist_htab(){    reset();}voidgist_htab::reset(){    for (int i = 0; i < GISTBUFS; i++) {        tab[i].key = 0;        tab[i].value = 0;        tab[i].inUse = false;    }}gist_htab::~gist_htab(){}intgist_htab::hash(shpid_t key){    return key % GISTBUFS;}intgist_htab::operator[](shpid_t page){    int index = hash(page);    int cnt = 0;    while ((!tab[index].inUse || tab[index].key != page) && cnt < GISTBUFS) {	index = (index + 1) % GISTBUFS;        cnt++;    }    if (cnt == GISTBUFS) {        return -1;    } else {        return tab[index].value;    }}voidgist_htab::add(shpid_t key, int value){    int index = hash(key);    int cnt = 0;    while (tab[index].inUse && cnt < GISTBUFS) {        index = (index + 1) % GISTBUFS;	cnt++;    }    assert(cnt != GISTBUFS);    assert(!tab[index].inUse);    tab[index].key = key;    tab[index].value = value;    tab[index].inUse = true;}voidgist_htab::remove(shpid_t key){    int index = hash(key);    int cnt = 0;    while ((!tab[index].inUse || tab[index].key != key) && cnt < GISTBUFS) {        index = (index + 1) % GISTBUFS;	cnt++;    }    if (tab[index].key == key) {        tab[index].inUse = false;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?