Added hash functions with support for multiple hash tables
[IRC.git] / Robust / src / Runtime / DSTM / interface / dstm.h
1 #ifndef _DSTM_H_
2 #define _DSTM_H_
3
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <string.h>
7
8 #define LOADFACTOR 0.75
9 #define HASH_SIZE 100
10
11 enum status {CLEAN, DIRTY};
12
13 typedef struct obj_header {
14         unsigned int oid;
15         unsigned short type;
16         unsigned short version;
17         unsigned short rcount;
18         char status;
19 } obj_header_t;
20
21 typedef struct obj_store {
22         unsigned int id;
23         char *base;
24         unsigned int size;
25         char *top;              //next available location
26         struct obj_store *next;
27 } obj_store_t;
28
29 //use for hash tables, transaction records.
30 //to check oid, do object->oid
31 typedef struct obj_lnode{
32         obj_header_t *object;
33         unsigned int oid;
34         struct obj_lnode *next;
35 } obj_listnode_t;
36
37 /*
38 typedef struct obj_addr_table {
39         unsigned int size;      //number of elements, not bytes
40         obj_listnode_t *table;  //this should point to an array of object lists, of the specified size
41 } obj_addr_table_t;
42 */
43
44 typedef struct hash_table {
45         obj_listnode_t **hash;  // points to beginning of hash table
46         float loadfactor;
47         unsigned int numelements;
48         unsigned int size;
49 }obj_addr_table_t;
50
51 typedef struct trans_record {
52         obj_listnode_t *obj_list;
53         obj_store_t *cache;
54         obj_addr_table_t *lookupTable;
55 } trans_record_t;
56
57 typedef struct obj_location_lnode {
58         unsigned int oid;
59         unsigned int mid;
60         struct obj_location_lnode *next;
61 } obj_location_listnode_t;
62
63 typedef struct {
64         unsigned int size; //number of elements, not bytes
65         obj_location_listnode_t *table; //this should point to an array of object lists, of the specified size
66 } obj_location_table;
67
68 /* Prototypes for object store */
69 void dstm_init(void);
70 void create_objstr(unsigned int);
71 void delete_objstr(int);
72 obj_store_t *get_objstr_begin(void);
73 /* end object store */
74
75
76 /* Prototypes for object header */
77 int get_newID(void);
78 int insertObject(obj_header_t h); 
79 int getObjSize(obj_header_t h);
80 void createObject(unsigned short type); 
81 /* end object header */
82
83 /* Prototypes for hash*/
84 void createHash(obj_addr_table_t *, int , float);
85 void resize(obj_addr_table_t * table);
86 int hashkey(unsigned int, obj_addr_table_t *);
87 void addKey(unsigned int, obj_header_t *, obj_addr_table_t *);
88 obj_header_t *findKey(unsigned int,obj_addr_table_t *);
89 int removeKey(unsigned int, obj_addr_table_t *);
90 /* end for hash */
91
92
93 /*
94 void * allocate_size(unsigned int);
95 void initializeobj(unsigned int);
96 unsigned int getobjSize(obj_header *);
97 int insertAddr(obj_addr_table *, obj_header *);
98 int removeAddr(obj_addr_table *, unsigned int);
99 obj_header *getAddr(obj_addr_table *, unsigned int);
100 trans_record *transStart();
101 obj_header *transRead(trans_record *, unsigned int);
102 int transCommit(trans_record *);
103 int insertLocation(obj_location_table *, unsigned int, unsigned int);
104 int removeLocation(obj_location_table *, unsigned int);
105 unsigned int getLocation(obj_location_table *, unsigned int);
106 */
107
108 #endif