Call getRandomCall() { CallType callType = getRandomCallType(); switch(callType) { case CallType::PASS: return Call::PASS(); case CallType::DOUBLE: return Call::DOUBLE(); case CallType::REDOUBLE: return Call::REDOUBLE(); case CallType::BID: return Call::BID(getRandomLevel(), getRandomDenomination()); } }
std::pair<Iterator, bool> insert(ValueType &pair) { int top_level = getRandomLevel(); std::stack<Node*> update_node_stack; Node* current_node; Node* fallback_node = levels; bool exists = false; for(int i = (MaxLevel - 1); i >= 0; i--) { current_node = fallback_node; while(current_node != NULL) { fallback_node = current_node; if(current_node->nodes[i] == NULL) { if(top_level > i) update_node_stack.push(current_node); break; // Next string on this node } else if (current_node->nodes[i]->dataPair.first == pair.first) { current_node->nodes[i]->dataPair.second = pair.second; exists = true; goto just_an_update; // Seems like the best way to get out } else if(current_node->nodes[i]->dataPair.first > pair.first) { if(top_level > i) update_node_stack.push(current_node); break; // Next string on this node } else if(current_node->nodes[i]->dataPair.first < pair.first) { current_node = current_node->nodes[i]; } } } just_an_update: if(!exists) { Node *new_node = new Node(pair, top_level); if(fallback_node == NULL) // This is the first element -- Special Case { for(int k = 0; k < top_level; k++) levels->nodes[k] = new_node; } else { // ASSERT: Current Node points to a node who precedes our node to // insert on at least string 0. int j = 0; Node *temp; while(update_node_stack.size() > 0) { // pop each node to be updated out [ 0 -> topLevel ] temp = update_node_stack.top()->nodes[j]; update_node_stack.top()->nodes[j] = new_node; new_node->nodes[j] = temp; update_node_stack.pop(); ++j; } } ++sz; return std::pair<Iterator, bool>(Iterator(new_node), exists); } else { return std::pair<Iterator, bool>(Iterator(fallback_node), exists); } }