summaryrefslogtreecommitdiffstats
path: root/Include/internal
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-05-14 19:55:47 (GMT)
committerGitHub <noreply@github.com>2020-05-14 19:55:47 (GMT)
commita482dc500b6ec4889f6a126ba08cbad6c11e37bc (patch)
treec12cf1f1598899627c9fa0aed9fa317bceebe0dc /Include/internal
parentf2c3b6823bc4777d4a14eb0c3615b719521f763a (diff)
downloadcpython-a482dc500b6ec4889f6a126ba08cbad6c11e37bc.zip
cpython-a482dc500b6ec4889f6a126ba08cbad6c11e37bc.tar.gz
cpython-a482dc500b6ec4889f6a126ba08cbad6c11e37bc.tar.bz2
bpo-40602: Write unit tests for _Py_hashtable_t (GH-20091)
Cleanup also hashtable.c. Rename _Py_hashtable_t members: * Rename entries to nentries * Rename num_buckets to nbuckets
Diffstat (limited to 'Include/internal')
-rw-r--r--Include/internal/pycore_hashtable.h23
1 files changed, 12 insertions, 11 deletions
diff --git a/Include/internal/pycore_hashtable.h b/Include/internal/pycore_hashtable.h
index 2990f9e..18757ab 100644
--- a/Include/internal/pycore_hashtable.h
+++ b/Include/internal/pycore_hashtable.h
@@ -48,18 +48,18 @@ typedef _Py_hashtable_entry_t* (*_Py_hashtable_get_entry_func)(_Py_hashtable_t *
const void *key);
typedef struct {
- /* allocate a memory block */
+ // Allocate a memory block
void* (*malloc) (size_t size);
- /* release a memory block */
+ // Release a memory block
void (*free) (void *ptr);
} _Py_hashtable_allocator_t;
/* _Py_hashtable: table */
struct _Py_hashtable_t {
- size_t num_buckets;
- size_t entries; /* Total number of entries in the table. */
+ size_t nentries; // Total number of entries in the table
+ size_t nbuckets;
_Py_slist_t *buckets;
_Py_hashtable_get_entry_func get_entry_func;
@@ -70,10 +70,10 @@ struct _Py_hashtable_t {
_Py_hashtable_allocator_t alloc;
};
-/* hash a pointer (void*) */
+/* Hash a pointer (void*) */
PyAPI_FUNC(Py_uhash_t) _Py_hashtable_hash_ptr(const void *key);
-/* comparison using memcmp() */
+/* Comparison using memcmp() */
PyAPI_FUNC(int) _Py_hashtable_compare_direct(
const void *key1,
const void *key2);
@@ -129,13 +129,14 @@ _Py_hashtable_get_entry(_Py_hashtable_t *ht, const void *key)
Use _Py_hashtable_get_entry() to distinguish entry value equal to NULL
and entry not found. */
-extern void *_Py_hashtable_get(_Py_hashtable_t *ht, const void *key);
+PyAPI_FUNC(void*) _Py_hashtable_get(_Py_hashtable_t *ht, const void *key);
-// Remove a key and its associated value without calling key and value destroy
-// functions.
-// Return the removed value if the key was found.
-// Return NULL if the key was not found.
+/* Remove a key and its associated value without calling key and value destroy
+ functions.
+
+ Return the removed value if the key was found.
+ Return NULL if the key was not found. */
PyAPI_FUNC(void*) _Py_hashtable_steal(
_Py_hashtable_t *ht,
const void *key);