bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / apache2 / include / ssl_util_table.h
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /*                      _             _
18  *  _ __ ___   ___   __| |    ___ ___| |  mod_ssl
19  * | '_ ` _ \ / _ \ / _` |   / __/ __| |  Apache Interface to OpenSSL
20  * | | | | | | (_) | (_| |   \__ \__ \ |
21  * |_| |_| |_|\___/ \__,_|___|___/___/_|
22  *                      |_____|
23  *  ssl_util_table.h
24  *  High Performance Hash Table Header
25  */
26
27 /*
28  * Generic hash table defines
29  * Table 4.1.0 July-28-1998
30  *
31  * This library is a generic open hash table with buckets and
32  * linked lists.  It is pretty high performance.  Each element
33  * has a key and a data.  The user indexes on the key to find the
34  * data.
35  *
36  * Copyright 1998 by Gray Watson <gray@letters.com>
37  *
38  * Permission to use, copy, modify, and distribute this software for any
39  * purpose and without fee is hereby granted, provided that the above
40  * copyright notice and this permission notice appear in all copies,
41  * and that the name of Gray Watson not be used in advertising or
42  * publicity pertaining to distribution of the document or software
43  * without specific, written prior permission.
44  *
45  * Gray Watson makes no representations about the suitability of the
46  * software described herein for any purpose.  It is provided "as is"
47  * without express or implied warranty.
48  */
49
50 #ifndef __SSL_UTIL_TABLE_H__
51 #define __SSL_UTIL_TABLE_H__
52
53 #ifdef __cplusplus
54 extern "C" {
55 #endif /* __cplusplus */
56
57 /*
58  * To build a "key" in any of the below routines, pass in a pointer to
59  * the key and its size [i.e. sizeof(int), etc].  With any of the
60  * "key" or "data" arguments, if their size is < 0, it will do an
61  * internal strlen of the item and add 1 for the \0.
62  *
63  * If you are using firstkey() and nextkey() functions, be careful if,
64  * after starting your firstkey loop, you use delete or insert, it
65  * will not crash but may produce interesting results.  If you are
66  * deleting from firstkey to NULL it will work fine.
67  */
68
69 /* return types for table functions */
70 #define TABLE_ERROR_NONE    1   /* no error from function */
71 #define TABLE_ERROR_PNT     2   /* bad table pointer */
72 #define TABLE_ERROR_ARG_NULL    3   /* buffer args were null */
73 #define TABLE_ERROR_SIZE    4   /* size of data was bad */
74 #define TABLE_ERROR_OVERWRITE   5   /* key exists and we cant overwrite */
75 #define TABLE_ERROR_NOT_FOUND   6   /* key does not exist */
76 #define TABLE_ERROR_ALLOC   7   /* memory allocation error */
77 #define TABLE_ERROR_LINEAR  8   /* no linear access started */
78 #define TABLE_ERROR_OPEN    9   /* could not open file */
79 #define TABLE_ERROR_SEEK    10  /* could not seek to pos in file */
80 #define TABLE_ERROR_READ    11  /* could not read from file */
81 #define TABLE_ERROR_WRITE   12  /* could not write to file */
82 #define TABLE_ERROR_EMPTY   13  /* table is empty */
83 #define TABLE_ERROR_NOT_EMPTY   14  /* table contains data */
84 #define TABLE_ERROR_ALIGNMENT   15  /* invalid alignment value */
85
86 /*
87  * Table flags set with table_attr.
88  */
89
90 /*
91  * Automatically adjust the number of table buckets on the fly.
92  * Whenever the number of entries gets above some threshold, the
93  * number of buckets is realloced to a new size and each entry is
94  * re-hashed.  Although this may take some time when it re-hashes, the
95  * table will perform better over time.
96  */
97 #define TABLE_FLAG_AUTO_ADJUST  (1<<0)
98
99 /*
100  * If the above auto-adjust flag is set, also adjust the number of
101  * table buckets down as we delete entries.
102  */
103 #define TABLE_FLAG_ADJUST_DOWN  (1<<1)
104
105 /* structure to walk through the fields in a linear order */
106 typedef struct {
107   unsigned int  tl_magic;   /* magic structure to ensure correct init */
108   unsigned int  tl_bucket_c;    /* where in the table buck array we are */
109   unsigned int  tl_entry_c; /* in the bucket, which entry we are on */
110 } table_linear_t;
111
112 typedef int (*table_compare_t)(const void *key1, const int key1_size,
113                    const void *data1, const int data1_size,
114                    const void *key2, const int key2_size,
115                    const void *data2, const int data2_size);
116
117 #ifndef TABLE_PRIVATE
118 typedef void    table_t;
119 typedef void    table_entry_t;
120 #endif
121
122 /*
123  * Prototypes
124  */
125 extern table_t        *table_alloc(const unsigned int bucket_n, int *error_p, void *(*malloc_f)(void *opt_param, size_t size), void *(*calloc_f)(void *opt_param, size_t number, size_t size), void *(*realloc_f)(void *opt_param, void *ptr, size_t size), void (*free_f)(void *opt_param, void *ptr), void *opt_param);
126 extern int             table_attr(table_t *table_p, const int attr);
127 extern int             table_set_data_alignment(table_t *table_p, const int alignment);
128 extern int             table_clear(table_t *table_p);
129 extern int             table_free(table_t *table_p);
130 extern int             table_insert_kd(table_t *table_p, const void *key_buf, const int key_size, const void *data_buf, const int data_size, void **key_buf_p, void **data_buf_p, const char overwrite_b);
131 extern int             table_insert(table_t *table_p, const void *key_buf, const int key_size, const void *data_buf, const int data_size, void **data_buf_p, const char overwrite_b);
132 extern int             table_retrieve(table_t *table_p, const void *key_buf, const int key_size, void **data_buf_p, int *data_size_p);
133 extern int             table_delete(table_t *table_p, const void *key_buf, const int key_size, void **data_buf_p, int *data_size_p);
134 extern int             table_delete_first(table_t *table_p, void **key_buf_p, int *key_size_p, void **data_buf_p, int *data_size_p);
135 extern int             table_info(table_t *table_p, int *num_buckets_p, int *num_entries_p);
136 extern int             table_adjust(table_t *table_p, const int bucket_n);
137 extern const char     *table_strerror(const int error);
138 extern int             table_type_size(void);
139 extern int             table_first(table_t *table_p, void **key_buf_p, int *key_size_p, void **data_buf_p, int *data_size_p);
140 extern int             table_next(table_t *table_p, void **key_buf_p, int *key_size_p, void **data_buf_p, int *data_size_p);
141 extern int             table_this(table_t *table_p, void **key_buf_p, int *key_size_p, void **data_buf_p, int *data_size_p);
142 extern int             table_first_r(table_t *table_p, table_linear_t *linear_p, void **key_buf_p, int *key_size_p, void **data_buf_p, int *data_size_p);
143 extern int             table_next_r(table_t *table_p, table_linear_t *linear_p, void **key_buf_p, int *key_size_p, void **data_buf_p, int *data_size_p);
144 extern int             table_this_r(table_t *table_p, table_linear_t *linear_p, void **key_buf_p, int *key_size_p, void **data_buf_p, int *data_size_p);
145 extern table_entry_t **table_order(table_t *table_p, table_compare_t compare, int *num_entries_p, int *error_p);
146 extern int             table_entry_info(table_t *table_p, table_entry_t *entry_p, void **key_buf_p, int *key_size_p, void **data_buf_p, int *data_size_p);
147
148 #ifdef __cplusplus
149 }
150 #endif /* __cplusplus */
151
152 #endif /* __SSL_UTIL_TABLE_H__ */