Blame gl/hash.h

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