for (off = 0; off < set->strs_data_len; off += strlen(set->strs_data + off) + 1) { /* hashmap__add() returns EEXIST if string with the same *contentalreadyisinthehashmap
*/
err = hashmap__add(hash, off, off); if (err == -EEXIST) continue; /* duplicate */ if (err) goto err_out;
}
}
/* Find string offset that corresponds to a given string *s*. *Returns: *->0offsetintostringdata,ifstringisfound; *--ENOENT,ifstringisnotinthestringdata; *-<0,onanyothererror.
*/ int strset__find_str(struct strset *set, constchar *s)
{ long old_off, new_off, len; void *p;
/* see strset__add_str() for why we do this */
len = strlen(s) + 1;
p = strset_add_str_mem(set, len); if (!p) return -ENOMEM;
new_off = set->strs_data_len;
memcpy(p, s, len);
if (hashmap__find(set->strs_hash, new_off, &old_off)) return old_off;
return -ENOENT;
}
/* Add a string s to the string data. If the string already exists, return its *offsetwithinstringdata. *Returns: *->0offsetintostringdata,onsuccess; *-<0,onerror.
*/ int strset__add_str(struct strset *set, constchar *s)
{ long old_off, new_off, len; void *p; int err;
/* Hashmap keys are always offsets within set->strs_data, so to even *lookupsomestringfromthe"outside",weneedtofirstappendit *attheend,sothatitcanbeaddressedwithanoffset.Luckily, *untilset->strs_data_lenisincremented,thatstringisjustapiece *ofgarbagefortherestofthecode,sonoharm,nofoul.Onthe *otherhand,ifthestringisunique,it'salreadyappendedand *readytobeused,onlyasimpleset->strs_data_lenincrementaway.
*/
len = strlen(s) + 1;
p = strset_add_str_mem(set, len); if (!p) return -ENOMEM;
new_off = set->strs_data_len;
memcpy(p, s, len);
/* Now attempt to add the string, but only if the string with the same *contentsdoesn'texistalready(HASHMAP_ADDstrategy).Ifsuch *stringexists,we'llgetitsoffsetinold_off(that'sold_key).
*/
err = hashmap__insert(set->strs_hash, new_off, new_off,
HASHMAP_ADD, &old_off, NULL); if (err == -EEXIST) return old_off; /* duplicated string, return existing offset */ if (err) return err;
set->strs_data_len += len; /* new unique string, adjust data length */ return new_off;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.21 Sekunden
(vorverarbeitet am 2026-09-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.