Address review comment

This commit is contained in:
Andrew Noyes 2021-03-09 01:40:59 +00:00
parent 5ecb1dfcba
commit 8766bb44b1

View File

@ -386,7 +386,11 @@ public:
// have changed (they won't if k already exists in the tree but was deleted). // have changed (they won't if k already exists in the tree but was deleted).
// Returns true if successful, false if k does not fit in the space available // Returns true if successful, false if k does not fit in the space available
// or if k is already in the tree (and was not already deleted). // or if k is already in the tree (and was not already deleted).
// Insertion on an empty tree returns false as well.
bool insert(const T& k, int skipLen = 0, int maxHeightAllowed = std::numeric_limits<int>::max()) { bool insert(const T& k, int skipLen = 0, int maxHeightAllowed = std::numeric_limits<int>::max()) {
if (root == nullptr) {
return false;
}
int height = 1; int height = 1;
DecodedNode* n = root; DecodedNode* n = root;
bool addLeftChild = false; bool addLeftChild = false;
@ -432,7 +436,6 @@ public:
return false; return false;
} }
ASSERT(n != nullptr);
// Insert k as the left or right child of n, depending on the value of addLeftChild // Insert k as the left or right child of n, depending on the value of addLeftChild
// First, see if it will fit. // First, see if it will fit.
const T* prev = addLeftChild ? n->prev : &n->item; const T* prev = addLeftChild ? n->prev : &n->item;