stringutil

package
v0.3.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 2 Imported by: 34

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertListToMap added in v0.3.2

func ConvertListToMap(list []string, makeIfEmpty bool) map[string]struct{}

ConvertListToMap will convert list entries to map keys. If makeIfEmpty is true then a map is made for an empty list, otherwise nil is returned.

func ConvertMapKeysToList added in v0.3.2

func ConvertMapKeysToList(mapData map[string]struct{}, doSort bool) []string

ConvertMapKeysToList will return a list of map keys.

func DeduplicateList added in v0.3.2

func DeduplicateList(list []string, makeIfEmpty bool) (
	[]string, map[string]struct{})

DeduplicateList will return a list of strings with duplicates removed, preserving the (initial) ordering of the input list. If the input list has no duplicates, it is simply returned rather than returning a copy of the list. The unique map keys are also returned. If makeIfEmpty, a non-nil map is always returned.

Types

type StringDeduplicator

type StringDeduplicator struct {
	// contains filtered or unexported fields
}

func NewStringDeduplicator

func NewStringDeduplicator(lock bool) *StringDeduplicator

NewStringDeduplicator will create a StringDeduplicator which may be used to eliminate duplicate string contents. It maintains an internal map of unique strings. If lock is true then each method call will take an exclusive lock.

func (*StringDeduplicator) Clear

func (d *StringDeduplicator) Clear()

Clear will clear the internal map and statistics.

func (*StringDeduplicator) DeDuplicate

func (d *StringDeduplicator) DeDuplicate(str string) string

DeDuplicate will return a string which has the same contents as str. This method should be called for every string in the application.

func (*StringDeduplicator) DeleteUnregistered added in v0.3.3

func (d *StringDeduplicator) DeleteUnregistered()

DeleteUnregistered will delete all strings not previously registered with Register. This will also delete the previously registered strings. This may be used for garbage collection.

func (*StringDeduplicator) GetStatistics

GetStatistics will return de-duplication statistics.

func (*StringDeduplicator) Register added in v0.3.3

func (d *StringDeduplicator) Register(str string)

Register will register the specified string to indicate it is used, so that a later call to DeleteUnregistered will not delete it. This method should be called for every string in the application.

type StringDuplicationStatistics

type StringDuplicationStatistics struct {
	DuplicateBytes   uint64
	DuplicateStrings uint64
	UniqueBytes      uint64
	UniqueStrings    uint64
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL