Blame lib/hash.h

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