Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new HashSet template #61194

Merged
merged 1 commit into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/config/project_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class ProjectSettings : public Object {
bool using_datapack = false;
List<String> input_presets;

RBSet<String> custom_features;
HashSet<String> custom_features;
HashMap<StringName, StringName> feature_overrides;

HashMap<StringName, AutoloadInfo> autoloads;
Expand Down
6 changes: 3 additions & 3 deletions core/debugger/local_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,15 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {

} else if (line.begins_with("br") || line.begins_with("break")) {
if (line.get_slice_count(" ") <= 1) {
const HashMap<int, RBSet<StringName>> &breakpoints = script_debugger->get_breakpoints();
const HashMap<int, HashSet<StringName>> &breakpoints = script_debugger->get_breakpoints();
if (breakpoints.size() == 0) {
print_line("No Breakpoints.");
continue;
}

print_line("Breakpoint(s): " + itos(breakpoints.size()));
for (const KeyValue<int, RBSet<StringName>> &E : breakpoints) {
print_line("\t" + String(E.value.front()->get()) + ":" + itos(E.key));
for (const KeyValue<int, HashSet<StringName>> &E : breakpoints) {
print_line("\t" + String(*E.value.begin()) + ":" + itos(E.key));
}

} else {
Expand Down
2 changes: 1 addition & 1 deletion core/debugger/script_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int ScriptDebugger::get_depth() const {

void ScriptDebugger::insert_breakpoint(int p_line, const StringName &p_source) {
if (!breakpoints.has(p_line)) {
breakpoints[p_line] = RBSet<StringName>();
breakpoints[p_line] = HashSet<StringName>();
}
breakpoints[p_line].insert(p_source);
}
Expand Down
6 changes: 3 additions & 3 deletions core/debugger/script_debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@

#include "core/object/script_language.h"
#include "core/string/string_name.h"
#include "core/templates/hash_set.h"
#include "core/templates/rb_map.h"
#include "core/templates/rb_set.h"
#include "core/templates/vector.h"

class ScriptDebugger {
Expand All @@ -44,7 +44,7 @@ class ScriptDebugger {
int depth = -1;
bool skip_breakpoints = false;

HashMap<int, RBSet<StringName>> breakpoints;
HashMap<int, HashSet<StringName>> breakpoints;

ScriptLanguage *break_lang = nullptr;
Vector<StackInfo> error_stack_info;
Expand All @@ -66,7 +66,7 @@ class ScriptDebugger {
bool is_breakpoint(int p_line, const StringName &p_source) const;
bool is_breakpoint_line(int p_line) const;
void clear_breakpoints();
const HashMap<int, RBSet<StringName>> &get_breakpoints() const { return breakpoints; }
const HashMap<int, HashSet<StringName>> &get_breakpoints() const { return breakpoints; }

void debug(ScriptLanguage *p_lang, bool p_can_continue = true, bool p_is_error_breakpoint = false);
ScriptLanguage *get_break_language() const;
Expand Down
1 change: 1 addition & 0 deletions core/input/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "core/object/object.h"
#include "core/os/keyboard.h"
#include "core/os/thread_safe.h"
#include "core/templates/rb_set.h"

class Input : public Object {
GDCLASS(Input, Object);
Expand Down
4 changes: 2 additions & 2 deletions core/io/file_access_pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
#include "core/io/dir_access.h"
#include "core/io/file_access.h"
#include "core/string/print_string.h"
#include "core/templates/hash_set.h"
#include "core/templates/list.h"
#include "core/templates/rb_map.h"
#include "core/templates/rb_set.h"

// Godot's packed file magic header ("GDPC" in ASCII).
#define PACK_HEADER_MAGIC 0x43504447
Expand Down Expand Up @@ -73,7 +73,7 @@ class PackedData {
PackedDir *parent = nullptr;
String name;
HashMap<String, PackedDir *> subdirs;
RBSet<String> files;
HashSet<String> files;
};

struct PathMD5 {
Expand Down
4 changes: 2 additions & 2 deletions core/io/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ String JSON::_make_indent(const String &p_indent, int p_size) {
return indent_text;
}

String JSON::_stringify(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys, RBSet<const void *> &p_markers, bool p_full_precision) {
String JSON::_stringify(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys, HashSet<const void *> &p_markers, bool p_full_precision) {
String colon = ":";
String end_statement = "";

Expand Down Expand Up @@ -529,7 +529,7 @@ Error JSON::_parse_string(const String &p_json, Variant &r_ret, String &r_err_st
}

String JSON::stringify(const Variant &p_var, const String &p_indent, bool p_sort_keys, bool p_full_precision) {
RBSet<const void *> markers;
HashSet<const void *> markers;
return _stringify(p_var, p_indent, 0, p_sort_keys, markers, p_full_precision);
}

Expand Down
2 changes: 1 addition & 1 deletion core/io/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class JSON : public RefCounted {
static const char *tk_name[];

static String _make_indent(const String &p_indent, int p_size);
static String _stringify(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys, RBSet<const void *> &p_markers, bool p_full_precision = false);
static String _stringify(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys, HashSet<const void *> &p_markers, bool p_full_precision = false);
static Error _get_token(const char32_t *p_str, int &index, int p_len, Token &r_token, int &line, String &r_err_str);
static Error _parse_value(Variant &value, Token &token, const char32_t *p_str, int &index, int p_len, int &line, String &r_err_str);
static Error _parse_array(Array &array, const char32_t *p_str, int &index, int p_len, int &line, String &r_err_str);
Expand Down
8 changes: 4 additions & 4 deletions core/io/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void RotatedFileLogger::clear_old_backups() {

da->list_dir_begin();
String f = da->get_next();
RBSet<String> backups;
HashSet<String> backups;
while (!f.is_empty()) {
if (!da->current_is_dir() && f.begins_with(basename) && f.get_extension() == extension && f != base_path.get_file()) {
backups.insert(f);
Expand All @@ -137,12 +137,12 @@ void RotatedFileLogger::clear_old_backups() {
}
da->list_dir_end();

if (backups.size() > max_backups) {
if (backups.size() > (uint32_t)max_backups) {
// since backups are appended with timestamp and Set iterates them in sorted order,
// first backups are the oldest
int to_delete = backups.size() - max_backups;
for (RBSet<String>::Element *E = backups.front(); E && to_delete > 0; E = E->next(), --to_delete) {
da->remove(E->get());
for (HashSet<String>::Iterator E = backups.begin(); E && to_delete > 0; ++E, --to_delete) {
da->remove(*E);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/io/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Resource : public RefCounted {
virtual String get_base_extension() const { return "res"; }

private:
RBSet<ObjectID> owners;
HashSet<ObjectID> owners;

friend class ResBase;
friend class ResourceCache;
Expand Down
2 changes: 1 addition & 1 deletion core/io/resource_format_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2022,7 +2022,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const Ref<Re
// save internal resource table
f->store_32(saved_resources.size()); //amount of internal resources
Vector<uint64_t> ofs_pos;
RBSet<String> used_unique_ids;
HashSet<String> used_unique_ids;

for (Ref<Resource> &r : saved_resources) {
if (r->is_built_in()) {
Expand Down
2 changes: 1 addition & 1 deletion core/io/resource_format_binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class ResourceFormatSaverBinaryInstance {
bool big_endian;
bool takeover_paths;
String magic;
RBSet<Ref<Resource>> resource_set;
HashSet<Ref<Resource>> resource_set;

struct NonPersistentKey { //for resource properties generated on the fly
Ref<Resource> base;
Expand Down
4 changes: 2 additions & 2 deletions core/io/resource_importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Ref<Resource> ResourceFormatImporter::load(const String &p_path, const String &p
}

void ResourceFormatImporter::get_recognized_extensions(List<String> *p_extensions) const {
RBSet<String> found;
HashSet<String> found;

for (int i = 0; i < importers.size(); i++) {
List<String> local_exts;
Expand All @@ -159,7 +159,7 @@ void ResourceFormatImporter::get_recognized_extensions_for_type(const String &p_
return;
}

RBSet<String> found;
HashSet<String> found;

for (int i = 0; i < importers.size(); i++) {
String res_type = importers[i]->get_resource_type();
Expand Down
2 changes: 1 addition & 1 deletion core/io/resource_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class ResourceLoader {
bool start_next = true;
int requests = 0;
int poll_requests = 0;
RBSet<String> sub_tasks;
HashSet<String> sub_tasks;
};

static void _thread_load_function(void *p_userdata);
Expand Down
24 changes: 12 additions & 12 deletions core/math/a_star.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,15 @@ void AStar3D::connect_points(int p_id, int p_with_id, bool bidirectional) {
s.direction = Segment::BIDIRECTIONAL;
}

RBSet<Segment>::Element *element = segments.find(s);
if (element != nullptr) {
s.direction |= element->get().direction;
HashSet<Segment, Segment>::Iterator element = segments.find(s);
if (element) {
s.direction |= element->direction;
if (s.direction == Segment::BIDIRECTIONAL) {
// Both are neighbours of each other now
a->unlinked_neighbours.remove(b->id);
b->unlinked_neighbours.remove(a->id);
}
segments.erase(element);
segments.remove(element);
}

segments.insert(s);
Expand All @@ -177,16 +177,16 @@ void AStar3D::disconnect_points(int p_id, int p_with_id, bool bidirectional) {
Segment s(p_id, p_with_id);
int remove_direction = bidirectional ? (int)Segment::BIDIRECTIONAL : s.direction;

RBSet<Segment>::Element *element = segments.find(s);
if (element != nullptr) {
HashSet<Segment, Segment>::Iterator element = segments.find(s);
if (element) {
// s is the new segment
// Erase the directions to be removed
s.direction = (element->get().direction & ~remove_direction);
s.direction = (element->direction & ~remove_direction);

a->neighbours.remove(b->id);
if (bidirectional) {
b->neighbours.remove(a->id);
if (element->get().direction != Segment::BIDIRECTIONAL) {
if (element->direction != Segment::BIDIRECTIONAL) {
a->unlinked_neighbours.remove(b->id);
b->unlinked_neighbours.remove(a->id);
}
Expand All @@ -198,7 +198,7 @@ void AStar3D::disconnect_points(int p_id, int p_with_id, bool bidirectional) {
}
}

segments.erase(element);
segments.remove(element);
if (s.direction != Segment::NONE) {
segments.insert(s);
}
Expand Down Expand Up @@ -235,10 +235,10 @@ Vector<int> AStar3D::get_point_connections(int p_id) {

bool AStar3D::are_points_connected(int p_id, int p_with_id, bool bidirectional) const {
Segment s(p_id, p_with_id);
const RBSet<Segment>::Element *element = segments.find(s);
const HashSet<Segment, Segment>::Iterator element = segments.find(s);

return element != nullptr &&
(bidirectional || (element->get().direction & s.direction) == s.direction);
return element &&
(bidirectional || (element->direction & s.direction) == s.direction);
}

void AStar3D::clear() {
Expand Down
7 changes: 5 additions & 2 deletions core/math/a_star.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ class AStar3D : public RefCounted {
};
unsigned char direction = NONE;

bool operator<(const Segment &p_s) const { return key < p_s.key; }
static uint32_t hash(const Segment &p_seg) {
return hash_one_uint64(p_seg.key);
}
bool operator==(const Segment &p_s) const { return key == p_s.key; }

Segment() {}
Segment(int p_from, int p_to) {
Expand All @@ -112,7 +115,7 @@ class AStar3D : public RefCounted {
uint64_t pass = 1;

OAHashMap<int, Point *> points;
RBSet<Segment> segments;
HashSet<Segment, Segment> segments;

bool _solve(Point *begin_point, Point *end_point);

Expand Down
2 changes: 1 addition & 1 deletion core/math/quick_hull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_

Vector<bool> valid_points;
valid_points.resize(p_points.size());
RBSet<Vector3> valid_cache;
HashSet<Vector3> valid_cache;

for (int i = 0; i < p_points.size(); i++) {
Vector3 sp = p_points[i].snapped(Vector3(0.0001, 0.0001, 0.0001));
Expand Down
2 changes: 1 addition & 1 deletion core/math/quick_hull.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@

#include "core/math/aabb.h"
#include "core/math/geometry_3d.h"
#include "core/templates/hash_set.h"
#include "core/templates/list.h"
#include "core/templates/rb_set.h"

class QuickHull {
public:
Expand Down
2 changes: 1 addition & 1 deletion core/math/static_raycaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class StaticRaycaster : public RefCounted {
virtual void add_mesh(const PackedVector3Array &p_vertices, const PackedInt32Array &p_indices, unsigned int p_id) = 0;
virtual void commit() = 0;

virtual void set_mesh_filter(const RBSet<int> &p_mesh_ids) = 0;
virtual void set_mesh_filter(const HashSet<int> &p_mesh_ids) = 0;
virtual void clear_mesh_filter() = 0;

static Ref<StaticRaycaster> create();
Expand Down
4 changes: 2 additions & 2 deletions core/multiplayer/multiplayer_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class MultiplayerAPI : public RefCounted {

private:
Ref<MultiplayerPeer> multiplayer_peer;
RBSet<int> connected_peers;
HashSet<int> connected_peers;
int remote_sender_id = 0;
int remote_sender_override = 0;

Expand Down Expand Up @@ -172,7 +172,7 @@ class MultiplayerAPI : public RefCounted {

bool has_multiplayer_peer() const { return multiplayer_peer.is_valid(); }
Vector<int> get_peer_ids() const;
const RBSet<int> get_connected_peers() const { return connected_peers; }
const HashSet<int> get_connected_peers() const { return connected_peers; }
int get_remote_sender_id() const { return remote_sender_override ? remote_sender_override : remote_sender_id; }
void set_remote_sender_override(int p_id) { remote_sender_override = p_id; }
int get_unique_id() const;
Expand Down
2 changes: 1 addition & 1 deletion core/object/class_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,7 @@ void ClassDB::get_extensions_for_type(const StringName &p_class, List<String> *p
}

HashMap<StringName, HashMap<StringName, Variant>> ClassDB::default_values;
RBSet<StringName> ClassDB::default_values_cached;
HashSet<StringName> ClassDB::default_values_cached;

Variant ClassDB::class_get_default_property_value(const StringName &p_class, const StringName &p_property, bool *r_valid) {
if (!default_values_cached.has(p_class)) {
Expand Down
5 changes: 3 additions & 2 deletions core/object/class_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
// Makes callable_mp readily available in all classes connecting signals.
// Needs to come after method_bind and object have been included.
#include "core/object/callable_method_pointer.h"
#include "core/templates/hash_set.h"

#define DEFVAL(m_defval) (m_defval)

Expand Down Expand Up @@ -110,7 +111,7 @@ class ClassDB {
#ifdef DEBUG_METHODS_ENABLED
List<StringName> constant_order;
List<StringName> method_order;
RBSet<StringName> methods_in_properties;
HashSet<StringName> methods_in_properties;
List<MethodInfo> virtual_methods;
HashMap<StringName, MethodInfo> virtual_methods_map;
HashMap<StringName, Vector<Error>> method_error_values;
Expand Down Expand Up @@ -149,7 +150,7 @@ class ClassDB {
static void _add_class2(const StringName &p_class, const StringName &p_inherits);

static HashMap<StringName, HashMap<StringName, Variant>> default_values;
static RBSet<StringName> default_values_cached;
static HashSet<StringName> default_values_cached;

// Native structs, used by binder
struct NativeStruct {
Expand Down
6 changes: 3 additions & 3 deletions core/object/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
#include "core/os/rw_lock.h"
#include "core/os/spin_lock.h"
#include "core/templates/hash_map.h"
#include "core/templates/hash_set.h"
#include "core/templates/list.h"
#include "core/templates/rb_map.h"
#include "core/templates/rb_set.h"
#include "core/templates/safe_refcount.h"
#include "core/templates/vmap.h"
#include "core/variant/callable_bind.h"
Expand Down Expand Up @@ -510,7 +510,7 @@ class Object {
#ifdef TOOLS_ENABLED
bool _edited = false;
uint32_t _edited_version = 0;
RBSet<String> editor_section_folding;
HashSet<String> editor_section_folding;
#endif
ScriptInstance *script_instance = nullptr;
Variant script; // Reference does not exist yet, store it in a Variant.
Expand Down Expand Up @@ -815,7 +815,7 @@ class Object {
#ifdef TOOLS_ENABLED
void editor_set_section_unfold(const String &p_section, bool p_unfolded);
bool editor_is_section_unfolded(const String &p_section);
const RBSet<String> &editor_get_section_folding() const { return editor_section_folding; }
const HashSet<String> &editor_get_section_folding() const { return editor_section_folding; }
void editor_clear_section_folding() { editor_section_folding.clear(); }

#endif
Expand Down
Loading