2012-02-11 04:16:17 +00:00
|
|
|
/*
|
2010-09-25 01:54:58 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2012-02-11 04:16:17 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2010-09-25 01:54:58 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2008 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
2018-06-17 16:32:54 +02:00
|
|
|
|
2012-02-12 14:40:08 +00:00
|
|
|
#ifndef __BLI_SMALLHASH_H__
|
|
|
|
#define __BLI_SMALLHASH_H__
|
2010-09-25 01:54:58 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup bli
|
2011-09-09 02:52:20 +00:00
|
|
|
*/
|
2010-09-25 01:54:58 +00:00
|
|
|
|
2013-09-01 15:01:15 +00:00
|
|
|
#include "BLI_compiler_attrs.h"
|
|
|
|
|
2011-09-09 02:52:20 +00:00
|
|
|
typedef struct {
|
|
|
|
uintptr_t key;
|
|
|
|
void *val;
|
|
|
|
} SmallHashEntry;
|
2010-09-25 01:54:58 +00:00
|
|
|
|
2014-02-02 02:19:11 +11:00
|
|
|
/* how much stack space to use before dynamically allocating memory.
|
|
|
|
* set to match one of the values in 'hashsizes' to avoid too many mallocs */
|
|
|
|
#define SMSTACKSIZE 131
|
2010-09-25 01:54:58 +00:00
|
|
|
typedef struct SmallHash {
|
2014-01-30 20:51:44 +11:00
|
|
|
unsigned int nbuckets;
|
|
|
|
unsigned int nentries;
|
|
|
|
unsigned int cursize;
|
2014-02-02 02:19:11 +11:00
|
|
|
|
|
|
|
SmallHashEntry *buckets;
|
|
|
|
SmallHashEntry buckets_stack[SMSTACKSIZE];
|
2010-09-25 01:54:58 +00:00
|
|
|
} SmallHash;
|
|
|
|
|
2011-09-09 02:52:20 +00:00
|
|
|
typedef struct {
|
2014-12-18 13:12:25 +01:00
|
|
|
const SmallHash *sh;
|
2013-06-22 20:20:06 +00:00
|
|
|
unsigned int i;
|
2011-04-13 21:48:16 +00:00
|
|
|
} SmallHashIter;
|
|
|
|
|
2014-02-02 17:08:26 +11:00
|
|
|
void BLI_smallhash_init_ex(SmallHash *sh,
|
|
|
|
const unsigned int nentries_reserve) ATTR_NONNULL(1);
|
2014-01-30 20:51:44 +11:00
|
|
|
void BLI_smallhash_init(SmallHash *sh) ATTR_NONNULL(1);
|
|
|
|
void BLI_smallhash_release(SmallHash *sh) ATTR_NONNULL(1);
|
|
|
|
void BLI_smallhash_insert(SmallHash *sh, uintptr_t key, void *item) ATTR_NONNULL(1);
|
2014-12-09 17:18:05 +01:00
|
|
|
bool BLI_smallhash_reinsert(SmallHash *sh, uintptr_t key, void *item) ATTR_NONNULL(1);
|
2014-01-30 20:51:44 +11:00
|
|
|
bool BLI_smallhash_remove(SmallHash *sh, uintptr_t key) ATTR_NONNULL(1);
|
2014-12-18 13:12:25 +01:00
|
|
|
void *BLI_smallhash_lookup(const SmallHash *sh, uintptr_t key) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
|
|
|
|
void **BLI_smallhash_lookup_p(const SmallHash *sh, uintptr_t key) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
|
|
|
|
bool BLI_smallhash_haskey(const SmallHash *sh, uintptr_t key) ATTR_NONNULL(1);
|
2018-02-15 23:36:11 +11:00
|
|
|
int BLI_smallhash_len(const SmallHash *sh) ATTR_NONNULL(1);
|
2013-09-01 15:01:15 +00:00
|
|
|
void *BLI_smallhash_iternext(SmallHashIter *iter, uintptr_t *key) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
|
2014-12-09 17:18:05 +01:00
|
|
|
void **BLI_smallhash_iternext_p(SmallHashIter *iter, uintptr_t *key) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
|
2014-12-18 13:12:25 +01:00
|
|
|
void *BLI_smallhash_iternew(const SmallHash *sh, SmallHashIter *iter, uintptr_t *key) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
|
|
|
|
void **BLI_smallhash_iternew_p(const SmallHash *sh, SmallHashIter *iter, uintptr_t *key) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
|
2014-01-30 20:51:44 +11:00
|
|
|
/* void BLI_smallhash_print(SmallHash *sh); */ /* UNUSED */
|
2011-04-13 21:48:16 +00:00
|
|
|
|
2014-08-23 21:15:15 +10:00
|
|
|
#ifdef DEBUG
|
|
|
|
double BLI_smallhash_calc_quality(SmallHash *sh);
|
|
|
|
#endif
|
|
|
|
|
2012-02-12 14:40:08 +00:00
|
|
|
#endif /* __BLI_SMALLHASH_H__ */
|