Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ public void modificationPatternTreeMapTest() throws IllegalPathException {
patternTreeMap.append(
new PartialPath("root.sg1.d1.*.d3.s4"),
new Deletion(new PartialPath("root.sg1.d1.*.d3.s4"), 3, 4, 6));
patternTreeMap.append(
new PartialPath("root.sg1.d1.t1.d*.s5"),
new Deletion(new PartialPath("root.sg1.d1.t1.d*.s5"), 4, 7, 10));

checkOverlappedByDevice(
patternTreeMap,
Expand All @@ -205,7 +208,8 @@ public void modificationPatternTreeMapTest() throws IllegalPathException {
new Deletion(new PartialPath("root.**.s1"), 10, 100, 200),
new Deletion(new PartialPath("root.**"), 5, 10, 100),
new Deletion(new PartialPath("root.sg1.d1.*.d3.s5"), 2, 4, 6),
new Deletion(new PartialPath("root.sg1.d1.*.d3.s4"), 3, 4, 6)));
new Deletion(new PartialPath("root.sg1.d1.*.d3.s4"), 3, 4, 6),
new Deletion(new PartialPath("root.sg1.d1.t1.d*.s5"), 4, 7, 10)));
}

private <T> void checkOverlapped(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public class PathPatternNode<V, VSerializer extends PathPatternNode.Serializer<V

private final VSerializer serializer;

// Children names with wildcard, for accelerating wildcard searching.
// Here we do not include "*" or "**" to ensure that the set is empty in most cases.
private final Set<String> childrenNamesWithNonTrivialWildcard = new HashSet<>();

public PathPatternNode(String name, VSerializer serializer) {
this.name = name;
this.children = new HashMap<>();
Expand Down Expand Up @@ -90,6 +94,10 @@ public List<PathPatternNode<V, VSerializer>> getMatchChildren(String nodeName) {
if (children.containsKey(MULTI_LEVEL_PATH_WILDCARD)) {
res.add(children.get(MULTI_LEVEL_PATH_WILDCARD));
}
childrenNamesWithNonTrivialWildcard.stream()
.filter(path -> PathPatternUtil.isNodeMatch(path, nodeName))
.map(children::get)
.forEach(res::add);
return res;
}

Expand All @@ -98,7 +106,13 @@ public Map<String, PathPatternNode<V, VSerializer>> getChildren() {
}

public void addChild(PathPatternNode<V, VSerializer> tmpNode) {
children.put(tmpNode.getName(), tmpNode);
String nodeName = tmpNode.getName();
if (PathPatternUtil.hasWildcard(nodeName)
&& !PathPatternUtil.isMultiLevelMatchWildcard(nodeName)
&& !ONE_LEVEL_PATH_WILDCARD.equals(nodeName)) {
childrenNamesWithNonTrivialWildcard.add(nodeName);
}
children.put(nodeName, tmpNode);
}

public void deleteChild(PathPatternNode<V, VSerializer> tmpNode) {
Expand Down Expand Up @@ -265,6 +279,7 @@ public long ramBytesUsed() {
return SHALLOW_SIZE
+ RamUsageEstimator.sizeOf(name)
+ RamUsageEstimator.sizeOfHashSet(valueSet)
+ RamUsageEstimator.sizeOfHashSet(childrenNamesWithNonTrivialWildcard)
+ RamUsageEstimator.sizeOfMapWithKnownShallowSize(
children,
RamUsageEstimator.SHALLOW_SIZE_OF_HASHMAP,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ private PathPatternUtil() {}
* patternNode that can match batch explicit node names. e.g. *, e.g. *, **, d*, *d*.
*/
public static boolean hasWildcard(String node) {
return node.startsWith(ONE_LEVEL_PATH_WILDCARD) || node.endsWith(ONE_LEVEL_PATH_WILDCARD);
return node != null
&& (node.startsWith(ONE_LEVEL_PATH_WILDCARD) || node.endsWith(ONE_LEVEL_PATH_WILDCARD));
}

public static boolean isMultiLevelMatchWildcard(String node) {
Expand Down
Loading