[YANGTOOLS-1178] Add unique indices Created: 18/Nov/20 Updated: 16/Jan/24 |
|
| Status: | Confirmed |
| Project: | yangtools |
| Component/s: | data-impl |
| Affects Version/s: | None |
| Fix Version/s: | 14.0.0 |
| Type: | New Feature | Priority: | Medium |
| Reporter: | Robert Varga | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | pt | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Description |
|
As a follow-up to The problem of In order to alleviate this, we need to keep further state in TreeNode – value vector/child node relation – and drive validation during TreeNode mutations. In steady state (in-between mutations) there is a unique mapping between a TreeNode child and a vector of unique constraint values (i.e. an invariant):
BiMap<DataContainerNode, List<Object>> childToUnique;
for each individual 'unique' statement. Current implementation maintains this in a
HashMultimap.<UniqueValidator<?>, List<Object>>> validatorToUnique;
where a violation is triggered if a duplicate UniqueValidator/List<Object> mapping is being stored – effectively enforcing the invariant on steady state.
Current implementation is not plugged into TreeNode mutation process and therefore is O(N) where N is the number of list entries. This obviously sucks for small modifications on large lists. The objective of this issue is to integrate UniqueValidation with TreeNode mutation process, so that unique enforcement will be O(N), but where N is the number of modified list entries. To achieve that we need to plug into ListModificationStrategy/MapModificationStrategy and perform a guided mutation:
Note that the resulting BiMap will in reality be a BiMap for small lists – for large lists we need to decompose it to two TrieMaps, which co-evolve and maintain the mapping. This is because TrieMaps offer efficient amortized O(1) snapshot facility and partial modification. After we exit from ListModificationStrategy with a unique index, the resulting TreeNode needs to contain these indices so that the next mutation can pick up from there and manipulate just the delta. This will probably need a forwarding TreeNode implementation to hold the one/two maps. |