mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-10 12:03:16 +02:00
Bug 402177: Btree.insert returns wrong value
The javadoc for BTree.insert says "don't insert if the key was already there, in which case we return the record that matched". However, the implementation was returning the new record even when it was not actually inserted. This is a fix for the problem and a test case to demonstrate the issue. Further Changes: ---------------- I have modified the code style as described in the comments in https://git.eclipse.org/r/#/c/10804. However, I'm still not sure what style is expected. I've looked through the CDT wiki a few times, especially the 'new developer' parts, but haven't found anything relevant. When I asked the question a few weeks ago, the only reply was to use the "eclipse built-in style", which I can't find in my preferences. The default seems to be "K&R Style" (that is what it is set to now, and I don't think that I would have changed it), so that is what I've used here. If I've missed the section in the wiki then a pointer would be greatly appreciated. Otherwise this topic would be a great topic for someone that knows the answers to add to the wiki. Change-Id: If079f235871fcdfbd35f1cba3f64cc3e33edaaec Reviewed-on: https://git.eclipse.org/r/10804 Reviewed-by: Doug Schaefer <dschaefer@qnx.com> IP-Clean: Doug Schaefer <dschaefer@qnx.com> Tested-by: Doug Schaefer <dschaefer@qnx.com>
This commit is contained in:
parent
88411d63e5
commit
8883fb1af5
2 changed files with 31 additions and 13 deletions
|
@ -102,6 +102,24 @@ public class BTreeTests extends BaseTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bug 402177: BTree.insert should return the matching record if the new record was not inserted.
|
||||||
|
*/
|
||||||
|
public void testEquivalentRecordInsert_Bug402177() throws Exception {
|
||||||
|
|
||||||
|
init(8);
|
||||||
|
try {
|
||||||
|
BTMockRecord value1 = new BTMockRecord(db, 42);
|
||||||
|
BTMockRecord value2 = new BTMockRecord(db, 42);
|
||||||
|
|
||||||
|
long insert1 = btree.insert(value1.getRecord());
|
||||||
|
long insert2 = btree.insert(value2.getRecord());
|
||||||
|
assertEquals(insert1, insert2);
|
||||||
|
} finally {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert/Delete a random number of records into/from the B-tree
|
* Insert/Delete a random number of records into/from the B-tree
|
||||||
* @param seed the seed for obtaining the deterministic random testing
|
* @param seed the seed for obtaining the deterministic random testing
|
||||||
|
|
|
@ -176,8 +176,8 @@ public class BTree {
|
||||||
} else if (compare < 0) {
|
} else if (compare < 0) {
|
||||||
lower= middle + 1;
|
lower= middle + 1;
|
||||||
} else {
|
} else {
|
||||||
// Found it, no insert, just return the record.
|
// Found it, no insert, just return the matched record.
|
||||||
return record;
|
return checkRec;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue