Skip to content

Commit

Permalink
Merge pull request #2 from devilelephant/master
Browse files Browse the repository at this point in the history
Fix Issue #1: Inserting IPs creates a match for that IP and one IP earlier
  • Loading branch information
x25 authored Feb 9, 2024
2 parents 410f3e9 + 3db412e commit d3ba815
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/com/github/x25/net/tree/IpSubnetTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void insert(String cidrNotation, V value) {
int pos = cidrNotation.indexOf('/');

if (pos == -1) {
insert(cidrNotation + "/255", value);
insert(cidrNotation + "/32", value);
return;
}

Expand Down
10 changes: 10 additions & 0 deletions src/test/java/com/github/x25/IpSubnetTreeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ public void testBasic() {
assertEquals("X", tree.find("128.0.0.1"));
}

public void testNoCidr() {
IpSubnetTree<String> tree = new IpSubnetTree<String>();
tree.setDefaultValue("X");
tree.insert("129.0.0.7", "F");

assertEquals("X", tree.find("129.0.0.6"));
assertEquals("F", tree.find("129.0.0.7"));
assertEquals("X", tree.find("129.0.0.6"));
}

public void testCidr() {
IpSubnetTree<Integer> tree = new IpSubnetTree<Integer>();
for (int i = 0; i < 255; i++) {
Expand Down

0 comments on commit d3ba815

Please sign in to comment.