⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hash_table.h

📁 国外游戏开发者杂志2003年第七期配套代码
💻 H
字号:
#pragma once

#ifndef __HASH_TABLE_H
#define __HASH_TABLE_H

const int MAX_OVERCROWDING_FACTOR = 4;

struct List;

struct Hashable {
    int hash_code;
    
    virtual int compare(Hashable *other) = 0;
    virtual int get_hash_code() = 0;
};

struct Hash_Table {
    Hash_Table(int hash_size);
    ~Hash_Table();

    void add(Hashable *hashable);
    Hashable *find(Hashable *hashable);
    Hashable *remove(Hashable *hashable);

    int items;
    int table_size;
    List *lists;

  protected:
    void resize();
};

struct Hash_Table_Iterator {
    void init(Hash_Table *table);
    void next();

    Hash_Table *table;
    int current_bucket_index;
    int current_list_item_index;

    Hashable *hashable;
    bool done;
};


#endif // __HASH_TABLE_H

⌨️ 快捷键说明

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