forked from cms-sw/cmsdist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpm-4.8.0-case-insensitive-sources.patch
387 lines (385 loc) · 8.88 KB
/
rpm-4.8.0-case-insensitive-sources.patch
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
commit a48af4fb6f3263e6b6443306ab84a9b2283c1b5e
Author: Giulio Eulisse <[email protected]>
Date: Thu Apr 22 11:18:18 2010 +0200
Avoid case-sensitive filenames.
diff --git a/lib/rpmhash.c b/lib/rpmhash.c
new file mode 100644
index 0000000..34be313
--- /dev/null
+++ b/lib/rpmhash.c
@@ -0,0 +1,24 @@
+/**
+ * \file lib/rpmhash.c
+ * Hash table implemenation
+ */
+
+#include "lib/rpmhash.h"
+
+
+unsigned int hashFunctionString(const char * string) {
+ /* Jenkins One-at-a-time hash */
+
+ unsigned int hash = 0xe4721b68;
+
+ while (*string != '\0') {
+ hash += *string;
+ hash += (hash << 10);
+ hash ^= (hash >> 6);
+ string++;
+ }
+ hash += (hash << 3);
+ hash ^= (hash >> 11);
+ hash += (hash << 15);
+ return hash;
+}
diff --git a/lib/rpmhash.h b/lib/rpmhash.h
new file mode 100644
index 0000000..57cc290
--- /dev/null
+++ b/lib/rpmhash.h
@@ -0,0 +1,22 @@
+#ifndef H_RPMHASH
+#define H_RPMHASH
+
+#include "rpm/rpmutil.h"
+
+/**
+ * \file lib/rpmhash.h
+ * Hash table implemenation.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+RPM_GNUC_INTERNAL
+unsigned int hashFunctionString(const char * string);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/rpmhash_big.c b/lib/rpmhash_big.c
new file mode 100644
index 0000000..79a82b0
--- /dev/null
+++ b/lib/rpmhash_big.c
@@ -0,0 +1,207 @@
+/**
+ * \file lib/rpmhash.c
+ * Hash table implemenation
+ */
+
+#include "system.h"
+#include "debug.h"
+
+#define Bucket JOIN(HASHTYPE,Buket)
+#define Bucket_s JOIN(HASHTYPE,Buket_s)
+
+typedef struct Bucket_s * Bucket;
+
+/**
+ */
+struct Bucket_s {
+ Bucket next; /*!< pointer to next item in bucket */
+ HTKEYTYPE key; /*!< hash key */
+#ifdef HTDATATYPE
+ int dataCount; /*!< data entries */
+ HTDATATYPE data[1]; /*!< data - grows by resizing whole bucket */
+#endif
+};
+
+/**
+ */
+struct HASHSTRUCT {
+ int numBuckets; /*!< number of hash buckets */
+ Bucket * buckets; /*!< hash bucket array */
+ hashFunctionType fn; /*!< generate hash value for key */
+ hashEqualityType eq; /*!< compare hash keys for equality */
+ hashFreeKey freeKey;
+#ifdef HTDATATYPE
+ hashFreeData freeData;
+#endif
+};
+
+/**
+ * Find entry in hash table.
+ * @param ht pointer to hash table
+ * @param key pointer to key value
+ * @return pointer to hash bucket of key (or NULL)
+ */
+static
+Bucket HASHPREFIX(findEntry)(HASHTYPE ht, HTKEYTYPE key)
+{
+ unsigned int hash;
+ Bucket b;
+
+ hash = ht->fn(key) % ht->numBuckets;
+ b = ht->buckets[hash];
+
+ while (b && ht->eq(b->key, key))
+ b = b->next;
+
+ return b;
+}
+
+HASHTYPE HASHPREFIX(Create)(int numBuckets,
+ hashFunctionType fn, hashEqualityType eq,
+ hashFreeKey freeKey
+#ifdef HTDATATYPE
+, hashFreeData freeData
+#endif
+)
+{
+ HASHTYPE ht;
+
+ ht = xmalloc(sizeof(*ht));
+ ht->numBuckets = numBuckets;
+ ht->buckets = xcalloc(numBuckets, sizeof(*ht->buckets));
+ ht->freeKey = freeKey;
+#ifdef HTDATATYPE
+ ht->freeData = freeData;
+#endif
+ ht->fn = fn;
+ ht->eq = eq;
+ return ht;
+}
+
+void HASHPREFIX(AddEntry)(HASHTYPE ht, HTKEYTYPE key
+#ifdef HTDATATYPE
+, HTDATATYPE data
+#endif
+)
+{
+ unsigned int hash;
+ Bucket b;
+ Bucket * b_addr;
+
+ hash = ht->fn(key) % ht->numBuckets;
+ b = ht->buckets[hash];
+ b_addr = ht->buckets + hash;
+
+ while (b && ht->eq(b->key, key)) {
+ b_addr = &(b->next);
+ b = b->next;
+ }
+
+ if (b == NULL) {
+ b = xmalloc(sizeof(*b));
+ b->key = key;
+#ifdef HTDATATYPE
+ b->dataCount = 1;
+ b->data[0] = data;
+#endif
+ b->next = ht->buckets[hash];
+ ht->buckets[hash] = b;
+ }
+#ifdef HTDATATYPE
+ else {
+ // resizing bucket TODO: increase exponentially
+ // Bucket_s already contains space for one dataset
+ b = *b_addr = xrealloc(
+ b, sizeof(*b) + sizeof(b->data[0]) * (b->dataCount));
+ // though increasing dataCount after the resize
+ b->data[b->dataCount++] = data;
+ }
+#endif
+}
+
+HASHTYPE HASHPREFIX(Free)(HASHTYPE ht)
+{
+ Bucket b, n;
+ int i;
+ if (ht==NULL)
+ return ht;
+ for (i = 0; i < ht->numBuckets; i++) {
+ b = ht->buckets[i];
+ if (b == NULL)
+ continue;
+ ht->buckets[i] = NULL;
+
+ do {
+ n = b->next;
+ if (ht->freeKey)
+ b->key = ht->freeKey(b->key);
+#ifdef HTDATATYPE
+ if (ht->freeData) {
+ int j;
+ for (j=0; j < b->dataCount; j++ ) {
+ b->data[j] = ht->freeData(b->data[j]);
+ }
+ }
+#endif
+ b = _free(b);
+ } while ((b = n) != NULL);
+ }
+
+ ht->buckets = _free(ht->buckets);
+ ht = _free(ht);
+
+ return NULL;
+}
+
+int HASHPREFIX(HasEntry)(HASHTYPE ht, HTKEYTYPE key)
+{
+ Bucket b;
+
+ if (!(b = HASHPREFIX(findEntry)(ht, key))) return 0; else return 1;
+}
+
+#ifdef HTDATATYPE
+
+int HASHPREFIX(GetEntry)(HASHTYPE ht, HTKEYTYPE key, HTDATATYPE** data,
+ int * dataCount, HTKEYTYPE* tableKey)
+{
+ Bucket b;
+ int rc = ((b = HASHPREFIX(findEntry)(ht, key)) != NULL);
+
+ if (data)
+ *data = rc ? b->data : NULL;
+ if (dataCount)
+ *dataCount = rc ? b->dataCount : 0;
+ if (tableKey && rc)
+ *tableKey = b->key;
+
+ return rc;
+}
+
+void HASHPREFIX(PrintStats)(HASHTYPE ht) {
+ int i;
+ Bucket bucket;
+
+ int hashcnt=0, bucketcnt=0, datacnt=0;
+ int maxbuckets=0;
+
+ for (i=0; i<ht->numBuckets; i++) {
+ int buckets = 0;
+ for (bucket=ht->buckets[i]; bucket; bucket=bucket->next){
+ buckets++;
+#ifdef HTDATATYPE
+ datacnt += bucket->dataCount;
+#endif
+ }
+ if (maxbuckets < buckets) maxbuckets = buckets;
+ if (buckets) hashcnt++;
+ bucketcnt += buckets;
+ }
+ fprintf(stderr, "Hashsize: %i\n", ht->numBuckets);
+ fprintf(stderr, "Hashbuckets: %i\n", hashcnt);
+ fprintf(stderr, "Keys: %i\n", bucketcnt);
+ fprintf(stderr, "Values: %i\n", datacnt);
+ fprintf(stderr, "Max Keys/Bucket: %i\n", maxbuckets);
+}
+
+#endif
diff --git a/lib/rpmhash_big.h b/lib/rpmhash_big.h
new file mode 100644
index 0000000..e6fcd29
--- /dev/null
+++ b/lib/rpmhash_big.h
@@ -0,0 +1,104 @@
+/**
+ * \file lib/rpmhash.h
+ * Hash table implemenation.
+ */
+
+#include <string.h>
+// Hackery to make sure that macros get expanded
+#define __JOIN(a,b) a##b
+#define JOIN(a,b) __JOIN(a,b)
+#define HASHPREFIX(name) JOIN(HASHTYPE,name)
+#define HASHSTRUCT JOIN(HASHTYPE,_s)
+
+typedef struct HASHSTRUCT * HASHTYPE;
+
+/* function pointer types to deal with the datatypes the hash works with */
+
+#define hashFunctionType JOIN(HASHTYPE,HashFunctionType)
+#define hashEqualityType JOIN(HASHTYPE,HashEqualityType)
+#define hashFreeKey JOIN(HASHTYPE,FreeKey)
+
+typedef unsigned int (*hashFunctionType) (HTKEYTYPE string);
+typedef int (*hashEqualityType) (HTKEYTYPE key1, HTKEYTYPE key2);
+typedef HTKEYTYPE (*hashFreeKey) (HTKEYTYPE);
+
+#ifdef HTDATATYPE
+#define hashFreeData JOIN(HASHTYPE,FreeData)
+typedef HTDATATYPE (*hashFreeData) (HTDATATYPE);
+#endif
+
+/**
+ * Create hash table.
+ * If keySize > 0, the key is duplicated within the table (which costs
+ * memory, but may be useful anyway.
+ * @param numBuckets number of hash buckets
+ * @param fn function to generate hash value for key
+ * @param eq function to compare hash keys for equality
+ * @param freeKey function to free the keys or NULL
+ * @param freeData function to free the data or NULL
+ * @return pointer to initialized hash table
+ */
+RPM_GNUC_INTERNAL
+HASHTYPE HASHPREFIX(Create)(int numBuckets,
+ hashFunctionType fn, hashEqualityType eq,
+ hashFreeKey freeKey
+#ifdef HTDATATYPE
+, hashFreeData freeData
+#endif
+);
+
+/**
+ * Destroy hash table.
+ * @param ht pointer to hash table
+ * @return NULL always
+ */
+RPM_GNUC_INTERNAL
+HASHTYPE HASHPREFIX(Free)( HASHTYPE ht);
+
+/**
+ * Add item to hash table.
+ * @param ht pointer to hash table
+ * @param key key
+ * @param data data value
+ */
+RPM_GNUC_INTERNAL
+void HASHPREFIX(AddEntry)(HASHTYPE ht, HTKEYTYPE key
+#ifdef HTDATATYPE
+, HTDATATYPE data
+#endif
+);
+
+#ifdef HTDATATYPE
+
+/**
+ * Retrieve item from hash table.
+ * @param ht pointer to hash table
+ * @param key key value
+ * @retval data address to store data value from bucket
+ * @retval dataCount address to store data value size from bucket
+ * @retval tableKey address to store key value from bucket (may be NULL)
+ * @return 1 on success, 0 if the item is not found.
+ */
+RPM_GNUC_INTERNAL
+int HASHPREFIX(GetEntry)(HASHTYPE ht, HTKEYTYPE key,
+ HTDATATYPE** data,
+ int * dataCount,
+ HTKEYTYPE* tableKey);
+#endif
+
+/**
+ * Check for key in hash table.
+ * @param ht pointer to hash table
+ * @param key key value
+ * @return 1 if the key is present, 0 otherwise
+ */
+RPM_GNUC_INTERNAL
+int HASHPREFIX(HasEntry)(HASHTYPE ht, HTKEYTYPE key);
+
+/**
+ * Print statistics about the hash to stderr
+ * This is for debugging only
+ * @param ht pointer to hash table
+ */
+RPM_GNUC_INTERNAL
+void HASHPREFIX(PrintStats)(HASHTYPE ht);