container

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2021 License: Apache-2.0 Imports: 1 Imported by: 0

README

container

container implements containers, currently the containers are not thread-safe.

GoDoc Go.Dev reference codecov Action Status Go Report Card License Tag

  • How to use this repo
  • Containers
    • Stack
      • stack use container/list.
      • quick stack use builtin slice.
    • Queue
      • queue use container/list
      • quick queue use builtin slice.
    • PriorityQueue use builtin slice with container/heap
    • ArrayList use builtin slice.
    • LinkedList use container/list
    • LinkedMap use container/list and builtin map.
  • safe container
    • fifo FIFO is a thread-safe Queue. in which (a) each accumulator is simply the most recently provided object and (b) the collection of keys to process is a FIFO.

      FIFO solves this use case:

      • You want to process every object (exactly) once.
      • You want to process the most recent version of the object when you process it.
      • You do not want to process deleted objects, they should be removed from the queue.
      • You do not want to periodically reprocess objects.
    • heap Heap is a thread-safe producer/consumer queue that implements a heap data structure.It can be used to implement priority queues and similar data structures.
  • others

Donation

if package help you a lot,you can support us by:

Alipay

alipay

WeChat Pay

wxpay

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comparator

type Comparator func(v1, v2 interface{}) int

Comparator compares its two arguments for order. It returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

type KeyError

type KeyError struct {
	Obj interface{}
	Err error
}

KeyError will be returned any time a KeyFunc gives an error; it includes the object at fault.

func (KeyError) Error

func (k KeyError) Error() string

Error gives a human-readable description of the error.

type KeyFunc

type KeyFunc func(obj interface{}) (string, error)

KeyFunc knows how to make a key from an object. Implementations should be deterministic.

type LinkedMap

type LinkedMap interface {
	// Cap returns the capacity of elements of list l.
	Cap() int
	// Len returns the number of elements in the collection.
	Len() int
	// IsEmpty returns true if this container contains no elements.
	IsEmpty() bool
	// Clear initializes or clears all of the elements from this container.
	Clear()
	// Push associates the specified value with the specified key in this map.
	// If the map previously contained a mapping for the key,
	// the old value is replaced by the specified value. and then move the item to the back of the list.
	// If over the cap, it will remove the back item then push new item to back
	// It returns the previous value associated with the specified key, or nil if there was no mapping for the key.
	// A nil return can also indicate that the map previously associated nil with the specified key.
	Push(k, v interface{}) interface{}
	// PushFront associates the specified value with the specified key in this map.
	// If the map previously contained a mapping for the key,
	// the old value is replaced by the specified value. and then move the item to the front of the list.
	// If over the cap, it will remove the back item then push new item to front
	// It returns the previous value associated with the specified key, or nil if there was no mapping for the key.
	// A nil return can also indicate that the map previously associated nil with the specified key.
	PushFront(k, v interface{}) interface{}
	// PushBack associates the specified value with the specified key in this map.
	// If the map previously contained a mapping for the key,
	// the old value is replaced by the specified value. and then move the item to the back of the list.
	// If over the cap, it will remove the back item then push new item to back
	PushBack(k, v interface{}) interface{}

	// Poll removes the first element from this map, which is the head of the list.
	// It returns the (key, value, true) if the map isn't empty, or (nil, nil, false) if the map is empty.
	Poll() (interface{}, interface{}, bool)
	// PollFront return the front element value and then remove from list
	PollFront() (k interface{}, v interface{}, exist bool)
	// PollBack removes the last element from this map, which is the tail of the list.
	// It returns the (key, value, true) if the map isn't empty, or (nil, nil, false) if the map is empty.
	PollBack() (interface{}, interface{}, bool)
	// Remove removes the mapping for a key from this map if it is present.
	// It returns the value to which this map previously associated the key, and true,
	// or nil and false if the map contained no mapping for the key.
	Remove(k interface{}) (interface{}, bool)

	// Get returns the value to which the specified key is mapped, or nil if this map contains no mapping for the key.
	Get(k interface{}, defaultValue ...interface{}) interface{}
	// Peek return the front element value
	Peek() (k, v interface{}, exist bool)
	// PeekFront return the front element value
	PeekFront() (k, v interface{}, exist bool)
	// PeekBack return the back element value
	PeekBack() (k, v interface{}, exist bool)

	// Iterator returns an iterator over the elements in this map in proper sequence.
	Iterator(cb func(k interface{}, v interface{}) bool)
	// ReverseIterator returns an iterator over the elements in this map in reverse sequence as Iterator.
	ReverseIterator(cb func(k interface{}, v interface{}) bool)

	// Contains returns true if this map contains a mapping for the specified key.
	Contains(k interface{}) bool
	// ContainsValue returns true if this map maps one or more keys to the specified value.
	ContainsValue(v interface{}) bool
}

LinkedMap is a type of linked map, and LinkedMap implements this interface.

type List

