Skip to content

Commit

Permalink
Fix hash collision in string pool
Browse files Browse the repository at this point in the history
  • Loading branch information
e-n-f committed Jun 7, 2024
1 parent 879a78d commit 90a7311
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
#include "errors.hpp"
#include "text.hpp"

inline int swizzlecmp(const char *a, int atype, unsigned long long ahash, const char *b, int btype, unsigned long long bhash) {
if (ahash == bhash) {
inline long long swizzlecmp(const char *a, int atype, unsigned long long ahash, const char *b, int btype, unsigned long long bhash) {
if ((long long) ahash == (long long) bhash) {
if (atype == btype) {
return strcmp(a, b);
} else {
return atype - btype;
}
} else {
return (int) (ahash - bhash);
return (long long) (ahash - bhash);
}
}

Expand All @@ -44,10 +44,10 @@ long long addpool(struct memfile *poolfile, struct memfile *treefile, const char
}

while (*sp != 0) {
int cmp = swizzlecmp(s, type, hash,
poolfile->map.c_str() + ((struct stringpool *) (treefile->map.c_str() + *sp))->off + 1,
(poolfile->map.c_str() + ((struct stringpool *) (treefile->map.c_str() + *sp))->off)[0],
((struct stringpool *) (treefile->map.c_str() + *sp))->hash);
long long cmp = swizzlecmp(s, type, hash,
poolfile->map.c_str() + ((struct stringpool *) (treefile->map.c_str() + *sp))->off + 1,
(poolfile->map.c_str() + ((struct stringpool *) (treefile->map.c_str() + *sp))->off)[0],
((struct stringpool *) (treefile->map.c_str() + *sp))->hash);

if (cmp < 0) {
sp = &(((struct stringpool *) (treefile->map.c_str() + *sp))->left);
Expand Down
4 changes: 2 additions & 2 deletions tests/overture-235/out/-z0.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
}, "features": [
{ "type": "FeatureCollection", "properties": { "zoom": 0, "x": 0, "y": 0 }, "features": [
{ "type": "FeatureCollection", "properties": { "layer": "in", "version": 2, "extent": 4096 }, "features": [
{ "type": "Feature", "id": 1096239, "properties": { "id": "085070173fffffff014fa86038bb5217", "@name": "[[{\"division_id\":\"085bc6b4ffffffff01fb3b67a2808435\",\"subtype\":\"country\",\"name\":\"Perú\"},{\"division_id\":\"08559acaffffffff01f27abb0a0cb14b\",\"subtype\":\"region\",\"name\":\"Arequipa\"},{\"division_id\":\"0856c834ffffffff01fd8ac1c98804cb\",\"subtype\":\"county\",\"name\":\"Caravelí\"},{\"division_id\":\"0856c53b7fffffff019e8d5b8b047485\",\"subtype\":\"locality\",\"name\":\"Chaparra\"},{\"division_id\":\"0856c5143fffffff0138e27e7a03f7d8\",\"subtype\":\"locality\",\"name\":\"Andenes\"}]]", "subtype": "county", "local_type": "{\"en\":\"county\"}", "country": "GB", "region": "GB-ENG", "hierarchies": "[[{\"division_id\":\"085eea613fffffff01a8a15aa3da4c44\",\"subtype\":\"country\",\"name\":\"United Kingdom\"},{\"division_id\":\"085255dd7fffffff011aba243af254bd\",\"subtype\":\"region\",\"name\":\"England\"},{\"division_id\":\"085070173fffffff014fa86038bb5217\",\"subtype\":\"county\",\"name\":\"Hammersmith And Fulham\"}]]", "parent_division_id": "085255dd7fffffff011aba243af254bd", "names": "{\"primary\":\"Hammersmith And Fulham\",\"common\":null,\"rules\":null}", "version": 0, "update_time": "2024-05-11T06:57:45Z", "sources": "[{\"property\":\"\",\"dataset\":\"geoBoundaries\",\"record_id\":\"GBR9080712B6991151074246\",\"confidence\":null}]" }, "geometry": { "type": "Point", "coordinates": [ -0.263672, 51.508742 ] } }
{ "type": "Feature", "id": 1096239, "properties": { "id": "085070173fffffff014fa86038bb5217", "@name": "Hammersmith And Fulham", "subtype": "county", "local_type": "{\"en\":\"county\"}", "country": "GB", "region": "GB-ENG", "hierarchies": "[[{\"division_id\":\"085eea613fffffff01a8a15aa3da4c44\",\"subtype\":\"country\",\"name\":\"United Kingdom\"},{\"division_id\":\"085255dd7fffffff011aba243af254bd\",\"subtype\":\"region\",\"name\":\"England\"},{\"division_id\":\"085070173fffffff014fa86038bb5217\",\"subtype\":\"county\",\"name\":\"Hammersmith And Fulham\"}]]", "parent_division_id": "085255dd7fffffff011aba243af254bd", "names": "{\"primary\":\"Hammersmith And Fulham\",\"common\":null,\"rules\":null}", "version": 0, "update_time": "2024-05-11T06:57:45Z", "sources": "[{\"property\":\"\",\"dataset\":\"geoBoundaries\",\"record_id\":\"GBR9080712B6991151074246\",\"confidence\":null}]" }, "geometry": { "type": "Point", "coordinates": [ -0.263672, 51.508742 ] } }
,
{ "type": "Feature", "id": 92526, "properties": { "id": "0856c5143fffffff0138e27e7a03f7d8", "@name": "Andenes", "subtype": "locality", "local_type": "{\"en\":\"hamlet\"}", "country": "PE", "region": "PE-ARE", "hierarchies": "[[{\"division_id\":\"085bc6b4ffffffff01fb3b67a2808435\",\"subtype\":\"country\",\"name\":\"Perú\"},{\"division_id\":\"08559acaffffffff01f27abb0a0cb14b\",\"subtype\":\"region\",\"name\":\"Arequipa\"},{\"division_id\":\"0856c834ffffffff01fd8ac1c98804cb\",\"subtype\":\"county\",\"name\":\"Caravelí\"},{\"division_id\":\"0856c53b7fffffff019e8d5b8b047485\",\"subtype\":\"locality\",\"name\":\"Chaparra\"},{\"division_id\":\"0856c5143fffffff0138e27e7a03f7d8\",\"subtype\":\"locality\",\"name\":\"Andenes\"}]]", "parent_division_id": "0856c53b7fffffff019e8d5b8b047485", "names": "{\"primary\":\"Andenes\",\"common\":{\"en\":\"Andenes\",\"es\":\"Andenes\"},\"rules\":null}", "version": 0, "update_time": "2024-05-11T06:56:01Z", "sources": "[{\"property\":\"\",\"dataset\":\"OpenStreetMap\",\"record_id\":\"N3522957503\",\"confidence\":null}]" }, "geometry": { "type": "Point", "coordinates": [ -73.828125, -15.707663 ] } }
,
{ "type": "Feature", "properties": { "one": "Poull Bojer" }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
,
{ "type": "Feature", "properties": { "two": "Poull Bojer" }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
{ "type": "Feature", "properties": { "two": "[[{\"division_id\":\"085ec5c23fffffff01339442745f3d55\",\"subtype\":\"country\",\"name\":\"Ecuador\"},{\"division_id\":\"085dac297fffffff0147c020488d610d\",\"subtype\":\"region\",\"name\":\"Cotopaxi\"},{\"division_id\":\"085bf1b2ffffffff012715ee575c3475\",\"subtype\":\"county\",\"name\":\"Sigchos\"},{\"division_id\":\"085bf010ffffffff014f248c7b4fe243\",\"subtype\":\"locality\",\"name\":\"Sigchos\"},{\"division_id\":\"085bf03a3fffffff01145a02d706b16f\",\"subtype\":\"locality\",\"name\":\"Tiliguila\"}]]" }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
] }
] }
] }

0 comments on commit 90a7311

Please sign in to comment.