📄 seshashmap.h
字号:
/****************************************************************************
*
* (c) Copyright 2006 by SCADA Enterprise Solutions Inc
* All rights reserved
*
* NAME:
*
* sesHashMap.H -- This is the header file for declaring all data
* of a hashmap which takes a string as key and
* returns an integer.
*
* AUTHOR: Wai Tse
*
* DESCRIPTION:
*
* This file contains all data structures used by a hashmap
*
* RESTRICTION:
* None
*
* REVISION HISTORY:
*
* 10-Mar-2006 Wai Tse Created the initial version.
*
***************************************************************************/
#ifndef HASHMAP_H
#define HASHMAP_H
#include <malloc.h>
#include <stdlib.h>
#include "sesConst.H"
#include "sesDbg.H"
#include "sesLogErr.H"
#define MAP_EXIST -3 // Element exists
#define MAP_MISSING -3 // No such element
#define MAP_FULL -2 // Hashmap is full
#define MAP_OMEM -1 // Out of Memory
#define MAP_OK 0 // OK
#define SIZE_FACTOR 4 // Factor to set the size of a hash map
#define KEY_SIZE 20 // Size of the hash key
// any_t is a pointer of any type.
typedef void *any_t;
// PFany is a pointer to a function that can take two any_t arguments
// and return an integer. Returns status code..
//typedef int (*PFany)(any_t, any_t);
// map_t is a pointer to an internally maintained data structure.
typedef any_t map_t;
// Data structure stores in a map
// For shared memory, we must use save the content instead of the pointer
// of a key.
// Note that when changing the size of an alias (dtAlias), we need to
// change the size of the key.
typedef struct {
char key[KEY_SIZE];
short in_use;
short data;
} hashmap_element;
// Header of a hashmap and its data
typedef struct {
int table_size;
int size;
int collision;
} hashmap_map;
class sesHashMap
{
public:
sesHashMap(int mapEntries);
sesHashMap(int mapEntries, void *ptrMap, int reset);
virtual ~sesHashMap();
void put(const char *key, int value);
void get(const char *key, int *value);
void remove(char *key);
int size() { return _m->size; }
int tableSize() { return _m->table_size; }
int collision() { return _m->collision; }
private:
int hash(const char *key);
unsigned int hash_char(const char *key);
unsigned int hash_char1(const char *key);
unsigned int hash_char2(const char *key);
unsigned int hash_char3(const char *key);
unsigned int hash_char4(const char *key);
unsigned int hash_char5(const char *key);
unsigned int hash_char6(const char *key);
unsigned int hash_char7(const char *key);
unsigned int hash_char8(const char *key);
void rehash();
hashmap_map *_m; // pointer of a hashmap
hashmap_element *_data; // hash map data block pointer
int _shared; // 1=shared memory mode, for controlling free()
int _semid; // semaphore ID
};
#endif // HASHMAP_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -