Coder Social home page Coder Social logo

gord's Introduction

Overview

Go ordered sets.

Features:

  • LinkedSet: ordered set with near-constant-time (O(1)) performance for inserting, deleting, and moving elements. Backed by a map and a doubly-linked list.

  • SyncLinkedSet: concurrency-safe LinkedSet, slightly slower.

  • SliceSet: slice-backed ordered set. Simpler and faster for small sets, extreme performance degradation for large sets.

  • All implementations share a common interface.

  • Small with no dependencies.

See the documentation at https://godoc.org/github.com/mitranim/gord.

Example:

import "github.com/mitranim/gord"

set := gord.NewOrdSet()

// Note the order.
set.Add(20)
set.Add(10)
set.Add(30)

// Redundant and doesn't change the order.
set.Add(30)
set.Add(10)
set.Add(20)

set.Has(10)    // true
set.Has(40)    // false
set.Values()   // []interface{}{20, 10, 30}

set.PopFirst() // 20
set.PopLast()  // 30
set.Values()   // []interface{}{10}

Known Limitations

  • Has room for performance optimizations.

  • LinkedSet and SyncLinkedSet don't expose a way to iterate over elements without allocating a slice via .Values(). Can be rectified on demand.

License

https://unlicense.org

Misc

I'm receptive to suggestions. If this library almost satisfies you but needs changes, open an issue or chat me up. Contacts: https://mitranim.com/#contacts

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.