-
Notifications
You must be signed in to change notification settings - Fork 88
Snapshot/signal value format registry #701
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
Merged
mkorbel1
merged 3 commits into
intel:main
from
desmonddak:snapshot/signal-value-format-registry
Sep 1, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| // Copyright (C) 2026 Intel Corporation | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| // | ||
| // occurrence_trie.dart | ||
| // Compact storage for values keyed by hierarchy occurrence addresses. | ||
| // | ||
| // 2026 August | ||
| // Author: Desmond Kirkpatrick <desmond.a.kirkpatrick@intel.com> | ||
|
|
||
| import 'package:rohd_hierarchy/src/occurrence_address.dart'; | ||
|
|
||
| /// A prefix-sharing map from [OccurrenceAddress] values to values of type [T]. | ||
| /// | ||
| /// Common address prefixes are stored once, making this more compact than a | ||
| /// conventional map when many values belong to the same hierarchy subtree. | ||
| class OccurrenceTrie<T extends Object> { | ||
| /// The root node, which represents [OccurrenceAddress.root]. | ||
| final _OccurrenceTrieNode<T> _root = _OccurrenceTrieNode<T>(); | ||
|
|
||
| /// Whether this trie contains no values. | ||
| bool get isEmpty => _root.isEmpty; | ||
|
|
||
| /// The value stored at [address], if any. | ||
| T? operator [](OccurrenceAddress address) { | ||
| var node = _root; | ||
| for (final index in _validatedPath(address)) { | ||
| final child = node.children[index]; | ||
| if (child == null) { | ||
| return null; | ||
| } | ||
| node = child; | ||
| } | ||
| return node.value; | ||
| } | ||
|
|
||
| /// Associates [value] with [address]. | ||
| void operator []=(OccurrenceAddress address, T value) { | ||
| var node = _root; | ||
| for (final index in _validatedPath(address)) { | ||
| node = node.children.putIfAbsent(index, _OccurrenceTrieNode<T>.new); | ||
| } | ||
| node.value = value; | ||
| } | ||
|
|
||
| /// Removes and returns the value stored at [address], if any. | ||
| T? remove(OccurrenceAddress address) { | ||
| final path = _validatedPath(address); | ||
| final nodes = <_OccurrenceTrieNode<T>>[_root]; | ||
| var node = _root; | ||
| for (final index in path) { | ||
| final child = node.children[index]; | ||
| if (child == null) { | ||
| return null; | ||
| } | ||
| nodes.add(child); | ||
| node = child; | ||
| } | ||
|
|
||
| final previous = node.value; | ||
| if (previous == null) { | ||
| return null; | ||
| } | ||
| node.value = null; | ||
| for (var index = path.length - 1; index >= 0; index--) { | ||
| final child = nodes[index + 1]; | ||
| if (!child.isEmpty) { | ||
| break; | ||
| } | ||
| nodes[index].children.remove(path[index]); | ||
| } | ||
| return previous; | ||
| } | ||
|
|
||
| /// Removes every value from this trie. | ||
| void clear() { | ||
| _root | ||
| ..value = null | ||
| ..children.clear(); | ||
| } | ||
|
|
||
| /// Returns [address]'s valid, non-negative path. | ||
| static List<int> _validatedPath(OccurrenceAddress address) { | ||
| if (address.path.any((index) => index < 0)) { | ||
| throw ArgumentError.value( | ||
| address, | ||
| 'address', | ||
| 'An occurrence address must contain non-negative indices.', | ||
| ); | ||
| } | ||
| return address.path; | ||
| } | ||
| } | ||
|
|
||
| /// A node in an [OccurrenceTrie]. | ||
| class _OccurrenceTrieNode<T extends Object> { | ||
| /// Descendants indexed by their address path component. | ||
| final Map<int, _OccurrenceTrieNode<T>> children = {}; | ||
|
|
||
| /// The value stored at this node, if one has been assigned. | ||
| T? value; | ||
|
|
||
| /// Whether this node has neither a value nor descendants. | ||
| bool get isEmpty => value == null && children.isEmpty; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // Copyright (C) 2026 Intel Corporation | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| // | ||
| // occurrence_trie_test.dart | ||
| // Tests for compact occurrence-address trie storage. | ||
| // | ||
| // 2026 August | ||
| // Author: Desmond Kirkpatrick <desmond.a.kirkpatrick@intel.com> | ||
|
|
||
| import 'package:rohd_hierarchy/rohd_hierarchy.dart'; | ||
| import 'package:test/test.dart'; | ||
|
|
||
| void main() { | ||
| test('stores values with shared occurrence-address prefixes', () { | ||
| final trie = OccurrenceTrie<String>(); | ||
| const first = OccurrenceAddress([0, 2, 4]); | ||
| const second = OccurrenceAddress([0, 2, 5]); | ||
|
|
||
| trie[first] = 'first'; | ||
| trie[OccurrenceAddress.root] = 'root'; | ||
| trie[second] = 'second'; | ||
|
|
||
| expect(trie[OccurrenceAddress.root], 'root'); | ||
| expect(trie[first], 'first'); | ||
| expect(trie[second], 'second'); | ||
| expect(trie[const OccurrenceAddress([0, 2, 6])], isNull); | ||
| }); | ||
|
|
||
| test('prunes an address branch after removing its final value', () { | ||
| final trie = OccurrenceTrie<String>(); | ||
| const first = OccurrenceAddress([0, 2, 4]); | ||
| const second = OccurrenceAddress([0, 2, 5]); | ||
| trie[first] = 'first'; | ||
| trie[second] = 'second'; | ||
|
|
||
| expect(trie.remove(first), 'first'); | ||
| expect(trie[first], isNull); | ||
| expect(trie[second], 'second'); | ||
| expect(trie.remove(second), 'second'); | ||
| expect(trie.isEmpty, isTrue); | ||
| }); | ||
|
|
||
| test('accepts root addresses and rejects negative path indices', () { | ||
| final trie = OccurrenceTrie<String>(); | ||
|
|
||
| trie[OccurrenceAddress.root] = 'root'; | ||
| expect(trie[OccurrenceAddress.root], 'root'); | ||
| expect( | ||
| () => trie[const OccurrenceAddress([0, -1])], | ||
| throwsArgumentError, | ||
| ); | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.