dynamicarray

package
v0.0.0-...-c4df37a Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2021 License: MIT Imports: 1 Imported by: 0

README

Dynamic Array

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorIndexOutOfRange will be returned if a given index is out of range a container.
	ErrorIndexOutOfRange = errors.New("an array's index should be >= 0 and < length of an array")

	// ErrorElementNotFound will be returned if a needed elements is not in a container.
	ErrorElementNotFound = errors.New("there is no a needed element in an array")

	// ErrorExceededCapacity will be returned if a given capacity is out of range.
	ErrorExceededCapacity = errors.New("capacity size should be between 1 and < 1024")
)

Functions

This section is empty.

Types

type Array

type Array interface {
	Add(int32) error
	Capacity() int32
	Find(interface{}) (int32, error)
	Get(int32) (interface{}, error)
	RemoveAt(int32) error
	Reverse()
	Set(int32, interface{}) error
	Size() int32
}

Array is an ADT.

type DynamicArray

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

DynamicArray is an implementation of a dynamic array using "static" arrays.

func NewDynamicArray

func NewDynamicArray() *DynamicArray

NewDynamicArray creates a new dynamic array with default capacity = 4.

func NewDynamicArrayWithCapacity

func NewDynamicArrayWithCapacity(capacity int32) (*DynamicArray, error)

NewDynamicArrayWithCapacity creates a new dynamic array with provided capacity that should not exceed MaxInt32 value, and be more than 0.

func (*DynamicArray) Add

func (d *DynamicArray) Add(element interface{}) error

Add appends an element to the end of an array. In case, there is insufficient capacity it will double a capacity of an array to keep append time complexity constant.

func (*DynamicArray) Capacity

func (d *DynamicArray) Capacity() int32

Capacity returns a number of elements in an array.

func (*DynamicArray) Find

func (d *DynamicArray) Find(element interface{}) (int32, error)

Find performs linear search on an array.

func (*DynamicArray) Get

func (d *DynamicArray) Get(index int32) (interface{}, error)

Get returns an element by a given index.

func (*DynamicArray) RemoveAt

func (d *DynamicArray) RemoveAt(index int32) error

RemoveAt a given index.

func (*DynamicArray) Reverse

func (d *DynamicArray) Reverse()

Reverse an array using two pointers approach.

func (*DynamicArray) Set

func (d *DynamicArray) Set(index int32, value interface{}) error

Set an element by a given index.

func (*DynamicArray) Size

func (d *DynamicArray) Size() int32

Size returns a number of elements in an array.

Jump to

Keyboard shortcuts

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