type List interface {
	// Len returns the number of elements in the collection.
	Len() int
	// IsEmpty returns true if this container contains no elements.
	IsEmpty() bool
	// Clear initializes or clears all of the elements from this container.
	Clear()
	// Push appends the specified elements to the end of this list.
	Push(vals interface{})
	// PushFront inserts a new element e with value v at the front of list l
	PushFront(v interface{})
	// PushBack inserts a new element e with value v at the back of list l.
	PushBack(v interface{})
	// Add inserts the specified element at the specified position in this list.
	Add(index int, val interface{}) error

	// Poll return the front element value and then remove from list
	Poll() interface{}
	// PollFront return the front element value and then remove from list
	PollFront() interface{}
	// PollBack return the back element value and then remove from list
	PollBack() interface{}
	// Remove removes the element at the specified position in this list.
	// It returns an error if the index is out of range.
	Remove(index int) (interface{}, error)
	// RemoveValue removes the first occurrence of the specified element from this list, if it is present.
	// It returns false if the target value isn't present, otherwise returns true.
	RemoveValue(val interface{}) bool

	// Get returns the element at the specified position in this list. The index must be in the range of [0, size).
	Get(index int) (interface{}, error)
	// Peek return the front element value
	Peek() interface{}
	// PeekFront return the front element value
	PeekFront() interface{}
	// PeekBack return the back element value
	PeekBack() interface{}

	// Iterator returns an iterator over the elements in this list in proper sequence.
	Iterator(f func(interface{}) bool)
	// ReverseIterator returns an iterator over the elements in this list in reverse sequence as Iterator.
	ReverseIterator(f func(interface{}) bool)

	// Contains returns true if this list contains the specified element.
	Contains(val interface{}) bool
	// Sort sorts the element using default options below.
	// It sorts the elements into ascending sequence according to their natural ordering.
	Sort(reverse ...bool)
	// Values get a copy of all the values in the list
	Values() []interface{}
}

List is a type of list, both ArrayList and LinkedList implement this interface.

type Queue

type Queue interface {
	// Len returns the number of elements in the collection.
	Len() int
	// IsEmpty returns true if this container contains no elements.
	IsEmpty() bool
	// Clear initializes or clears all of the elements from this container.
	Clear()
	// Add inserts an element into the tail of this Queue.
	Add(interface{})
	// Peek retrieves, but does not remove, the head of this Queue, or return nil if this Queue is empty.
	Peek() interface{}
	// Poll retrieves and removes the head of the this Queue, or return nil if this Queue is empty.
	Poll() interface{}
	// Remove a single instance of the specified element from this queue, if it is present.
	Remove(val interface{})
	// Contains returns true if this queue contains the specified element.
	Contains(val interface{}) bool
}

Queue is a type of Queue, which is FIFO(first-in-first-out).

type Stack

type Stack interface {
	// Len returns the number of elements in the collection.
	Len() int
	// IsEmpty returns true if this container contains no elements.
	IsEmpty() bool
	// Clear initializes or clears all of the elements from this container.
	Clear()
	// Push pushes an element into this Stack.
	Push(interface{})
	// Pop pops the element on the top of this Stack.
	Pop() interface{}
	// Peek retrieves, but does not remove, the element on the top of this Stack, or return nil if this Stack is empty.
	Peek() interface{}
}

Stack is a Stack interface, which is LIFO (last-in-first-out).

type Store

type Store interface {

	// Add adds the given object to the accumulator associated with the given object's key
	Add(obj interface{}) error

	// Update updates the given object in the accumulator associated with the given object's key
	Update(obj interface{}) error

	// Delete deletes the given object from the accumulator associated with the given object's key
	Delete(obj interface{}) error

	// List returns a list of all the currently non-empty accumulators
	List() []interface{}

	// ListKeys returns a list of all the keys currently associated with non-empty accumulators
	ListKeys() []string

	// Get returns the accumulator associated with the given object's key
	Get(obj interface{}) (item interface{}, exists bool, err error)

	// GetByKey returns the accumulator associated with the given key
	GetByKey(key string) (item interface{}, exists bool, err error)

	// Replace will delete the contents of the store, using instead the
	// given list. Store takes ownership of the list, you should not reference
	// it after calling this function.
	Replace([]interface{}, string) error

	// Resync is meaningless in the terms appearing here but has
	// meaning in some implementations that have non-trivial
	// additional behavior (e.g., DeltaFIFO).
	Resync() error
}

Store is a generic object storage and processing interface. A Store holds a map from string keys to accumulators, and has operations to add, update, and delete a given object to/from the accumulator currently associated with a given key. A Store also knows how to extract the key from a given object, so many operations are given only the object.

In the simplest Store implementations each accumulator is simply the last given object, or empty after Delete, and thus the Store's behavior is simple storage.

Reflector knows how to watch a server and update a Store. This package provides a variety of implementations of Store.

Directories

Path Synopsis
Package arraylist implements both an array List.
Package arraylist implements both an array List.
Package linkedlist implements both an linked and a list.
Package linkedlist implements both an linked and a list.
Package priorityqueue implements an unbounded priority queue based on a priority heap.
Package priorityqueue implements an unbounded priority queue based on a priority heap.
safe
heap
Package heap This file implements a heap data structure.
Package heap This file implements a heap data structure.
Package stack implements a Stack, which orders elements in a LIFO (last-in-first-out) manner.
Package stack implements a Stack, which orders elements in a LIFO (last-in-first-out) manner.

Jump to

Keyboard shortcuts

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