Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mc36
committed
Dec 29, 2021
1 parent
30e265f
commit 6f585a9
Showing
8 changed files
with
245 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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 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 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,20 @@ | ||
package net.freertr.tab; | ||
|
||
import net.freertr.addr.addrType; | ||
|
||
/** | ||
* one prefix tree | ||
* | ||
* @param <T> type of elements in the list | ||
* @author matecsaba | ||
*/ | ||
public class tabGep<T extends addrType> extends tabGepV2<T> { | ||
|
||
/** | ||
* create one generic tree | ||
*/ | ||
public tabGep() { | ||
super(); | ||
} | ||
|
||
} |
This file contains 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,79 @@ | ||
package net.freertr.tab; | ||
|
||
import java.util.Map; | ||
import java.util.TreeMap; | ||
import net.freertr.addr.addrPrefix; | ||
import net.freertr.addr.addrType; | ||
|
||
/** | ||
* one prefix tree | ||
* | ||
* @param <T> type of elements in the list | ||
* @author matecsaba | ||
*/ | ||
public class tabGepV1<T extends addrType> { | ||
|
||
private TreeMap<tabGepV1nod<T>, tabRouteEntry<T>> tree; | ||
|
||
/** | ||
* create one generic tree | ||
*/ | ||
public tabGepV1() { | ||
tree = new TreeMap<tabGepV1nod<T>, tabRouteEntry<T>>(); | ||
} | ||
|
||
/** | ||
* add one entry | ||
* | ||
* @param val value to add | ||
* @return old value, null if freshly added | ||
*/ | ||
public tabRouteEntry<T> add(tabRouteEntry<T> val) { | ||
return tree.put(new tabGepV1nod<T>(val), val); | ||
} | ||
|
||
/** | ||
* add one entry | ||
* | ||
* @param val value to add | ||
* @return removed value, null if not found | ||
*/ | ||
public tabRouteEntry<T> del(tabRouteEntry<T> val) { | ||
return tree.remove(new tabGepV1nod<T>(val)); | ||
} | ||
|
||
/** | ||
* find one container entry | ||
* | ||
* @param val value to look up | ||
* @return found value | ||
*/ | ||
public tabRouteEntry<T> search(tabRouteEntry<T> val) { | ||
Map.Entry<tabGepV1nod<T>, tabRouteEntry<T>> res = tree.floorEntry(new tabGepV1nod<T>(val)); | ||
for (;;) { | ||
if (res == null) { | ||
return null; | ||
} | ||
tabRouteEntry<T> v = res.getValue(); | ||
if (v.prefix.supernet(val.prefix, true)) { | ||
return v; | ||
} | ||
res = tree.lowerEntry(res.getKey()); | ||
} | ||
} | ||
|
||
} | ||
|
||
class tabGepV1nod<T extends addrType> implements Comparable<tabGepV1nod<T>> { | ||
|
||
public addrPrefix<T> pfx; | ||
|
||
public tabGepV1nod(tabRouteEntry<T> val) { | ||
pfx = val.prefix; | ||
} | ||
|
||
public int compareTo(tabGepV1nod<T> o) { | ||
return pfx.compare(pfx, o.pfx); | ||
} | ||
|
||
} |
This file contains 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,124 @@ | ||
package net.freertr.tab; | ||
|
||
import net.freertr.addr.addrType; | ||
|
||
/** | ||
* one prefix tree | ||
* | ||
* @param <T> type of elements in the list | ||
* @author matecsaba | ||
*/ | ||
public class tabGepV2<T extends addrType> { | ||
|
||
private tabGepV2nod<T> rot; | ||
|
||
/** | ||
* create one generic tree | ||
*/ | ||
public tabGepV2() { | ||
rot = new tabGepV2nod<T>(); | ||
} | ||
|
||
/** | ||
* add one entry | ||
* | ||
* @param val value to add | ||
* @return old value, null if freshly added | ||
*/ | ||
public tabRouteEntry<T> add(tabRouteEntry<T> val) { | ||
tabGepV2nod<T> cur = rot; | ||
for (int p = 0;; p++) { | ||
if (p >= val.prefix.maskLen) { | ||
tabRouteEntry<T> old = cur.val; | ||
cur.val = val; | ||
return old; | ||
} | ||
if (val.prefix.network.bitValue(p)) { | ||
if (cur.one == null) { | ||
cur.one = new tabGepV2nod<T>(); | ||
} | ||
cur = cur.one; | ||
} else { | ||
if (cur.zero == null) { | ||
cur.zero = new tabGepV2nod<T>(); | ||
} | ||
cur = cur.zero; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* add one entry | ||
* | ||
* @param val value to add | ||
* @return removed value, null if not found | ||
*/ | ||
public tabRouteEntry<T> del(tabRouteEntry<T> val) { | ||
tabGepV2nod<T> cur = rot; | ||
for (int p = 0;; p++) { | ||
if (p >= val.prefix.maskLen) { | ||
tabRouteEntry<T> old = cur.val; | ||
cur.val = null; | ||
return old; | ||
} | ||
if (val.prefix.network.bitValue(p)) { | ||
if (cur.one == null) { | ||
return null; | ||
} | ||
cur = cur.one; | ||
} else { | ||
if (cur.zero == null) { | ||
return null; | ||
} | ||
cur = cur.zero; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* find one container entry | ||
* | ||
* @param val value to look up | ||
* @return found value | ||
*/ | ||
public tabRouteEntry<T> search(tabRouteEntry<T> val) { | ||
tabGepV2nod<T> cur = rot; | ||
tabRouteEntry<T> lst = null; | ||
for (int p = 0;; p++) { | ||
if (cur.val != null) { | ||
lst = cur.val; | ||
} | ||
if (p >= val.prefix.maskLen) { | ||
return lst; | ||
} | ||
if (val.prefix.network.bitValue(p)) { | ||
if (cur.one == null) { | ||
return lst; | ||
} | ||
cur = cur.one; | ||
} else { | ||
if (cur.zero == null) { | ||
return lst; | ||
} | ||
cur = cur.zero; | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
class tabGepV2nod<T extends addrType> { | ||
|
||
public tabGepV2nod<T> zero; | ||
|
||
public tabGepV2nod<T> one; | ||
|
||
public tabRouteEntry<T> val; | ||
|
||
public tabGepV2nod() { | ||
val = null; | ||
zero = null; | ||
one = null; | ||
} | ||
|
||
} |
This file contains 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 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 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