csharptest / CSharpTest.Net.Collections

BPlusTree and other collections moved from http://code.google.com/p/csharptest-net
107 stars 48 forks source link

Value update options for BulkInsert and AddRange #9

Open VJalili opened 9 years ago

VJalili commented 9 years ago

First of all, I would like to thank you (again) for sharing such an excellent work with us.

I usually use AddOrUpdate method to add a new item to the bplustree. The possibility of passing a struct of AddUpdateValue that implements ICreateOrUpdateValue<C, B>, IRemoveValue<C, B> is a perfect option that extends and facilitates value update procedure. However, I wonder why such a magnificent feature is avoided in BulkInsert and AddRange.

Depending on application, value update by replacing old value with new one might be preferred, however, some applications could have custom update procedures. Some applications may require updating the value of a given key with new value where the new value it self depends on old one. For instance, lets suppose value is the average of all observed measures for a key; you observe new measure, now you would like to update the value, not replace it. AddOrUpdate perfectly addresses this requirement, but BulkInsert and AddRange are very limited in this regard.

I would like to know if you have any plans for incorporating AddUpdateValue feature in these super fast :) insertions ?

csharptest commented 9 years ago

@VJalili, You are correct AddRange could easily adopt this behavior and gain a bit of performance with it. I'll leave this open for when I get some time to add the overload.

For BulkInsert I think you would be better off merging the sets before insertion and performing whatever add/update logic at that time. If you look at the implementation of the BulkInsert operation you should be able to see how this is done.