1 /* Copyright (C) 2021 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
22 * Dbe Cache Map implementation.
24 * Simple Cache Map makes the following assumptions:
25 * - Cache Map is used for very fast but not guaranteed mapping;
26 * - No Relations can be used;
27 * - all objects used as keys or values has to be managed
28 * outside CacheMap (f.e. deletion);
31 #ifndef _DbeCacheMap_h
32 #define _DbeCacheMap_h
36 template <typename Key_t, class ITEM>
37 class DbeCacheMap : public Map<Key_t, ITEM *>
41 DbeCacheMap (int _size = DefaultSize)
42 { // _size should be 2 ** N
44 table = new DbeCache_T[size];
45 memset (table, 0, size * sizeof (DbeCache_T));
54 put (Key_t key, ITEM *val)
56 int ind = get_hash (key);
58 table[ind].value = val;
64 int ind = get_hash (key);
65 if (table[ind].key == key)
66 return table[ind].value;
73 int ind = get_hash (key);
74 ITEM *v = table[ind].value;
75 table[ind].value = (ITEM *) NULL;
80 get (Key_t /* key */, typename Map<Key_t, ITEM *>::Relation /* rel */)
89 DefaultSize = (1 << 13)
92 typedef struct DbeCache_S
103 unsigned long long h = (unsigned long long) key;
104 h ^= (h >> 20) ^ (h >> 12);
105 return (h ^ (h >> 7) ^ (h >> 4)) & (size - 1);