prevent undo delete from re-inserting duplicate ids
This commit is contained in:
parent
ee9b2e6302
commit
c410c92343
@ -47,6 +47,14 @@ void UndoManager<T>::undoDelete() {
|
|||||||
if (!undoStack->isEmpty()) {
|
if (!undoStack->isEmpty()) {
|
||||||
T lastDeleted = undoStack->pop();
|
T lastDeleted = undoStack->pop();
|
||||||
|
|
||||||
|
// Check if the CPU is already in the HashTable
|
||||||
|
T foundCPU;
|
||||||
|
foundCPU.setCpuId(lastDeleted.getCpuId());
|
||||||
|
if (hashTable->search(foundCPU, foundCPU, key_to_index) != -1) {
|
||||||
|
std::cout << "Undo failed: CPU \"" << lastDeleted.getCpuId() << "\" already exists in the HashTable." << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Reinsert the CPU into the HashTable and BST
|
// Reinsert the CPU into the HashTable and BST
|
||||||
hashTable->insert(lastDeleted, key_to_index);
|
hashTable->insert(lastDeleted, key_to_index);
|
||||||
bst->insert(lastDeleted.getCpuId());
|
bst->insert(lastDeleted.getCpuId());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user