diff options
author | Jacques Lucke <jacques@blender.org> | 2020-07-20 13:16:20 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-07-20 13:16:20 +0300 |
commit | 8cbbdedaf4dfec9e320e7e2be58b75d256950df1 (patch) | |
tree | 496b9620e11ac44e515b0bb4ca52c05834d557f9 /source/blender/blenlib/BLI_disjoint_set.hh | |
parent | 686ab4c9401a90b22fb17e46c992eb513fe4f693 (diff) |
Refactor: Update integer type usage
This updates the usage of integer types in code I wrote according to our new style guides.
Major changes:
* Use signed instead of unsigned integers in many places.
* C++ containers in blenlib use `int64_t` for size and indices now (instead of `uint`).
* Hash values for C++ containers are 64 bit wide now (instead of 32 bit).
I do hope that I broke no builds, but it is quite likely that some compiler reports
slightly different errors. Please let me know when there are any errors. If the fix
is small, feel free to commit it yourself.
I compiled successfully on linux with gcc and on windows.
Diffstat (limited to 'source/blender/blenlib/BLI_disjoint_set.hh')
-rw-r--r-- | source/blender/blenlib/BLI_disjoint_set.hh | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/source/blender/blenlib/BLI_disjoint_set.hh b/source/blender/blenlib/BLI_disjoint_set.hh index 3b8453669aa..e0580709a44 100644 --- a/source/blender/blenlib/BLI_disjoint_set.hh +++ b/source/blender/blenlib/BLI_disjoint_set.hh @@ -29,16 +29,17 @@ namespace blender { class DisjointSet { private: - Array<uint> parents_; - Array<uint> ranks_; + Array<int64_t> parents_; + Array<int64_t> ranks_; public: /** * Create a new disjoint set with the given size. Initially, every element is in a separate set. */ - DisjointSet(uint size) : parents_(size), ranks_(size, 0) + DisjointSet(int64_t size) : parents_(size), ranks_(size, 0) { - for (uint i = 0; i < size; i++) { + BLI_assert(size >= 0); + for (int64_t i = 0; i < size; i++) { parents_[i] = i; } } @@ -47,10 +48,10 @@ class DisjointSet { * Join the sets containing elements x and y. Nothing happens when they have been in the same set * before. */ - void join(uint x, uint y) + void join(int64_t x, int64_t y) { - uint root1 = this->find_root(x); - uint root2 = this->find_root(y); + int64_t root1 = this->find_root(x); + int64_t root2 = this->find_root(y); /* x and y are in the same set already. */ if (root1 == root2) { @@ -71,27 +72,27 @@ class DisjointSet { /** * Return true when x and y are in the same set. */ - bool in_same_set(uint x, uint y) + bool in_same_set(int64_t x, int64_t y) { - uint root1 = this->find_root(x); - uint root2 = this->find_root(y); + int64_t root1 = this->find_root(x); + int64_t root2 = this->find_root(y); return root1 == root2; } /** * Find the element that represents the set containing x currently. */ - uint find_root(uint x) + int64_t find_root(int64_t x) { /* Find root by following parents. */ - uint root = x; + int64_t root = x; while (parents_[root] != root) { root = parents_[root]; } /* Compress path. */ while (parents_[x] != root) { - uint parent = parents_[x]; + int64_t parent = parents_[x]; parents_[x] = root; x = parent; } |