Skip to content

Commit

Permalink
floatingimages overlap problem
Browse files Browse the repository at this point in the history
  • Loading branch information
dragoncoder047 committed May 31, 2024
1 parent 41ea855 commit 6075c82
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/2024/a-hash-mapped-mess/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions markdown/pickle_slow_progress.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,27 @@ Obviously, hashmaps for object properties aren't static -- they will have proper

The algorithms outlined for adding or deleting a property end up causing problems. Deleting a property just clears the node, it doesn't delete the node, and so the property-addition algorithm can check for and re-use cleared nodes instead of creating new children. This means that a simple add-or-update implementation might end up accidentally inserting the value twice, because it found a cleared node higher-up in the tree than the existing node's position and stopped too soon.

<div markdown="block">
```{.mermaid .float-right}
graph TD
foo --> bar
foo --> baz
```

Consider what happens if you have, say, three nodes called `foo`, `bar`, and `baz`. First `foo` is inserted to an empty tree, so it becomes the root node, Then `bar` and `baz` are added, and become children of `foo`.
</div>

<div markdown="block">
```{.mermaid .float-right}
graph TD
foo[ ] --> bar
foo --> baz
```

Now `foo` is deleted. The first node matching it is cleared - no problem. There are no `foo`s in the tree.
</div>

<div markdown="block">
```{.mermaid .float-right}
graph TD
foo["bar (new)"] --> bar["bar (old)"]
Expand All @@ -40,14 +45,17 @@ graph TD
`bar` is updated. Since there is a free node above the old `bar`, there ends up two `bar` nodes.

Up until now, there isn't any problem. Finding any node, even in the tree with the duplicated `bar`, finds the correct value.
</div>

<div markdown="block">
```{.mermaid .float-right}
graph TD
foo[ ] --> bar["bar (old)"]
foo --> baz
```

The problem arises when you try to delete `bar` on this duplicated tree -- and since the old `bar` node wasn't ever deleted, this "shadow" node now rears it ugly head and causes the key `bar` to revert to its old value, instead of being deleted like it was supposed to be.
</div>

I spent a long time trying to figure out how to combat this problem. The easiest solution, which I implemented, is to traverse the entire hash's search path, not just stopping at the first free node, when updating a value. If the new value is set by filling a free node (rather than simply updating the existing node with the same key), there may be shadow nodes under it, so the rest of the tree has to be traversed, and these shadow nodes cleared. This guarantees there will only be one node for any given key in use at the same time.

Expand Down

0 comments on commit 6075c82

Please sign in to comment.