Top Description Fields Constructors Methods
org.eclipse.jetty.util

pack-priv abstract Class AbstractTrie<V>

extends Object
implements Index.Mutable<V>
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.util.Index.Mutable, org.eclipse.jetty.util.Index
Known Direct Subclasses
org.eclipse.jetty.util.ArrayTernaryTrie, org.eclipse.jetty.util.ArrayTernaryTrie.Growing, org.eclipse.jetty.util.ArrayTrie, org.eclipse.jetty.util.EmptyTrie, org.eclipse.jetty.util.TreeTrie
Type Parameters
<V>
the type of object that the Trie holds
Imports
java.nio.ByteBuffer, java.nio.charset.StandardCharsets, java.util.ArrayList, .Collections, .List, .Map, .Set, java.util.stream.Collectors

Abstract Trie implementation.

Provides some common implementations, which may not be the most efficient. For byte operations, the assumption is made that the charset is ISO-8859-1

Field Summary

Modifier and TypeField and Description
pack-priv final boolean

Constructor Summary

AccessConstructor and Description
protected
AbstractTrie(boolean caseSensitive)

Method Summary

Modifier and TypeMethod and Description
public V
get(String
The key
s
)

Implements org.eclipse.jetty.util.Index.get.

Get an exact match from a String key
public V
get(ByteBuffer
The buffer
b
)

Implements org.eclipse.jetty.util.Index.get.

Get an exact match from a segment of a ByteBuffer as key
public V
getBest(String
The string
s
)

Implements org.eclipse.jetty.util.Index.getBest.

Get the best match from key in a String, which may be a prefix match or an exact match.
public V
getBest(byte[]
The buffer
b
,
int
The offset within the array of the key
offset
,
int
the length of the key
len
)

Implements org.eclipse.jetty.util.Index.getBest.

Get the best match from key in a byte array.
public boolean
public boolean
public boolean
put(V
The value and key
v
)

Implements org.eclipse.jetty.util.Index.Mutable.put.

Put a value as both a key and a value.
protected boolean
putAll(Map<String, V> contents)

public V
remove(String
The key for the entry
s
)

Implements org.eclipse.jetty.util.Index.Mutable.remove.

Remove an entry from the index.
protected static int

Returns:

The capacity in nodes of a tree decomposition
requiredCapacity
(Set<String>
The keys to be put in a Trie
keys
,
boolean
true if the capacity should be calculated with case-sensitive keys
caseSensitive
)

Calculate required Trie capacity in nodes of a tree decomposition of the keys.

private static int

Returns:

The capacity in tree nodes of the substree
requiredCapacity
(List<String>
The keys to calculate the capacity for
keys
,
int
The offset of the first key to be considered
offset
,
int
The number of keys to be considered
length
,
int
The character to be considered
index
)

Calculate required Trie capacity in nodes of a sub-tree decomposition of the keys.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_caseSensitiveback to summary
pack-priv final boolean _caseSensitive

Constructor Detail

AbstractTrieback to summary
protected AbstractTrie(boolean caseSensitive)

Method Detail

getback to summary
public V get(String s)

Implements org.eclipse.jetty.util.Index.get.

Doc from org.eclipse.jetty.util.Index.get.

Get an exact match from a String key

Parameters
s:String

The key

Returns:V

the value for the string key

getback to summary
public V get(ByteBuffer b)

Implements org.eclipse.jetty.util.Index.get.

Doc from org.eclipse.jetty.util.Index.get.

Get an exact match from a segment of a ByteBuffer as key

Parameters
b:ByteBuffer

The buffer

Returns:V

The value or null if not found

getBestback to summary
public V getBest(String s)

Implements org.eclipse.jetty.util.Index.getBest.

Doc from org.eclipse.jetty.util.Index.getBest.

Get the best match from key in a String, which may be a prefix match or an exact match.

Parameters
s:String

The string

Returns:V

The value or null if not found

getBestback to summary
public V getBest(byte[] b, int offset, int len)

Implements org.eclipse.jetty.util.Index.getBest.

Doc from org.eclipse.jetty.util.Index.getBest.

Get the best match from key in a byte array. The key is assumed to by ISO_8859_1 characters.

Parameters
b:byte[]

The buffer

offset:int

The offset within the array of the key

len:int

the length of the key

Returns:V

The value or null if not found

isCaseInsensitiveback to summary
public boolean isCaseInsensitive()
isCaseSensitiveback to summary
public boolean isCaseSensitive()
putback to summary
public boolean put(V v)

Implements org.eclipse.jetty.util.Index.Mutable.put.

Doc from org.eclipse.jetty.util.Index.Mutable.put.

Put a value as both a key and a value.

Parameters
v:V

The value and key

Returns:boolean

True if the Trie had capacity to add the field.

putAllback to summary
protected boolean putAll(Map<String, V> contents)
removeback to summary
public V remove(String s)

Implements org.eclipse.jetty.util.Index.Mutable.remove.

Doc from org.eclipse.jetty.util.Index.Mutable.remove.

Remove an entry from the index.

Parameters
s:String

The key for the entry

Returns:V

The removed value of the entry

requiredCapacityback to summary
protected static int requiredCapacity(Set<String> keys, boolean caseSensitive)

Calculate required Trie capacity in nodes of a tree decomposition of the keys. For example given the keys:

  • utf_16
  • utf_8
  • utf16
  • utf8
The tree switching by character is:
                           1 - 6
                         /
                       _ - 8
                     /
    root - u - t - f - 1 - 6
                     \
                       8
The count also applies to ternary trees as follows:
    root - u - t - f - _ ----- 1 - 6
                        \       \
                         1 - 6   8
                          \
                           8
In both cases above there are 10 character nodes plus the root node that can hold a value for the empty string key, so the returned capacity is 11.
Parameters
keys:Set<String>

The keys to be put in a Trie

caseSensitive:boolean

true if the capacity should be calculated with case-sensitive keys

Returns:int

The capacity in nodes of a tree decomposition

requiredCapacityback to summary
private static int requiredCapacity(List<String> keys, int offset, int length, int index)

Calculate required Trie capacity in nodes of a sub-tree decomposition of the keys.

Parameters
keys:List<String>

The keys to calculate the capacity for

offset:int

The offset of the first key to be considered

length:int

The number of keys to be considered

index:int

The character to be considered

Returns:int

The capacity in tree nodes of the substree