ordered

package
v2.0.0-...-4b7107c Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: MIT Imports: 4 Imported by: 0

README

orderedSet

Description

An ordered set of any type. Given a set of n elements, where all n elements are of the same type, this structure will ensure the ordering is unchanged and represents the order in which the elements were received.

  • Elements are stored in order of storage
  • Elements are addressable by index.
  • Elements are guaranteed unique
  • Elements are of the same type

Methods

.Add(item any) error

Add a new item to the set and throw an error if it already exists.

.Count() int

Return a count of records

.Delete(pos int) error

Delete an existing

.List() []any

Return a list of elements []any from the given set

.Pop() any

Pop element 0 from the set and return its value

.Push(item any)

Push an element to the top of the set.

Build / test

For local builds, there is a Makefile but there is also a GitHub action for this project.

make test - run tests

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

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

Set - Create map of any to its type

func (*Set) Add

func (set *Set) Add(item any) (err error)

Add - add item to set if the item is the same type as the set

func (*Set) Count

func (set *Set) Count() int

Count - return a count of the records in a set

func (*Set) Delete

func (set *Set) Delete(pos int) error

func (*Set) Empty

func (set *Set) Empty() bool

Empty - Return boolean true if set has 1 or more records

func (*Set) Has

func (set *Set) Has(data any) bool

Has scan the set and see if an item (data) has been seen before.

func (*Set) List

func (set *Set) List() (result []any)

List - return a list of items

func (*Set) Pop

func (set *Set) Pop() any

Pop - return the item at the head of the set.

func (*Set) Push

func (set *Set) Push(item any) error

Push - Push the item to the top of the list (n+1)

func (*Set) TypeCheck

func (set *Set) TypeCheck(data any) (err error)

TypeCheck - verify that the given data is of the same type as the elements already there

Jump to

Keyboard shortcuts

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