Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // Defines the maximum length of a string which can be interned. // Strings longer than this will be generated but not interned. // // <= 0 indicates no limit on string length. MaxLen int // Defines the maximum total number of bytes which can be interned. // Once this limit is reached no new strings will be interned. // // <= 0 indicates no limit on total bytes, this may risk memory // exhaustion. MaxBytes int // Defines the number shards used internally to determine the level of // available concurrency for the interner. // // Important to note that this is not an exactly configurable // parameter. The number of shards must always be a power of two, and // the value provided here may be rounded up if necessary. // // <= 0 indicates that the interner should determine the number of // shards automatically. Shards int // Defines the offheap store to use for allocating interned strings. // // If nil then a new store will be created internally. Only needed if // you want to share a single offheap store across multiple interners. Store *offheap.Store }
type ConverterWithBytesId ¶
type ConverterWithBytesId interface {
Identity() []byte
}
An ConverterWithBytesId converts types to strings which are able to be canonically identified by a []byte value.
A good example of this is a plain []byte. But many complex types could use this converter with values which can't be canonically identified by a single uint64.
We don't include the String() method here, because we will _always_ directly convert the []byte into a string. This is important because the []byte value is compared, byte-wise, to the existing interned string value identified by the hash. If the string value could be different from the []byte from the identity then this comparison wouldn't work.
type ConverterWithUint64Id ¶
An ConverterWithUint64Id converts types to strings which are able to be canonically identified by a uint64 value.
A good example of this is an actual uint64 value. Another example would be a time.Time value which is identified by its UnixNanos() value.
type InternerWithBytesId ¶
type InternerWithBytesId[C ConverterWithBytesId] struct { // contains filtered or unexported fields }
A InternerWithBytesId is the type which manages the interning of strings.
func NewInternerWithBytesId ¶
func NewInternerWithBytesId[C ConverterWithBytesId](config Config) InternerWithBytesId[C]
Construct a new InternerWithBytesId with the provided config.
func (*InternerWithBytesId[C]) Get ¶
func (i *InternerWithBytesId[C]) Get(converter C) string
Converts converter into a string representation
The string value may be retrieved from an interning cache or stored in the cache. Regardless of whether the string is or was interned, the correct string value is returned.
func (*InternerWithBytesId[C]) GetStats ¶
func (i *InternerWithBytesId[C]) GetStats() StatsSummary
Retrieves the summarised stats for interned strings
type InternerWithUint64Id ¶
type InternerWithUint64Id[C ConverterWithUint64Id] struct { // contains filtered or unexported fields }
A InternerWithUint64Id is the type which manages the interning of strings.
func NewInternerWithUint64Id ¶
func NewInternerWithUint64Id[C ConverterWithUint64Id](config Config) InternerWithUint64Id[C]
Construct a new InternerWithUint64Id with the provided config.
func (*InternerWithUint64Id[C]) Get ¶
func (i *InternerWithUint64Id[C]) Get(converter C) string
Returns the string representation of converter.
The string value may be retrieved from an interning cache or stored in the cache. Regardless of whether the string is or was interned, the correct string value is returned.
func (*InternerWithUint64Id[C]) GetStats ¶
func (i *InternerWithUint64Id[C]) GetStats() StatsSummary
Retrieves the summarised stats for interned int strings
type Stats ¶
type Stats struct { Returned int Interned int MaxLenExceeded int UsedBytesExceeded int HashCollision int }
The statistics capturing the runtime behaviour of the interner.
Returned indicates the number of previously interned strings that have been returned.
Interned indicates the number of strings which have been interned.
MaxLenExceeded indicates the number of strings not interned because they were too long.
UsedBytesExceeded indicates the number of strings not interned because the global usedBytes limit was exceeded.
HashCollision indicates the number of strings not interned because of a hash collision.
type StatsSummary ¶
A summary of the stats for a specific type of interned converter.
UsedBytes stat is global across all converters.
Total is sum across all shards of the fields in Stats.
Shards holds the individual shard Stats.
func MakeSummary ¶
func MakeSummary(shards []Stats, usedBytes int) StatsSummary