2 * A string cache, possibly with a bounded size, using FIFO order to control
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
11 #ifndef __FIFO_STRING_CACHE_H__
12 #define __FIFO_STRING_CACHE_H__
18 #include "ws_symbol_export.h"
22 #endif /* __cplusplus */
29 } fifo_string_cache_t
;
31 // These functions are marked with WS_DLL_PUBLIC so they can be unit-tested
33 // Initialize an object. If string_free_func is given, then the
34 // fifo_string_cache owns the string data, and will call this string_free_func
35 // during fifo_string_cache_free().
36 // If string_free_func is NULL, then the caller owns the string data, and it is
37 // the caller that is responsible for freeing the data.
39 fifo_string_cache_init(fifo_string_cache_t
*fcache
, unsigned max_entries
, GDestroyNotify string_free_func
);
41 // Free all memory owned by the fifo_string_cache. Whether or not the
42 // fifoe_string_cache owns the actual strings depends on whether a
43 // string_free_func was passed in during fifo_string_cache_init().
45 fifo_string_cache_free(fifo_string_cache_t
*fcache
);
47 // Does the cache contain a specific string?
49 fifo_string_cache_contains(fifo_string_cache_t
*fcache
, const char *entry
);
51 // Insert a string. The return value indicates whether the string was already
52 // in the cache before this function was called. If the string was newly
53 // inserted, and max_entries is > 0, and inserting the string would have caused
54 // max_entries to be exceeded, the oldest inserted key is removed (FIFO order).
56 fifo_string_cache_insert(fifo_string_cache_t
*fcache
, const char *entry
);
60 #endif /* __cplusplus */
62 #endif /* __FIFO_STRING_CACHE_H__ */