Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dynarray

Package dynarray contains data structures for Dynamic Arrays.

About

DynArray works like regular arrays except for the following differences:

  1. Indexing is one based.
  2. An index can hold no value at all.
  3. Memory usage depends on count of values stored not the index count.
  4. When storing values beyond the highest index, length grows automatically instead of seeing index out of bounds.
  5. Inserting into or deleting from the beginning or middle of the array takes O(log n) time instead of O(n) time.
  6. Accessing a random array element takes O(log n) time instead of O(1) time.

Cursor instances can speed up array access if reading and writing to the same area of the DynArray. DynArray instances are not safe to use with multiple goroutines.

Examples

package main

import (
    "fmt"

    "github.com/keep94/dynarray"
)

func main() {
    var dyn dynarray.DynArray[string]
    dyn.Set(1, "hello")
    dyn.Set(3, "goodbye")
    for i := 1; i <= dyn.Len(); i++ {
        fmt.Println(dyn.GetOrElse(i, "novalue"))
    }
    // Prints:
    //
    // hello
    // novalue
    // goodbye
}

More documentation and examples can be found here.

About

Package dynarray contains data structures for Dynamic Arrays.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages