Skip to content

Commit

Permalink
Update colony implementation to v5.10
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ifreund committed Jun 13, 2019
1 parent 62d8cc6 commit 2e04c54
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/colony.h
Original file line number Diff line number Diff line change
Expand Up @@ -2330,9 +2330,12 @@ class colony : private element_allocator_type
}

void reserve( const size_type original_reserve_amount ) {
assert( original_reserve_amount > 2 );
if( original_reserve_amount == 0 || original_reserve_amount <= total_capacity ) {
// Already have enough space allocated
return;
}

skipfield_type reserve_amount = static_cast<skipfield_type>( original_reserve_amount );
skipfield_type reserve_amount;

if( original_reserve_amount > static_cast<size_type>
( group_allocator_pair.max_elements_per_group ) ) {
Expand All @@ -2342,6 +2345,8 @@ class colony : private element_allocator_type
reserve_amount = pointer_allocator_pair.min_elements_per_group;
} else if( original_reserve_amount > max_size() ) {
reserve_amount = static_cast<skipfield_type>( max_size() );
} else {
reserve_amount = static_cast<skipfield_type>( original_reserve_amount );
}

if( total_number_of_elements == 0 ) { // Most common scenario - empty colony
Expand All @@ -2355,8 +2360,6 @@ class colony : private element_allocator_type
// last_endpoint initially == elements + 1 via default constructor
begin_iterator.group_pointer->last_endpoint = begin_iterator.group_pointer->elements;
begin_iterator.group_pointer->number_of_elements = 0; // 1 by default
} else if( reserve_amount <= total_capacity ) { // Already have enough space allocated
return;
} else { // Non-empty colony, don't have enough space allocated
const skipfield_type original_min_elements = pointer_allocator_pair.min_elements_per_group;
// Make sure all groups are at maximum appropriate capacity (this amount already rounded down to a skipfield type earlier in function)
Expand Down

0 comments on commit 2e04c54

Please sign in to comment.