libaaruformat 1.0 Aaru Data Preservation Suite - Format Library

Loading...
Searching...
No Matches
hash_map.h
Go to the documentation of this file.
1/*
2 * This file is part of the Aaru Data Preservation Suite.
3 * Copyright (c) 2019-2025 Natalia Portillo.
4 *
5 * This library is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as
7 * published by the Free Software Foundation; either version 2.1 of the
8 * License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef LIBAARUFORMAT_HASH_MAP_H
20#define LIBAARUFORMAT_HASH_MAP_H
21
22#include <stdbool.h>
23#include <stdlib.h>
24
32 typedef struct
33{
34 uint64_t key;
35 uint64_t value;
36} kv_pair_t;
37
49 typedef struct
50{
51 kv_pair_t *table;
52 size_t size;
53 size_t count;
54} hash_map_t;
55
56 hash_map_t *create_map(size_t size);
57 void free_map(hash_map_t *map);
58 bool insert_map(hash_map_t *map, uint64_t key, uint64_t value);
59 bool lookup_map(const hash_map_t *map, uint64_t key, uint64_t *out_value);
60
61#endif // LIBAARUFORMAT_HASH_MAP_H
lookup_map
bool lookup_map(const hash_map_t *map, uint64_t key, uint64_t *out_value)
Looks up a value by key in the hash map.
Definition hash_map.c:196
create_map
hash_map_t * create_map(size_t size)
Creates a new hash map with the specified initial size.
Definition hash_map.c:49
insert_map
bool insert_map(hash_map_t *map, uint64_t key, uint64_t value)
Inserts a key-value pair into the hash map.
Definition hash_map.c:153
free_map
void free_map(hash_map_t *map)
Frees all memory associated with a hash map.
Definition hash_map.c:73
hash_map_t
Minimal open-addressing hash map for 64-bit key/value pairs used in deduplication lookup.
Definition hash_map.h:50
hash_map_t::count
size_t count
Number of active (filled) entries.
Definition hash_map.h:53
hash_map_t::size
size_t size
Allocated slot capacity of table.
Definition hash_map.h:52
hash_map_t::table
kv_pair_t * table
Array of key/value slots of length == size.
Definition hash_map.h:51
kv_pair_t
Single key/value slot used internally by the open-addressing hash map.
Definition hash_map.h:33
kv_pair_t::value
uint64_t value
Associated value payload (64-bit) stored alongside the key.
Definition hash_map.h:35
kv_pair_t::key
uint64_t key
Stored key (64-bit). May use a reserved sentinel to denote an empty slot.
Definition hash_map.h:34