/usr/include/io_lib/hash_table.h is in libstaden-read-dev 1.14.8-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | /*
* Copyright (c) 2005-2010, 2013 Genome Research Ltd.
* Author(s): James Bonfield
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* 3. Neither the names Genome Research Ltd and Wellcome Trust Sanger
* Institute nor the names of its contributors may be used to endorse
* or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY GENOME RESEARCH LTD AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENOME RESEARCH
* LTD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _HASH_TABLE_H_
#define _HASH_TABLE_H_
#include <inttypes.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include "io_lib/pooled_alloc.h"
#ifdef __cplusplus
extern "C" {
#endif
/* The data referenced by the hash table */
typedef union {
uint64_t i;
float f;
double d;
void *p;
} HashData;
/* A hash item with "next" pointer to use in a linked list */
typedef struct HashItemStruct {
HashData data; /* user defined data attached to this key */
char *key; /* key we hashed on */
int key_len; /* and its length */
struct HashItemStruct *next;
} HashItem;
/* The main hash table structure itself */
typedef struct {
int options; /* HASH_FUNC & HASH_OPT macros */
uint32_t nbuckets; /* Number of hash buckets; power of 2 */
uint32_t mask; /* bit-mask equiv of nbuckets */
int nused; /* How many hash entries we're storing */
HashItem **bucket; /* The bucket "list heads" themselves */
pool_alloc_t *hi_pool; /* Pool of allocated HashItem structs */
} HashTable;
/* An iterator on HashTable items */
typedef struct {
int bnum;
HashItem *hi;
} HashIter;
#define HASHFILE_MAGIC ".hsh"
#define HASHFILE_VERSION100 "1.00"
#define HASHFILE_VERSION "1.01"
#define HASHFILE_PREPEND -1
/* File format: the hash table header */
typedef struct {
char magic[4];
char vers[4];
char hfunc;
unsigned char nheaders;
unsigned char nfooters;
unsigned char narchives;
uint32_t nbuckets;
int64_t offset;
uint32_t size;
} HashFileHeader;
/* sizeof(HashFileHeader) minus terminal padding */
#define HHSIZE 28
typedef struct {
char magic[4];
char offset[8];
} HashFileFooter;
/* The data block attached to the hash table */
typedef struct {
uint64_t pos;
uint32_t size;
unsigned char archive;
unsigned char header; /* zero if not set */
unsigned char footer; /* zero if not set */
} HashFileItem;
/* Common headers or footers to prepend to the archive contents */
typedef struct {
unsigned char archive_no;
uint64_t pos;
uint32_t size;
unsigned char *cached_data;
} HashFileSection;
/*
* The main structure for the HashFile functions.
*
* We obtain an existing HashFile by opening a stored hash file or by
* loading the entire thing.
* New empty ones can be created using HashFileCreate.
*/
typedef struct {
HashFileHeader hh; /* on-disk file header */
HashTable *h; /* the in-memory hash table */
int nheaders; /* number of common file headers */
HashFileSection *headers; /* on-disk common file headers struct */
int nfooters; /* number of common file footers */
HashFileSection *footers; /* on-disk common file footers struct */
int narchives; /* number of archive files, 0 if inline file */
char **archives; /* archive filenames */
FILE *hfp; /* hash FILE */
FILE **afp; /* archive FILE(s) */
int header_size; /* size of header + filename + N(head/feet) */
off_t hf_start; /* location of HashFile header in file */
} HashFile;
/* Functions to to use HashTable.options */
#define HASH_FUNC_HSIEH 0
#define HASH_FUNC_TCL 1
#define HASH_FUNC_JENKINS 2
#define HASH_FUNC_JENKINS3 3
#define HASH_FUNC_MASK 7
/* Other HashTable.options values */
#define HASH_NONVOLATILE_KEYS (1<<3)
#define HASH_ALLOW_DUP_KEYS (1<<4)
#define HASH_DYNAMIC_SIZE (1<<5)
#define HASH_OWN_KEYS (1<<6)
#define HASH_POOL_ITEMS (1<<7)
#define HASH_INT_KEYS (1<<8)
/* Hashing prototypes */
uint32_t hash(int func, uint8_t *key, int key_len);
uint64_t hash64(int func, uint8_t *key, int key_len);
uint32_t HashJenkins(uint8_t *k, int length);
uint32_t HashTcl(uint8_t *data, int len);
uint32_t HashHsieh(uint8_t *k, int length);
/* HashTable management prototypes */
HashTable *HashTableCreate(int size, int options);
void HashTableDestroy(HashTable *h, int deallocate_date);
int HashTableResize(HashTable *h, int newsize);
HashItem *HashTableAdd(HashTable *h, char *key, int key_len,
HashData data, int *added);
int HashTableDel(HashTable *h, HashItem *hi, int deallocate_data);
int HashTableRemove(HashTable *h, char *key, int key_len, int deallocate_data);
HashItem *HashTableSearch(HashTable *h, char *key, int key_len);
HashItem *HashTableNext(HashItem *hi, char *key, int key_len);
HashItem *HashTableNextInt(HashItem *hi, char *key, int key_len);
void HashTableStats(HashTable *h, FILE *fp);
void HashTableDump(HashTable *h, FILE *fp, char *prefix);
/* Iterator prototypes */
HashIter *HashTableIterCreate(void);
void HashTableIterDestroy(HashIter *iter);
HashItem *HashTableIterNext(HashTable *h, HashIter *iter);
void HashTableIterReset(HashIter *iter);
/* HashFile prototypes */
uint64_t HashFileSave(HashFile *hf, FILE *fp, int64_t offset);
HashFile *HashFileLoad(FILE *fp);
int HashFileQuery(HashFile *hf, uint8_t *key, int key_len, HashFileItem *item);
char *HashFileExtract(HashFile *hf, char *fname, size_t *len);
HashFile *HashFileCreate(int size, int options);
void HashFileDestroy(HashFile *hf);
HashFile *HashFileOpen(char *fname);
HashFile *HashFileFopen(FILE *fp);
#ifdef __cplusplus
}
#endif
#endif /* _HASH_TABLE_H_ */
|