Blame gl/hash.h

Packit Service 991b93
/* hash - hashing table processing.
Packit Service 991b93
   Copyright (C) 1998-1999, 2001, 2003, 2009-2020 Free Software Foundation,
Packit Service 991b93
   Inc.
Packit Service 991b93
   Written by Jim Meyering <meyering@ascend.com>, 1998.
Packit Service 991b93
Packit Service 991b93
   This program is free software: you can redistribute it and/or modify
Packit Service 991b93
   it under the terms of the GNU Lesser General Public License as published by
Packit Service 991b93
   the Free Software Foundation; either version 2.1 of the License, or
Packit Service 991b93
   (at your option) any later version.
Packit Service 991b93
Packit Service 991b93
   This program is distributed in the hope that it will be useful,
Packit Service 991b93
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 991b93
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 991b93
   GNU Lesser General Public License for more details.
Packit Service 991b93
Packit Service 991b93
   You should have received a copy of the GNU Lesser General Public License
Packit Service 991b93
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
Packit Service 991b93
Packit Service 991b93
/* A generic hash table package.  */
Packit Service 991b93
Packit Service 991b93
/* Make sure USE_OBSTACK is defined to 1 if you want the allocator to use
Packit Service 991b93
   obstacks instead of malloc, and recompile 'hash.c' with same setting.  */
Packit Service 991b93
Packit Service 991b93
#ifndef HASH_H_
Packit Service 991b93
# define HASH_H_
Packit Service 991b93
Packit Service 991b93
# include <stdio.h>
Packit Service 991b93
# include <stdbool.h>
Packit Service 991b93
Packit Service 991b93
typedef size_t (*Hash_hasher) (const void *, size_t);
Packit Service 991b93
typedef bool (*Hash_comparator) (const void *, const void *);
Packit Service 991b93
typedef void (*Hash_data_freer) (void *);
Packit Service 991b93
typedef bool (*Hash_processor) (void *, void *);
Packit Service 991b93
Packit Service 991b93
struct hash_tuning
Packit Service 991b93
  {
Packit Service 991b93
    /* This structure is mainly used for 'hash_initialize', see the block
Packit Service 991b93
       documentation of 'hash_reset_tuning' for more complete comments.  */
Packit Service 991b93
Packit Service 991b93
    float shrink_threshold;     /* ratio of used buckets to trigger a shrink */
Packit Service 991b93
    float shrink_factor;        /* ratio of new smaller size to original size */
Packit Service 991b93
    float growth_threshold;     /* ratio of used buckets to trigger a growth */
Packit Service 991b93
    float growth_factor;        /* ratio of new bigger size to original size */
Packit Service 991b93
    bool is_n_buckets;          /* if CANDIDATE really means table size */
Packit Service 991b93
  };
Packit Service 991b93
Packit Service 991b93
typedef struct hash_tuning Hash_tuning;
Packit Service 991b93
Packit Service 991b93
struct hash_table;
Packit Service 991b93
Packit Service 991b93
typedef struct hash_table Hash_table;
Packit Service 991b93
Packit Service 991b93
/* Information and lookup.  */
Packit Service 991b93
size_t hash_get_n_buckets (const Hash_table *) _GL_ATTRIBUTE_PURE;
Packit Service 991b93
size_t hash_get_n_buckets_used (const Hash_table *) _GL_ATTRIBUTE_PURE;
Packit Service 991b93
size_t hash_get_n_entries (const Hash_table *) _GL_ATTRIBUTE_PURE;
Packit Service 991b93
size_t hash_get_max_bucket_length (const Hash_table *) _GL_ATTRIBUTE_PURE;
Packit Service 991b93
bool hash_table_ok (const Hash_table *) _GL_ATTRIBUTE_PURE;
Packit Service 991b93
void hash_print_statistics (const Hash_table *, FILE *);
Packit Service 991b93
void *hash_lookup (const Hash_table *, const void *);
Packit Service 991b93
Packit Service 991b93
/* Walking.  */
Packit Service 991b93
void *hash_get_first (const Hash_table *) _GL_ATTRIBUTE_PURE;
Packit Service 991b93
void *hash_get_next (const Hash_table *, const void *);
Packit Service 991b93
size_t hash_get_entries (const Hash_table *, void **, size_t);
Packit Service 991b93
size_t hash_do_for_each (const Hash_table *, Hash_processor, void *);
Packit Service 991b93
Packit Service 991b93
/* Allocation and clean-up.  */
Packit Service 991b93
size_t hash_string (const char *, size_t) _GL_ATTRIBUTE_PURE;
Packit Service 991b93
void hash_reset_tuning (Hash_tuning *);
Packit Service 991b93
Hash_table *hash_initialize (size_t, const Hash_tuning *,
Packit Service 991b93
                             Hash_hasher, Hash_comparator,
Packit Service 991b93
                             Hash_data_freer) _GL_ATTRIBUTE_NODISCARD;
Packit Service 991b93
Hash_table *hash_xinitialize (size_t, const Hash_tuning *,
Packit Service 991b93
                              Hash_hasher, Hash_comparator,
Packit Service 991b93
                              Hash_data_freer) _GL_ATTRIBUTE_NODISCARD;
Packit Service 991b93
void hash_clear (Hash_table *);
Packit Service 991b93
void hash_free (Hash_table *);
Packit Service 991b93
Packit Service 991b93
/* Insertion and deletion.  */
Packit Service 991b93
bool hash_rehash (Hash_table *, size_t) _GL_ATTRIBUTE_NODISCARD;
Packit Service 991b93
void *hash_insert (Hash_table *, const void *) _GL_ATTRIBUTE_NODISCARD;
Packit Service 991b93
void *hash_xinsert (Hash_table *, const void *);
Packit Service 991b93
Packit Service 991b93
int hash_insert_if_absent (Hash_table *table, const void *entry,
Packit Service 991b93
                           const void **matched_ent);
Packit Service 991b93
void *hash_delete (Hash_table *, const void *);
Packit Service 991b93
Packit Service 991b93
#endif