btree: fix sign-compare warnings (#800)

pull/802/head
Dominic Chen 5 years ago committed by GitHub
parent 1fd58b69c6
commit 40fdb59d37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      absl/container/internal/btree.h

@ -2278,11 +2278,11 @@ void btree<P>::rebalance_or_split(iterator *iter) {
// inserting at the end of the right node then we bias rebalancing to // inserting at the end of the right node then we bias rebalancing to
// fill up the left node. // fill up the left node.
int to_move = (kNodeValues - left->count()) / int to_move = (kNodeValues - left->count()) /
(1 + (insert_position < kNodeValues)); (1 + (insert_position < static_cast<int>(kNodeValues)));
to_move = (std::max)(1, to_move); to_move = (std::max)(1, to_move);
if (insert_position - to_move >= node->start() || if (insert_position - to_move >= node->start() ||
left->count() + to_move < kNodeValues) { left->count() + to_move < static_cast<int>(kNodeValues)) {
left->rebalance_right_to_left(to_move, node, mutable_allocator()); left->rebalance_right_to_left(to_move, node, mutable_allocator());
assert(node->max_count() - node->count() == to_move); assert(node->max_count() - node->count() == to_move);
@ -2306,12 +2306,12 @@ void btree<P>::rebalance_or_split(iterator *iter) {
// We bias rebalancing based on the position being inserted. If we're // We bias rebalancing based on the position being inserted. If we're
// inserting at the beginning of the left node then we bias rebalancing // inserting at the beginning of the left node then we bias rebalancing
// to fill up the right node. // to fill up the right node.
int to_move = (kNodeValues - right->count()) / int to_move = (static_cast<int>(kNodeValues) - right->count()) /
(1 + (insert_position > node->start())); (1 + (insert_position > node->start()));
to_move = (std::max)(1, to_move); to_move = (std::max)(1, to_move);
if (insert_position <= node->finish() - to_move || if (insert_position <= node->finish() - to_move ||
right->count() + to_move < kNodeValues) { right->count() + to_move < static_cast<int>(kNodeValues)) {
node->rebalance_left_to_right(to_move, right, mutable_allocator()); node->rebalance_left_to_right(to_move, right, mutable_allocator());
if (insert_position > node->finish()) { if (insert_position > node->finish()) {
@ -2374,7 +2374,7 @@ bool btree<P>::try_merge_or_rebalance(iterator *iter) {
// Try merging with our left sibling. // Try merging with our left sibling.
node_type *left = parent->child(iter->node->position() - 1); node_type *left = parent->child(iter->node->position() - 1);
assert(left->max_count() == kNodeValues); assert(left->max_count() == kNodeValues);
if (1 + left->count() + iter->node->count() <= kNodeValues) { if (1U + left->count() + iter->node->count() <= kNodeValues) {
iter->position += 1 + left->count(); iter->position += 1 + left->count();
merge_nodes(left, iter->node); merge_nodes(left, iter->node);
iter->node = left; iter->node = left;
@ -2385,7 +2385,7 @@ bool btree<P>::try_merge_or_rebalance(iterator *iter) {
// Try merging with our right sibling. // Try merging with our right sibling.
node_type *right = parent->child(iter->node->position() + 1); node_type *right = parent->child(iter->node->position() + 1);
assert(right->max_count() == kNodeValues); assert(right->max_count() == kNodeValues);
if (1 + iter->node->count() + right->count() <= kNodeValues) { if (1U + iter->node->count() + right->count() <= kNodeValues) {
merge_nodes(iter->node, right); merge_nodes(iter->node, right);
return true; return true;
} }

Loading…
Cancel
Save