New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mark structs as merged and filter out at the end of bulk operations #542
Conversation
* @param {Array<AbstractStruct>} structs | ||
* @param {number} mergedCount | ||
*/ | ||
const filterMergedStructs = (structs, mergedCount) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably better off constructing a new array using array.filter but im not sure if there will be references to the old array dangling so gotta do this ugly mutation
c3cde54
to
748c5f5
Compare
I'll admit, I don't fully understand what is going on in this PR, but would it be possible to do something like this:
Usage:
The idea being we track the data in another data structure as opposed to adding values on the struct as we process them? (Then do some operation at the end, which I believe is similar to your solution here - Fully aware that might sample code does not pass tests - just trying contribute to the iteration of the solution somehow) |
instead of splicing out of the array immediately
this avoids mutating the struct objects beyond the merge, no additional properties
Conceptually, while merging structs, a struct can become "wider" in the struct store, taking up multiple array indexes. The binary search accounts for this, and tries to return the left-most index of the wide struct. We scan the array at the end to shrink the wide structs into a single position in the array. |
@dmonad Can we bump the priority on this one please? |
Thanks @NilSet! I spent the week and thought more about this problem. This PR adds special behavior to how we interact with the data structure that stores the structs. In Yjs, we use a simple Array. In Yrs, we created a special data structure. Eventually, I want to do the same in Yjs. Hence, I feel we shouldn't add additional complexity specific to StructStore using Arrays & binary search. It should be possible to keep the data structure in a valid state without duplicates. A better data structure will eventually avoid splicing altogether. I distilled the idea to a simpler fix #553 (admittedly covering fewer cases). It also avoids iterating again through the structs to filter out the duplicates. This should fix #541 as well. |
instead of splicing out of the array immediately
Fixes #541