Changeset View
Changeset View
Standalone View
Standalone View
swh/perfecthash/hash.h
- This file was added.
/* | |||||
* Copyright (C) 2021 The Software Heritage developers | |||||
* See the AUTHORS file at the top-level directory of this distribution | |||||
* License: GNU General Public License version 3, or any later version | |||||
* See top-level LICENSE file for more information | |||||
*/ | |||||
#include <cmph.h> | |||||
#include <cmph_types.h> | |||||
/* | |||||
* The Read Shard has the following structure: | |||||
* | |||||
* - bytes [0, objects_position[ | |||||
* The header shard_header_t | |||||
* - bytes [objects_position, index_position[ | |||||
* objects_count times the size of the object (size_t) followed by the | |||||
* object itself | |||||
* - bytes [index_position, hash_position[ | |||||
* An array of size_t object positions in the range [objects_position, | |||||
* index_position[ The size of the array is provided by cmph_size after building | |||||
* the hash function | |||||
* - bytes [hash_position, ...[ | |||||
* The hash function, as written by cmph_dump | |||||
*/ | |||||
#define SHARD_OFFSET_HEADER 512 | |||||
#define SHARD_KEY_LEN 32 | |||||
typedef struct { | |||||
size_t objects_count; | |||||
size_t objects_position; | |||||
size_t objects_size; | |||||
size_t index_position; | |||||
size_t index_size; | |||||
size_t hash_position; | |||||
} shard_header_t; | |||||
typedef struct { | |||||
char key[SHARD_KEY_LEN]; | |||||
size_t object_offset; | |||||
} shard_index_t; | |||||
typedef struct { | |||||
char *path; | |||||
FILE *f; | |||||
shard_header_t header; | |||||
cmph_t *hash; | |||||
// The following fields are only used when creating the Read Shard | |||||
cmph_io_adapter_t *source; | |||||
cmph_config_t *config; | |||||
shard_index_t *index; | |||||
size_t index_offset; | |||||
} shard_t; | |||||
shard_t *shard_init(const char *path); | |||||
int shard_destroy(shard_t *shard); | |||||
int shard_create(shard_t *shard, size_t objects_count); | |||||
int shard_object_write(shard_t *shard, const char *key, const char *object, | |||||
size_t object_size); | |||||
int shard_save(shard_t *shard); | |||||
int shard_load(shard_t *shard); | |||||
int shard_lookup_object_size(shard_t *shard, const char *key, | |||||
size_t *object_size); | |||||
int shard_lookup_object(shard_t *shard, char *object, size_t object_size); |