From 7e865e9ff7939c7e2205b2943fa3955e8c129728 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Mon, 17 Nov 2025 23:09:43 -0600 Subject: [PATCH 1/3] changes needed to implement unordered maps and sets see DFHack/df-structures#862 --- library/include/DataIdentity.h | 16 ++++++++- .../include/df/custom/hash/texture_fullid.h | 34 +++++++++++++++++++ .../df/custom/texture_fullid.methods.inc | 26 ++++++++++++++ library/modules/Gui.cpp | 7 ++-- library/xml | 2 +- 5 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 library/include/df/custom/hash/texture_fullid.h create mode 100644 library/include/df/custom/texture_fullid.methods.inc diff --git a/library/include/DataIdentity.h b/library/include/DataIdentity.h index 8a9e3c406b..ed4ca06ecd 100644 --- a/library/include/DataIdentity.h +++ b/library/include/DataIdentity.h @@ -29,9 +29,10 @@ distribution. #include #include #include +#include +#include #include #include -#include #include #include "DataDefs.h" @@ -748,6 +749,11 @@ namespace df static const container_identity *get(); }; + template struct identity_traits > + { + static const container_identity* get(); + }; + template<> struct identity_traits > { static const bit_array_identity identity; static const bit_container_identity *get() { return &identity; } @@ -831,6 +837,14 @@ namespace df return &identity; } + template + inline const container_identity* identity_traits >::get() + { + using container = std::set; + static const ro_stl_container_identity identity("unordered_set", identity_traits::get()); + return &identity; + } + template inline const container_identity *identity_traits>::get() { using container = std::map; diff --git a/library/include/df/custom/hash/texture_fullid.h b/library/include/df/custom/hash/texture_fullid.h new file mode 100644 index 0000000000..25eff39cf3 --- /dev/null +++ b/library/include/df/custom/hash/texture_fullid.h @@ -0,0 +1,34 @@ +#pragma once + +#include +#include +#include "df/texture_fullid.h" + +template<> +struct std::hash +{ + size_t operator()(df::texture_fullid const &t) const noexcept + { +// for some reason, bay12 used different hash methods on windows vs linux +#ifdef WIN32 + size_t h=std::hash{}(t.texpos); + auto u_hash=std::hash{}; + h^=u_hash(std::bit_cast(std::make_pair(t.r, t.g))); + h^=u_hash(std::bit_cast(std::make_pair(t.b, t.br)))<<1; + h^=u_hash(std::bit_cast(std::make_pair(t.bg, t.bb)))<<2; + h^=std::hash{}(t.flag.whole); + return h; +#else + size_t h=std::hash{}(t.texpos); + auto u_hash=std::hash{}; + h^=u_hash(t.r); + h^=u_hash(t.g)<<1; + h^=u_hash(t.b)<<2; + h^=u_hash(t.br)<<3; + h^=u_hash(t.bg)<<4; + h^=u_hash(t.bb)<<5; + h^=std::hash{}(t.flag.whole)<<6; + return h; +#endif + } +}; \ No newline at end of file diff --git a/library/include/df/custom/texture_fullid.methods.inc b/library/include/df/custom/texture_fullid.methods.inc new file mode 100644 index 0000000000..ff57b2f4c5 --- /dev/null +++ b/library/include/df/custom/texture_fullid.methods.inc @@ -0,0 +1,26 @@ +auto operator== (const texture_fullid &other) const { + return ( + this->texpos == other.texpos && + this->r == other.r && + this->g == other.g && + this->b == other.b && + this->br == other.br && + this->bg == other.bg && + this->bb == other.bb && + this->flag.whole == other.flag.whole + ); +} + +auto operator< (const texture_fullid &other) const { + if (this->texpos < other.texpos) return true; + if (this->r < other.r) return true; + if (this->g < other.g) return true; + if (this->b < other.b) return true; + if (this->br < other.br) return true; + if (this->bg < other.bg) return true; + if (this->bb < other.bb) return true; + if (this->flag.whole < other.flag.whole) return true; + return false; +} + + diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index 1e079da598..fae55ce9d7 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -2686,10 +2686,9 @@ void Gui::MTB_set_width(df::markup_text_boxst *mtb, int32_t n_width) df::widget * Gui::getWidget(df::widget_container *container, string name) { CHECK_NULL_POINTER(container); // ensure the compiler catches the change if we ever fix the template parameters - std::map & orig_field = container->children_by_name; - auto children_by_name = reinterpret_cast> *>(&orig_field); - if (children_by_name->contains(name)) - return (*children_by_name)[name].get(); + auto & children_by_name = container->children_by_name; + if (children_by_name.contains(name)) + return (children_by_name)[name].get(); return NULL; } diff --git a/library/xml b/library/xml index 48077a042d..461cd5a7e6 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 48077a042dff14de22d682de3afc6d9157203c81 +Subproject commit 461cd5a7e6773ea89e2795e6ef6cef1d3abdffc9 From c628dde44670d0a2948bfefab3a80e26cc70d9bd Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Mon, 17 Nov 2025 23:18:47 -0600 Subject: [PATCH 2/3] whitespacery --- .../include/df/custom/hash/texture_fullid.h | 38 +++++++++---------- .../df/custom/texture_fullid.methods.inc | 2 - 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/library/include/df/custom/hash/texture_fullid.h b/library/include/df/custom/hash/texture_fullid.h index 25eff39cf3..a1e4606e33 100644 --- a/library/include/df/custom/hash/texture_fullid.h +++ b/library/include/df/custom/hash/texture_fullid.h @@ -7,28 +7,28 @@ template<> struct std::hash { - size_t operator()(df::texture_fullid const &t) const noexcept + size_t operator()(df::texture_fullid const &t) const noexcept { // for some reason, bay12 used different hash methods on windows vs linux #ifdef WIN32 - size_t h=std::hash{}(t.texpos); - auto u_hash=std::hash{}; - h^=u_hash(std::bit_cast(std::make_pair(t.r, t.g))); - h^=u_hash(std::bit_cast(std::make_pair(t.b, t.br)))<<1; - h^=u_hash(std::bit_cast(std::make_pair(t.bg, t.bb)))<<2; - h^=std::hash{}(t.flag.whole); - return h; + size_t h=std::hash{}(t.texpos); + auto u_hash=std::hash{}; + h^=u_hash(std::bit_cast(std::make_pair(t.r, t.g))); + h^=u_hash(std::bit_cast(std::make_pair(t.b, t.br)))<<1; + h^=u_hash(std::bit_cast(std::make_pair(t.bg, t.bb)))<<2; + h^=std::hash{}(t.flag.whole); + return h; #else - size_t h=std::hash{}(t.texpos); - auto u_hash=std::hash{}; - h^=u_hash(t.r); - h^=u_hash(t.g)<<1; - h^=u_hash(t.b)<<2; - h^=u_hash(t.br)<<3; - h^=u_hash(t.bg)<<4; - h^=u_hash(t.bb)<<5; - h^=std::hash{}(t.flag.whole)<<6; - return h; + size_t h=std::hash{}(t.texpos); + auto u_hash=std::hash{}; + h^=u_hash(t.r); + h^=u_hash(t.g)<<1; + h^=u_hash(t.b)<<2; + h^=u_hash(t.br)<<3; + h^=u_hash(t.bg)<<4; + h^=u_hash(t.bb)<<5; + h^=std::hash{}(t.flag.whole)<<6; + return h; #endif } -}; \ No newline at end of file +}; diff --git a/library/include/df/custom/texture_fullid.methods.inc b/library/include/df/custom/texture_fullid.methods.inc index ff57b2f4c5..12e21f6735 100644 --- a/library/include/df/custom/texture_fullid.methods.inc +++ b/library/include/df/custom/texture_fullid.methods.inc @@ -22,5 +22,3 @@ auto operator< (const texture_fullid &other) const { if (this->flag.whole < other.flag.whole) return true; return false; } - - From 353f16395a627133b0a3c8a7942fe87cb2fef2eb Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Mon, 17 Nov 2025 23:31:20 -0600 Subject: [PATCH 3/3] Update xml --- library/xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/xml b/library/xml index 461cd5a7e6..00e1c5ea00 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 461cd5a7e6773ea89e2795e6ef6cef1d3abdffc9 +Subproject commit 00e1c5ea0071b716afad5a4140dc43e0ed7a8fbb