Open clbarnes opened 3 months ago
Hello @clbarnes,
There are currently no plans to implement encoding for this crate. We’re open for contributions if you (or anyone else reading this) want(s) to implement TCString encoding for this crate.
I agree with you that bitfield lists should be sorted, but I (personally) would prefer a solution which is optional either via an option or crate feature. With the current implementation it is not possible to pass options, be it a callback function that can be used to sort the bitfield lists or an option to signal the implementation, it should sort these lists. So it would require a rewrite of the user-facing API as well.
The sorting was a bit of an aside - switching out the vec of vendor IDs for a btreeset would coincidentally guarantee order while primarily making containment checks more efficient (order being a useful tiebreaker vs a hashset). Containment checks are the entire purpose of vendor list so it seems like a use case worth prioritising. And serde serialises them exactly the same way so no changes needed there!
I only mentioned sorting as well because in a read-only workflow as currently supported, a sorted vec is probably about as good as a btreeset because you can binary search it.
The overhead for using the BTreeSet
is probably also beneficial for the allowed_vendors
and disclosed_vendors
not just the vendors_consent
and vendors_li_consent
.
I will have to do some testing whether this overhead is worth placing behind an option / feature or if it should be the new default behavior.
The overhead for using BTreeSet
is roughly 39%.
So this would need to be placed behind an opt-in feature. The code used in the latter benchmark can be found here: https://github.com/advancedSTORE/lib_tcstring/commit/09a54c9dbeacfa4e228a2b97ce8aaab09b4b4e52
The vendor consent vecs will almost always be used for membership checks. If encoding is ever added to this crate, guaranteeing ascending order and non-repeats through modification makes that much easier. You'd hope that people would encode their TC strings as sorted (always true for a bitfield, but possibly not true for ranges), but they might not, so it would be good to guarantee it.
Using a BTreeSet instead of a Vec guarantees ascending order and uniqueness, even if people modify it for re-encoding later. Otherwise, a sorted vec is an improvement as it allows binary searches. An
&mut self
method to sort all the internal vendor lists would be minimally invasive.