In the current solution to Exercise 3.26 the insert function does nothing when a matching key is found in the table.
The issue raised with the solution to this Exercise included the logic for this. #805
But in the commit 245bdc0 some changes were made, and it was not added.
From my understanding. In the original issue with the solution, when a matching key is found, the mutation of the value caused the structure of the tree to change.
...
put(3, "d");
put(1, "a");
put(2, "b");
Calling get(2) returns: [2, ["b", null]]
put(2, "c");
Now calling get(2) returns: [2, "c"]
And changing the get function to only return the value, caused errors.
To add the functionality of mutating a value, to the current solution, we need to change: (245bdc0#diff-2fcf2160827ca147db35db6ff4fb66b54efe0be937c726b2b87cedd80d4f1dc1R875)
from:
...
function insert(k, v) {
let record = lookup(k, local_table);
if (is_null(record)) {
local_table = adjoin_set(list(k, v), local_table);
} else {
// do nothing
}
}
...
to:
...
function insert(k, v) {
let record = lookup(k, local_table);
if (is_null(record)) {
local_table = adjoin_set(list(k, v), local_table);
} else {
set_tail(record, list(v));
}
}
...
And the comment can be removed :
(245bdc0#diff-2fcf2160827ca147db35db6ff4fb66b54efe0be937c726b2b87cedd80d4f1dc1R921 )
...
display(get(2)); // displays: "b"
...
to:
In the current solution to Exercise 3.26 the insert function does nothing when a matching key is found in the table.
The issue raised with the solution to this Exercise included the logic for this. #805
But in the commit 245bdc0 some changes were made, and it was not added.
From my understanding. In the original issue with the solution, when a matching key is found, the mutation of the value caused the structure of the tree to change.
Calling get(2) returns:
[2, ["b", null]]put(2, "c");Now calling get(2) returns:
[2, "c"]And changing the get function to only return the value, caused errors.
To add the functionality of mutating a value, to the current solution, we need to change: (245bdc0#diff-2fcf2160827ca147db35db6ff4fb66b54efe0be937c726b2b87cedd80d4f1dc1R875)
from:
to:
And the comment can be removed :
(245bdc0#diff-2fcf2160827ca147db35db6ff4fb66b54efe0be937c726b2b87cedd80d4f1dc1R921 )
to: