comparison mupdf-source/include/mupdf/fitz/hash.h @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 // Copyright (C) 2004-2021 Artifex Software, Inc.
2 //
3 // This file is part of MuPDF.
4 //
5 // MuPDF is free software: you can redistribute it and/or modify it under the
6 // terms of the GNU Affero General Public License as published by the Free
7 // Software Foundation, either version 3 of the License, or (at your option)
8 // any later version.
9 //
10 // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Affero General Public License
16 // along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>
17 //
18 // Alternative licensing terms are available from the licensor.
19 // For commercial licensing, see <https://www.artifex.com/> or contact
20 // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
21 // CA 94129, USA, for further information.
22
23 #ifndef MUPDF_FITZ_HASH_H
24 #define MUPDF_FITZ_HASH_H
25
26 #include "mupdf/fitz/system.h"
27 #include "mupdf/fitz/context.h"
28 #include "mupdf/fitz/output.h"
29
30 #define FZ_HASH_TABLE_KEY_LENGTH 48
31
32 /**
33 Generic hash-table with fixed-length keys.
34
35 The keys and values are NOT reference counted by the hash table.
36 Callers are responsible for taking care the reference counts are
37 correct. Inserting a duplicate entry will NOT overwrite the old
38 value, and will return the old value.
39
40 The drop_val callback function is only used to release values
41 when the hash table is destroyed.
42 */
43
44 typedef struct fz_hash_table fz_hash_table;
45
46 /**
47 Function type called when a hash table entry is dropped.
48
49 Only used when the entire hash table is dropped.
50 */
51 typedef void (fz_hash_table_drop_fn)(fz_context *ctx, void *val);
52
53 /**
54 Create a new hash table.
55
56 initialsize: The initial size of the hashtable. The hashtable
57 may grow (double in size) if it starts to get crowded (80%
58 full).
59
60 keylen: byte length for each key.
61
62 lock: -1 for no lock, otherwise the FZ_LOCK to use to protect
63 this table.
64
65 drop_val: Function to use to destroy values on table drop.
66 */
67 fz_hash_table *fz_new_hash_table(fz_context *ctx, int initialsize, int keylen, int lock, fz_hash_table_drop_fn *drop_val);
68
69 /**
70 Destroy the hash table.
71
72 Values are dropped using the drop function.
73 */
74 void fz_drop_hash_table(fz_context *ctx, fz_hash_table *table);
75
76 /**
77 Search for a matching hash within the table, and return the
78 associated value.
79 */
80 void *fz_hash_find(fz_context *ctx, fz_hash_table *table, const void *key);
81
82 /**
83 Insert a new key/value pair into the hash table.
84
85 If an existing entry with the same key is found, no change is
86 made to the hash table, and a pointer to the existing value is
87 returned.
88
89 If no existing entry with the same key is found, ownership of
90 val passes in, key is copied, and NULL is returned.
91 */
92 void *fz_hash_insert(fz_context *ctx, fz_hash_table *table, const void *key, void *val);
93
94 /**
95 Remove the entry for a given key.
96
97 The value is NOT freed, so the caller is expected to take care
98 of this.
99 */
100 void fz_hash_remove(fz_context *ctx, fz_hash_table *table, const void *key);
101
102 /**
103 Callback function called on each key/value pair in the hash
104 table, when fz_hash_for_each is run.
105 */
106 typedef void (fz_hash_table_for_each_fn)(fz_context *ctx, void *state, void *key, int keylen, void *val);
107
108 /**
109 Iterate over the entries in a hash table.
110 */
111 void fz_hash_for_each(fz_context *ctx, fz_hash_table *table, void *state, fz_hash_table_for_each_fn *callback);
112
113 /**
114 Callback function called on each key/value pair in the hash
115 table, when fz_hash_filter is run to remove entries where the
116 callback returns true.
117 */
118 typedef int (fz_hash_table_filter_fn)(fz_context *ctx, void *state, void *key, int keylen, void *val);
119
120 /**
121 Iterate over the entries in a hash table, removing all the ones where callback returns true.
122 Does NOT free the value of the entry, so the caller is expected to take care of this.
123 */
124 void fz_hash_filter(fz_context *ctx, fz_hash_table *table, void *state, fz_hash_table_filter_fn *callback);
125
126 #endif