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 colony data structure #31338

Merged
merged 7 commits into from
Jun 13, 2019
Merged

Add colony data structure #31338

merged 7 commits into from
Jun 13, 2019

Conversation

ifreund
Copy link
Contributor

@ifreund ifreund commented Jun 11, 2019

Summary

SUMMARY: Infrastructure "Add colony data structure."

Purpose of change

The intent is to used this data structure to replace how we store items on the map.

There are several issues with using our current data structure of an std::list. In particular, removal of elements from the "middle" of the list invalidates references and iterators to elements after the one removed. This makes the item management code convoluted, and in some cases severely technically limited.

Describe the solution

Introduce a new data structure, colony that has the following major advantages over std::list:

You can read about all the details and more about the justification here: https://www.plflib.org/colony.htm

This implementation is taken directly from https://github.com/mattreecebentley/plf_colony and modified to fit into our code better

This pull request does not yet reimplement item_stack using a colony, that will come in a subsequent PR. I just wanted to get the data structure/implementation itself up for formal review.

Additional context

I'm not quite done with this, I intend to remove the preprocessor directives for supporting older c++ compilers/versions than we support to further clean up the code.

Also, it would be probably be polite to acknowledge that we are using a modified version of the PLF implementation somewhere in the project documentation, but I wasn't sure where best to put this. Will defer to @kevingranade on that.

@ifreund ifreund added [C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style labels Jun 11, 2019
#define COLONY_DESTROY(the_allocator, allocator_instance, location) std::allocator_traits<the_allocator>::destroy(allocator_instance, location)
#define COLONY_ALLOCATE(the_allocator, allocator_instance, size, hint) std::allocator_traits<the_allocator>::allocate(allocator_instance, size, hint)
#define COLONY_ALLOCATE_INITIALIZATION(the_allocator, size, hint) std::allocator_traits<the_allocator>::allocate(*this, size, hint)
#define COLONY_DEALLOCATE(the_allocator, allocator_instance, location, size) std::allocator_traits<the_allocator>::deallocate(allocator_instance, location, size)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could get rid of these now too, trying to decide if its worth the effort...

@ifreund
Copy link
Contributor Author

ifreund commented Jun 12, 2019

I'm in the process of porting the test suite from plf over to our catch2 testing environment. Once that is finished, this should be ready to go.

@ifreund ifreund force-pushed the colony branch 3 times, most recently from a28ab96 to 863317e Compare June 13, 2019 01:04
@ifreund
Copy link
Contributor Author

ifreund commented Jun 13, 2019

Alright, we now have 1000 lines of test cases making sure this works as expected. I'm calling this done, barring additional code cleanup suggestions.

@ifreund ifreund marked this pull request as ready for review June 13, 2019 01:06
ifreund added 7 commits June 13, 2019 14:50
- colony basics (simple insertion/erasure/iterator testing)
- insert and erase
- range erase
- sort
- insertion methods
- perfect forwarding
- emplace
- group size and capacity
- splice

Delete `group_size_sum()` from colony as it is only needed for debugging
Correction to reserve() semantics. Reserve() also will no longer assert that reserve amount is within bounds of maximum and minimum group sizes, and will silently round the value down or up accordingly. Please consult the documentation to understand the current limitations of reserve() for colony.
@ifreund
Copy link
Contributor Author

ifreund commented Jun 13, 2019

plflib just released a small update, so I applied that too.

@kevingranade kevingranade merged commit 4fce0ca into CleverRaven:master Jun 13, 2019
@ifreund ifreund deleted the colony branch June 13, 2019 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants