🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

github.com/wernerstrydom/go-collections

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/wernerstrydom/go-collections

v0.2.0
Source
Go
Version published
Created
Source

Collections

Overview

This is a collection of data structures and algorithms implemented in Go. While one can use the standard library to implement these data structures, this library provides a more convenient and easy to use interface. There are collections that are safe for concurrent use and collections that are not.

This library doesn't import any other libraries, so it can be used in any project without worrying about dependency conflicts.

Installation

go get github.com/wernerstrydom/go-collections

Usage

The following is an example of how to use the list collection. The concurrent list is used in this example, but the same methods are available for the non-concurrent list. The only difference is that the non-concurrent list is not safe for concurrent use.

package main

import (
		"github.com/wernerstrydom/go-collections/concurrent"
		"fmt"
)

func main() {
    // write an example showing all the uses of a list
    list := concurrent.NewList[string]()
    _ = list.Add("a")
    _ = list.Add("b")
    _ = list.Add("c")

    fmt.Println("After Add")
    for i := 0; i < list.Len(); i++ {
        item, _ := list.Get(i)
        fmt.Println(item)
    }

    fmt.Println("Index of b")
    index := list.IndexOf("b")
    fmt.Println(index)

    fmt.Println("Insert d at index 1")
    _ = list.Insert(1, "d")
    for i := 0; i < list.Len(); i++ {
        item, _ := list.Get(i)
        fmt.Println(item)
    }

    fmt.Println("Remove b")
    _ = list.Remove("b")
    for i := 0; i < list.Len(); i++ {
        item, _ := list.Get(i)
        fmt.Println(item)
    }

    fmt.Println("Remove at index 1")
    _ = list.RemoveAt(1)
    for i := 0; i < list.Len(); i++ {
        item, _ := list.Get(i)
        fmt.Println(item)
    }

    fmt.Println("Clear")
    list.Clear()
    fmt.Println(list.Len())

    // Output:
    // After Add
    // a
    // b
    // c
    // Index of b
    // 1
    // Insert d at index 1
    // a
    // d
    // b
    // c
    // Remove b
    // a
    // d
    // c
    // Remove at index 1
    // a
    // c
    // Clear
    // 0
} 

Collections

The following collections are available:

  • List
  • Stack
  • Queue

Algorithms

No algorithms are currently implemented.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

The library was inspired by the .NET Collections.

TODO

  • Implement algorithms
  • Implement more collections
    • Set
    • Map

Contributing

Please submit a pull request if you would like to contribute to this project.

Authors

Contact

Contact me at hello@wernerstrydom.com.

FAQs

Package last updated on 11 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts