Feature Request: Support bulk operations for Trees (puts, merge, etc) #167

Closed
opened 2021-05-10 04:55:07 +00:00 by bramp · 1 comment
bramp commented 2021-05-10 04:55:07 +00:00 (Migrated from github.com)

Would it be possible to add bulk puts for Trees, or a Tree Merge operation? So it would be quicker to insert multiple keys.

For example

	// Instead of
	tree.Put(1, "x") // 1->x
	tree.Put(2, "b") // 1->x, 2->b

	// This
	tree.Put(1, "x", 2, "b"...) // 1->x, 2->b

or

	// Instead of
	treeA.Put(1, "x") // 1->x
	treeA.Put(2, "b") // 1->x, 2->b

	// This
	treeB.Merge(treeA)  // 1->x, 2->b

        // Or perhaps another syntax, where I can guarantee the input is sorted, so the tree can efficiently insert them.
Would it be possible to add bulk puts for Trees, or a Tree Merge operation? So it would be quicker to insert multiple keys. For example ```go // Instead of tree.Put(1, "x") // 1->x tree.Put(2, "b") // 1->x, 2->b // This tree.Put(1, "x", 2, "b"...) // 1->x, 2->b ``` or ```go // Instead of treeA.Put(1, "x") // 1->x treeA.Put(2, "b") // 1->x, 2->b // This treeB.Merge(treeA) // 1->x, 2->b // Or perhaps another syntax, where I can guarantee the input is sorted, so the tree can efficiently insert them. ```
emirpasic commented 2022-04-12 18:10:49 +00:00 (Migrated from github.com)

Where I could make the Put function variadic. One would still need to split those values into k1,v1,k2,v2... and by the time you do that, what is the point, and how much time has been saved?

Regarding merging values of one tree into another, I hope it is not much wrong with the code below?

for it := treeA.Iterator(); it.Next(); {
   treeB.put(it.Key(),it.Value())
}

Since both trees are sorted and elements are likely to be inserted at the given sorted node, there will be an internal optimization (unintentional really) occurring during insertion in the way the tree balances itself.

The bulk insertion optimizations are not as significant as the deeper research shows e.g. in Java, this is discussed in #105

Where I could make the Put function variadic. One would still need to split those values into `k1,v1,k2,v2...` and by the time you do that, what is the point, and how much time has been saved? Regarding merging values of one tree into another, I hope it is not much wrong with the code below? ```go for it := treeA.Iterator(); it.Next(); { treeB.put(it.Key(),it.Value()) } ``` Since both trees are sorted and elements are likely to be inserted at the given sorted node, there will be an internal optimization (unintentional really) occurring during insertion in the way the tree balances itself. The bulk insertion optimizations are not as significant as the deeper research shows e.g. in Java, this is discussed in #105
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
golibs/gms-gods#167
No description provided.