package org.freertr.tab; import java.util.Map; import java.util.TreeMap; import org.freertr.addr.addrPrefix; import org.freertr.addr.addrType; /** * one prefix tree * * @param type of elements in the list * @author matecsaba */ public class tabGepV1 { private TreeMap, tabRouteEntry> tree; /** * create one generic tree */ public tabGepV1() { tree = new TreeMap, tabRouteEntry>(); } /** * add one entry * * @param val value to add * @return old value, null if freshly added */ public tabRouteEntry add(tabRouteEntry val) { return tree.put(new tabGepV1nod(val), val); } /** * add one entry * * @param val value to add * @return removed value, null if not found */ public tabRouteEntry del(tabRouteEntry val) { return tree.remove(new tabGepV1nod(val)); } /** * find one container entry * * @param val value to look up * @return found value */ public tabRouteEntry search(tabRouteEntry val) { Map.Entry, tabRouteEntry> res = tree.floorEntry(new tabGepV1nod(val)); for (;;) { if (res == null) { return null; } tabRouteEntry v = res.getValue(); if (v.prefix.supernet(val.prefix, true)) { return v; } res = tree.lowerEntry(res.getKey()); } } } class tabGepV1nod implements Comparable> { public addrPrefix pfx; public tabGepV1nod(tabRouteEntry val) { pfx = val.prefix; } public int compareTo(tabGepV1nod o) { return pfx.compareTo(o.pfx); } }