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 Core::CollapsedVector #78

Merged
merged 6 commits into from
Jan 8, 2025
Merged

Add Core::CollapsedVector #78

merged 6 commits into from
Jan 8, 2025

Conversation

SimBe195
Copy link
Collaborator

Vector that is automatically collapsed down to one element if all entries have the same value
From the outside it behaves like a normal vector. Whether it is collapsed or not only matters internally.

Example:

CollapsedVector<int> v;  // Internal data of v is [] with logical size 0
v.push_back(5);  // Normal push. Internal data of v is [5] with logical size 1
v.push_back(5);  // v stays collapsed. Internal data of v is [5] with logical size 2
std::cout << v.size() << std::endl;  // Prints "2"
std::cout << v[1] << std::endl;  // Prints "5"
v.push_back(6);  // v is expanded because the new value is different. Internal data of v is [5, 5, 6] with logical size 3
std::cout << v[2] << std::endl;  // Prints "6"
v.clear();  // Internal data of v is [] with logical size 0.

Copy link
Contributor

@curufinwe curufinwe left a comment

Choose a reason for hiding this comment

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

In addition to inline comments, please also add inline to the function definitions, s.t. the linker does not treat it as an error if two object files with the same symbol are linked together.

src/Core/CollapsedVector.hh Outdated Show resolved Hide resolved
src/Core/CollapsedVector.hh Outdated Show resolved Hide resolved
src/Core/CollapsedVector.hh Outdated Show resolved Hide resolved
@curufinwe curufinwe mentioned this pull request Nov 8, 2024
@SimBe195 SimBe195 requested a review from curufinwe December 5, 2024 10:17
@curufinwe curufinwe merged commit 51748d9 into master Jan 8, 2025
@curufinwe curufinwe deleted the collapsed-vector branch January 8, 2025 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants