Feature: move internal node nesting model to doubly linked lists
See original GitHub issueToday, Lexical nodes are nested using arrays. This means that ElementNode
references an array of child node keys. However, we can improve performance by switching away from arrays, and to using doubly linked lists. This would mean
- We remove
ElementNode.__children
- We add
ElementNode.__first
, which is eitherNodeKey
ornull
. - We add
ElementNode.__last
, which is eitherNodeKey
ornull
. - We add
ElementNode.__size
, which isnumber
. Avoiding the need to do O(n) lookups to find the amount of children in the element. - We add
LexicalNode._prev
, which is eitherNodeKey
ornull
. - We add
LexicalNode._next
, which is eitherNodeKey
ornull
.
When we add/remove a node, we’ll need to make sure to update the linked list of both adjacent siblings (__prev
and __next
). Additionally, if the node is the first or last node of its parent, we’ll also have to update the parent __size
, __first
and/or __last
. We can remove the logic we have for marking siblings dirty, as we’ll do that organically from using linked lists.
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Introduction and Insertion in a Doubly Linked List
A Doubly Linked List (DLL) contains an extra pointer, typically called the previous pointer, together with the next pointer and data which are ......
Read more >Linked Lists I
Lists are doubly-linked, circular, and have a header node. Iterators are provided with two nested classes, named iterator and const_iterator, which satisfy ...
Read more >Trying to write a swap position function for a doubly linked list
Ideally I would like to have a generic function that can handle all edge cases (moving to the begin, end and swapping random...
Read more >Doubly Linked List In Java – Implementation & Code Examples
As each node needs to make space for the previous pointer, extra memory is required. · We need to deal with lots of...
Read more >Javanotes 9, Solution to Exercise 3, Chapter 10
To implement this, I use linked lists in which each node contains both a key and ... This private nested class is used...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think we probably want to introduce this to start with, in addition to the existing API. Have them both there, then switch, then remove the old in v0.3. So we’ll be duplicating work for a short-time, to ensure backwards compatibility.
It’s actually called “remove”
https://github.com/facebook/lexical/pull/2044/files#diff-eae9d8a8a05fee2910d2082d36f6f1683ba3632596e8d9cab326ef1fb0651065R660