CUBRID Engine  latest
file_hash.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 
20 /*
21  * file_hash.h: File Hashing
22  */
23 
24 #ifndef _FILE_HASH_H_
25 #define _FILE_HASH_H_
26 
27 #ident "$Id$"
28 
29 #include "config.h"
30 #include "error_manager.h"
31 #include "oid.h"
32 
33 /* hash key and data */
34 typedef struct fh_info
35 {
36  union
37  {
38  struct
39  {
41  char data;
42  } fh_oidkey;
43  struct
44  {
45  int key;
46  char data;
47  } fh_intkey;
48  } fh_key_data;
49 } FH_INFO;
50 
51 #define fh_oidk_key fh_key_data.fh_oidkey.key
52 #define fh_oidk_data fh_key_data.fh_oidkey.data
53 #define fh_intk_key fh_key_data.fh_intkey.key
54 #define fh_intk_data fh_key_data.fh_intkey.data
55 
56 typedef unsigned int FH_FILE_POS;
57 #define INVALID_FILE_POS (FH_FILE_POS)~0
58 
59 /* A hash table entry. */
60 typedef struct fh_entry
61 {
62  FH_FILE_POS next; /* Collision chain */
63  FH_INFO info; /* Key & data */
64 } FH_ENTRY;
65 
66 typedef struct fh_entry *FH_ENTRY_PTR;
67 
68 /* header for a page of fh_entry's */
69 typedef struct fh_page_hdr
70 {
71  struct fh_page_hdr *next; /* Next header */
72  struct fh_page_hdr *prev; /* Previous header */
73  struct fh_entry *fh_entries; /* Location of fh_entry's */
74  FH_FILE_POS page; /* Hash file page number */
75 } FH_PAGE_HDR;
76 
77 typedef unsigned int (*HASH_FUNC) (const void *info, unsigned int htsize);
78 typedef int (*CMP_FUNC) (const void *key1, const void *key2);
79 
80 typedef enum
81 {
84 } FH_KEY_TYPE;
85 
86 /* Hash table */
87 typedef struct fh_table
88 {
89  HASH_FUNC hfun; /* Hash function */
90  CMP_FUNC cmpfun; /* How to compare keys */
91  const char *name; /* Name of Table */
92  FH_PAGE_HDR *pg_hdr; /* The page headers */
93  FH_PAGE_HDR *pg_hdr_last; /* The last page's header */
94  FH_PAGE_HDR *pg_hdr_free; /* The first free pages's header */
95  FH_PAGE_HDR *pg_hdr_alloc; /* The page header address allocated */
96  int size; /* Better if prime number */
97  int page_size; /* Number of bytes per page */
98  int data_size; /* Number of bytes of data per entry */
99  int entry_size; /* Number of bytes per entry */
100  int entries_per_page; /* Number of fh_entry's per page */
101  int cached_pages; /* Number of cached pages */
102  FH_FILE_POS overflow; /* Page & entry for overflow */
103  int nentries; /* Actual number of entries */
104  int ncollisions; /* Number of collisions */
105  char *hash_filename; /* Hash file pathname */
106  int fd; /* Hash file file descriptor */
107  FH_KEY_TYPE key_type; /* Type of key */
108  char *bitmap; /* Bitmap for used pages */
109  int bitmap_size; /* Size of page bitmap */
110 } FH_TABLE;
111 
112 typedef void *FH_KEY;
113 typedef void *FH_DATA;
114 
115 FH_TABLE *fh_create (const char *, int, int, int, const char *, FH_KEY_TYPE, int, HASH_FUNC, CMP_FUNC);
116 int fh_put (FH_TABLE * ht, FH_KEY key, FH_DATA data);
117 int fh_get (FH_TABLE * ht, FH_KEY key, FH_DATA * data);
118 void fh_destroy (FH_TABLE * ht);
119 void fh_dump (FH_TABLE * ht);
120 
121 #endif /* _FILE_HASH_H_ */
FH_INFO info
Definition: file_hash.h:63
int entries_per_page
Definition: file_hash.h:100
unsigned int FH_FILE_POS
Definition: file_hash.h:56
int nentries
Definition: file_hash.h:103
struct fh_info::@78::@80 fh_intkey
int fh_get(FH_TABLE *ht, FH_KEY key, FH_DATA *data)
Definition: file_hash.c:353
int data_size
Definition: file_hash.h:98
struct fh_page_hdr FH_PAGE_HDR
FH_FILE_POS next
Definition: file_hash.h:62
int cached_pages
Definition: file_hash.h:101
union fh_info::@78 fh_key_data
char data
Definition: file_hash.h:41
void fh_dump(FH_TABLE *ht)
Definition: file_hash.c:833
int fd
Definition: file_hash.h:106
struct fh_info::@78::@79 fh_oidkey
struct fh_table FH_TABLE
FH_KEY_TYPE key_type
Definition: file_hash.h:107
struct fh_entry * FH_ENTRY_PTR
Definition: file_hash.h:66
struct fh_page_hdr * next
Definition: file_hash.h:71
FH_KEY_TYPE
Definition: file_hash.h:80
CMP_FUNC cmpfun
Definition: file_hash.h:90
FH_PAGE_HDR * pg_hdr
Definition: file_hash.h:92
FH_TABLE * fh_create(const char *, int, int, int, const char *, FH_KEY_TYPE, int, HASH_FUNC, CMP_FUNC)
Definition: file_hash.c:164
FH_PAGE_HDR * pg_hdr_alloc
Definition: file_hash.h:95
struct fh_entry FH_ENTRY
int fh_put(FH_TABLE *ht, FH_KEY key, FH_DATA data)
Definition: file_hash.c:449
FH_FILE_POS overflow
Definition: file_hash.h:102
int bitmap_size
Definition: file_hash.h:109
struct fh_entry * fh_entries
Definition: file_hash.h:73
int entry_size
Definition: file_hash.h:99
int size
Definition: file_hash.h:96
OID key
Definition: file_hash.h:40
HASH_FUNC hfun
Definition: file_hash.h:89
void * FH_KEY
Definition: file_hash.h:112
unsigned int(* HASH_FUNC)(const void *info, unsigned int htsize)
Definition: file_hash.h:77
const char * name
Definition: file_hash.h:91
int ncollisions
Definition: file_hash.h:104
int page_size
Definition: file_hash.h:97
struct fh_info FH_INFO
int(* CMP_FUNC)(const void *key1, const void *key2)
Definition: file_hash.h:78
FH_PAGE_HDR * pg_hdr_last
Definition: file_hash.h:93
FH_FILE_POS page
Definition: file_hash.h:74
char * hash_filename
Definition: file_hash.h:105
Definition: file_hash.h:60
void fh_destroy(FH_TABLE *ht)
Definition: file_hash.c:310
int key
Definition: file_hash.h:45
void * FH_DATA
Definition: file_hash.h:113
struct fh_page_hdr * prev
Definition: file_hash.h:72
char * bitmap
Definition: file_hash.h:108
FH_PAGE_HDR * pg_hdr_free
Definition: file_hash.h:94