protected MapEntry<K, V> findEntry(K key) { int hash = key.hashCode(); return findEntry(key, entries.bucket(hash)); }
public void put(String key, T value) { assert key.length() >= 1; MapEntry<byte[], T> route = new MapEntry<>(key.getBytes(), value); long hash = hash(key); entries.put(hash, route); }
public AbstractMapImpl(int capacity, int bucketSize) { this(new SimpleHashTable<>(capacity, bucketSize)); }
public SimpleBucket<T> bucket(long key) { int index = index(key); return getBucketAt(index); }
protected MapEntry<K, V> findEntry(K key) { SimpleList<MapEntry<K, V>> bucket = entries.get(key.hashCode()); return findEntry(key, bucket); }
public void clear() { for (int i = 0; i < buckets.length; i++) { clearBucket(i); } }
@Override public void clear() { entries.clear(); }
public void put(long key, T value) { get(key).add(value); }
public void clear() { for (int i = 0; i < buckets.length; i++) { clearBucket(i); } }
@Override public void clear() { entries.clear(); }
public void put(long key, T value) { bucket(key).add(value); }
private synchronized void addRoute(String action, String path, Handler handler) { assert action.length() >= 1; assert path.length() >= 1; Route route = new Route(); route.handler = handler; route.action = action.getBytes(); route.path = path.getBytes(); long hash = hash(action, path); routes.put(hash, route); }
public Handler findHandler(Buf buf, Range action, Range path) { long hash = hash(buf.bytes(), action, path); SimpleList<Route> candidates = routes.get(hash); if (candidates != null) { for (int i = 0; i < candidates.size(); i++) { Route route = candidates.get(i); if (BytesUtil.matches(buf.bytes(), action, route.action, true) && BytesUtil.startsWith(buf.bytes(), path, route.path, true)) { int pos = path.start + route.path.length; if (path.limit() == pos || buf.get(pos) == '/') { return route.handler; } } } } return null; }
public AbstractMapImpl(int width) { this.entries = new SimpleHashTable<MapEntry<K, V>>(width); }
@Override public boolean remove(String key) { assert key.length() >= 1; long hash = hash(key); SimpleBucket<MapEntry<byte[], T>> bucket = this.entries.bucket(hash); if (bucket == null) { return false; } for (int i = 0; i < bucket.size(); i++) { MapEntry<byte[], T> route = bucket.get(i); if (new String(route.key).equals(key)) { bucket.delete(i); return true; } } return false; }
public void put(String key, T value) { assert key.length() >= 1; MapEntry<byte[], T> route = new MapEntry<>(key.getBytes(), value); long hash = hash(key); entries.put(hash, route); }
private Handler findHandler(HttpExchangeImpl x) { Buf buf = x.input(); Range action = x.verb_().range(); Range path = x.path_().range(); // serveStaticFileIfExists(x, buf, path); long hash = hash(buf.bytes(), action, path); synchronized (this) { SimpleList<Route> candidates = routes.get(hash); candidates = routes.get(hash); if (candidates != null) { for (int i = 0; i < candidates.size(); i++) { Route route = candidates.get(i); if (BytesUtil.matches(buf.bytes(), action, route.action, true) && BytesUtil.startsWith(buf.bytes(), path, route.path, true)) { int pos = path.start + route.path.length; if (path.limit() == pos || buf.get(pos) == '/') { x.setSubpath(pos, path.limit()); return route.handler; } } } } if (genericHandler != null) { x.setSubpath(path.start, path.limit()); return genericHandler; } } throw x.notFound(); }
public AbstractMapImpl(int width, int initialBucketSize) { this.entries = new SimpleHashTable<MapEntry<K, V>>(width, initialBucketSize); }
@Override public T get(Buf buf, BufRange key) { long hash = hash(buf.bytes(), key); SimpleBucket<MapEntry<byte[], T>> candidates = entries.bucket(hash); if (candidates != null) { for (int i = 0; i < candidates.size(); i++) { MapEntry<byte[], T> route = candidates.get(i); if (BytesUtil.matches(buf.bytes(), key, route.key, true)) { return route.value; } } } return defaultValue; }