Class SmallSortedMap<K extends FieldSet.FieldDescriptorLite<K>>

java.lang.Object
java.util.AbstractMap<K,Object>
com.google.protobuf.SmallSortedMap<K>
All Implemented Interfaces:
Map<K,Object>

class SmallSortedMap<K extends FieldSet.FieldDescriptorLite<K>> extends AbstractMap<K,Object>
A custom map implementation from FieldSet.FieldDescriptorLite to Object.

This implementation is heavily optimized for insertion and iteration when the map is built (via put()) with keys (FieldDescriptors) in ascending sorted order. When entries are added in increasing order of the FieldDescriptor, no sorting overhead is incurred. The entries are simply appended to a backing array, making memory allocation and insertion highly efficient.

Iteration over the entries is straightforward and avoids the creation of an Iterator object. It should be done as follows:

for (int i = 0; i < fieldMap.size(); i++) {
  process(fieldMap.getArrayEntryAt(i));
}
The resulting iteration is in order of ascending field tag number. The object returned by entrySet() adheres to the same contract but is less efficient as it necessarily involves creating an object for iteration.

If entries are added out of order, the map defers sorting until necessary (e.g., when iterating, querying size, or retrieving elements). This lazily sorts and deduplicates the underlying array.

Modifying operations (such as put(), remove(), or clear()) are not thread-safe until makeImmutable() is called, after which any modifying operation will result in an UnsupportedOperationException. However, instances are thread-safe for concurrent read-only operations (such as get() or size()) even before makeImmutable() is called, as long as no modifying operations are performed concurrently.