← Commit list

7da2175b6b

Stefan Eissing
Stefan Eissing
2026-09-17
SUCCESS Duration: 400s

Subject

u8_strset: rename and mask

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

lib/Makefile.inc+2 -2
@@ -288,9 +288,9 @@ LIB_CFILES = \
thrdpool.c \
thrdqueue.c \
transfer.c \
+ u8_strset.c \
uint-bset.c \
uint-hash.c \
- uint-hashset.c \
uint-spbset.c \
uint-table.c \
url.c \
@@ -420,9 +420,9 @@ LIB_HFILES = \
thrdpool.h \
thrdqueue.h \
transfer.h \
+ u8_strset.h \
uint-bset.h \
uint-hash.h \
- uint-hashset.h \
uint-spbset.h \
uint-table.h \
url.h \
lib/uint-hashset.c → lib/u8_strset.c+16 -25
@@ -23,7 +23,7 @@
***************************************************************************/
#include "curl_setup.h"
-#include "uint-hashset.h"
+#include "u8_strset.h"
#include "curlx/strdup.h"
/* random patterns for API verification */
@@ -35,21 +35,10 @@
#define CURL_SWAP(a, b) (((a) ^= (b)), ((b) ^= (a)), ((a) ^= (b)))
-static const uint8_t u8_smask[] = {
- 0x00U,
- 0x01U,
- 0x03U,
- 0x07U,
- 0x0FU,
- 0x1FU,
- 0x3FU,
- 0x7FU,
- 0xFFU,
-};
-
-#define CURL_U8_SET_SLOT_IDX(s, i) (uint8_t)((i) & u8_smask[(s)->slotbits])
-#define CURL_U8_SLOT_CNT(i) ((uint16_t)u8_smask[(i)] + 1)
-#define CURL_U8_SET_SLOT_CNT(s) CURL_U8_SLOT_CNT((s)->slotbits)
+#define CURL_U8_STRSET_SLOT_IDX(s, i) (uint8_t)((i) & (s)->slotmask)
+#define CURL_U8_SLOT_CNT(i) (uint16_t)((i) ? (1U << (i)) : 0)
+#define CURL_U8_SLOT_MASK(i) (uint8_t)((1U << (i)) - 1)
+#define CURL_U8_STRSET_SLOT_CNT(s) CURL_U8_SLOT_CNT((s)->slotbits)
/* A hashset for tuples (id, string) using Robin Hood Hashing.
* <https://www.cs.cornell.edu/courses/JavaAndDS/files/hashing_RobinHood.pdf>
@@ -85,6 +74,7 @@ void Curl_u8_strset_init(struct u8_strset *set)
set->ids = set->sids;
set->psl = set->spsl;
set->slotbits = CURL_U8_STRSET_START_BITS;
+ set->slotmask = CURL_U8_SLOT_MASK(set->slotbits);
set->count = 0;
#ifdef DEBUGBUILD
set->init = CURL_U8_STRSET_MAGIC;
@@ -95,7 +85,7 @@ void Curl_u8_strset_clear(struct u8_strset *set)
{
uint16_t i;
DEBUGASSERT(set->init == CURL_U8_STRSET_MAGIC);
- for(i = 0; i < CURL_U8_SET_SLOT_CNT(set); ++i)
+ for(i = 0; i < CURL_U8_STRSET_SLOT_CNT(set); ++i)
curlx_safefree(set->data[i]);
if(set->data != set->sdata)
@@ -105,7 +95,7 @@ void Curl_u8_strset_clear(struct u8_strset *set)
static void u8_strset_addn(struct u8_strset *set, uint8_t id, char *val)
{
- uint8_t i = CURL_U8_SET_SLOT_IDX(set, id);
+ uint8_t i = CURL_U8_STRSET_SLOT_IDX(set, id);
uint8_t psl = 0;
while(set->data[i]) {
if(psl > set->psl[i]) { /* SWAP */
@@ -116,7 +106,7 @@ static void u8_strset_addn(struct u8_strset *set, uint8_t id, char *val)
CURL_SWAP(set->psl[i], psl);
CURL_SWAP(set->ids[i], id);
}
- i = CURL_U8_SET_SLOT_IDX(set, i + 1);
+ i = CURL_U8_STRSET_SLOT_IDX(set, i + 1);
++psl;
}
set->ids[i] = id;
@@ -159,6 +149,7 @@ static bool u8_strset_grow(struct u8_strset *set)
set->ids = (uint8_t *)d + (nslots * sizeof(char *));
set->psl = set->ids + nslots;
set->slotbits = nslotbits;
+ set->slotmask = CURL_U8_SLOT_MASK(set->slotbits);
set->count = 0;
/* re-add previous entries */
for(i = 0; i < CURL_U8_SLOT_CNT(prev_slots); ++i) {
@@ -173,7 +164,7 @@ static bool u8_strset_grow(struct u8_strset *set)
static bool u8_strset_get_index(struct u8_strset *set,
uint8_t id, uint8_t *pindex)
{
- uint8_t i = CURL_U8_SET_SLOT_IDX(set, id);
+ uint8_t i = CURL_U8_STRSET_SLOT_IDX(set, id);
uint8_t psl = 0;
while(set->data[i] && (psl <= set->psl[i])) {
if(set->ids[i] == id) {
@@ -183,7 +174,7 @@ static bool u8_strset_get_index(struct u8_strset *set,
#endif
return TRUE;
}
- i = CURL_U8_SET_SLOT_IDX(set, i + 1);
+ i = CURL_U8_STRSET_SLOT_IDX(set, i + 1);
++psl;
}
#if CURL_U8_STRSET_DEBUG
@@ -231,7 +222,7 @@ CURLcode Curl_u8_strset_setn(struct u8_strset *set,
return CURLE_OK;
}
/* `id` not in set yet, grow if full */
- if((set->count >= CURL_U8_SET_SLOT_CNT(set)) && !u8_strset_grow(set)) {
+ if((set->count >= CURL_U8_STRSET_SLOT_CNT(set)) && !u8_strset_grow(set)) {
curlx_free(str);
return CURLE_OUT_OF_MEMORY;
}
@@ -278,7 +269,7 @@ static void u8_strset_unset(struct u8_strset *set, uint8_t id, bool zero)
curlx_safefree(set->data[i]);
set->ids[i] = set->psl[i] = 0;
--set->count;
- j = CURL_U8_SET_SLOT_IDX(set, i + 1);
+ j = CURL_U8_STRSET_SLOT_IDX(set, i + 1);
/* shift all entries with positive psl "down" */
while(set->data[j] && set->psl[j]) {
set->data[i] = set->data[j];
@@ -287,7 +278,7 @@ static void u8_strset_unset(struct u8_strset *set, uint8_t id, bool zero)
set->data[j] = NULL;
set->ids[j] = set->psl[j] = 0;
i = j;
- j = CURL_U8_SET_SLOT_IDX(set, i + 1);
+ j = CURL_U8_STRSET_SLOT_IDX(set, i + 1);
}
}
}
@@ -309,7 +300,7 @@ CURLcode Curl_u8_strset_copy(struct u8_strset *dest, struct u8_strset *src)
DEBUGASSERT(src->init == CURL_U8_STRSET_MAGIC);
Curl_u8_strset_clear(dest);
- for(i = 0; !result && (i < CURL_U8_SET_SLOT_CNT(src)); ++i) {
+ for(i = 0; !result && (i < CURL_U8_STRSET_SLOT_CNT(src)); ++i) {
if(src->data[i])
result = u8_strset_set(dest, src->ids[i], src->data[i]);
}
lib/uint-hashset.h → lib/u8_strset.h+4 -3
@@ -1,5 +1,5 @@
-#ifndef HEADER_CURL_UINT_HASHSET_H
-#define HEADER_CURL_UINT_HASHSET_H
+#ifndef HEADER_CURL_U8_STRSET_H
+#define HEADER_CURL_U8_STRSET_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
@@ -53,6 +53,7 @@ struct u8_strset {
uint8_t spsl[CURL_U8_STRSET_START_DIM];
uint16_t count;
uint8_t slotbits;
+ uint8_t slotmask;
#ifdef DEBUGBUILD
int32_t init;
#endif
@@ -80,4 +81,4 @@ void Curl_u8_strset_unset0(struct u8_strset *set, uint8_t id);
CURLcode Curl_u8_strset_copy(struct u8_strset *dest, struct u8_strset *src);
-#endif /* HEADER_CURL_UINT_HASHSET_H */
+#endif /* HEADER_CURL_U8_STRSET_H */
lib/urldata.h+1 -1
@@ -69,7 +69,7 @@
#include "request.h"
#include "ratelimit.h"
#include "netrc.h"
-#include "uint-hashset.h"
+#include "u8_strset.h"
#include "vdns/asyn.h"
#include "vdns/hostip.h"
#include "vtls/vtls_config.h"
tests/data/test3211+2 -1
@@ -4,6 +4,7 @@
<keywords>
unittest
uint_bset
+u8_strset
</keywords>
</info>
@@ -13,7 +14,7 @@ uint_bset
unittest
</features>
<name>
-uint_bset and uint_hashset unit tests
+uint_bset and u8_strset unit tests
</name>
</client>
</testcase>
tests/unit/unit3211.c+3 -3
@@ -24,7 +24,7 @@
#include "unitcheck.h"
#include "urldata.h"
#include "uint-bset.h"
-#include "uint-hashset.h"
+#include "u8_strset.h"
#include "curl_trc.h"
static void t3211_check_bset(const char *name, uint32_t capacity,
@@ -130,7 +130,7 @@ static bool t3211_strcmp(const char *s1, const char *s2)
return s1 == s2;
}
-static void t3211_check_strset1(void)
+static void t3211_check_u8_strset(void)
{
struct u8_strset set;
char buf[128];
@@ -243,7 +243,7 @@ static CURLcode test_unit3211(const char *arg)
t3211_check_bset("s1", 100, s1, CURL_ARRAYSIZE(s1));
t3211_check_bset("s2", 1000, s2, CURL_ARRAYSIZE(s2));
- t3211_check_strset1();
+ t3211_check_u8_strset();
UNITTEST_END_SIMPLE
}