orderedset

package module
Version: v0.0.0-...-8e67b20 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2018 License: Apache-2.0 Imports: 3 Imported by: 3

README

orderedset

Insertion ordered set implementation in golang.

License CircleCI Status Coverage Report Go Report Card CII Best Practices GoDoc

Install

go get github.com/goombaio/orderedset

You can also update an already installed version:

go get -u github.com/goombaio/orderedset

Example of use

package main

import (
    "github.com/goombaio/orderedset"
)

func main() {
    s := orderedset.NewOrderedSet()
    s.Add("First element")
    s.Add("Second element")
    s.Add("Last element")

    for _, entry := range s.Values() {
        fmt.Println(entry)
    }
    // Output:
    // First element
    // Second element
    // Last element
}

License

Copyright (c) 2018 Goomba project Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Overview

Package orderedset implements a dynamic, insertion-ordered, set abstract data type. A set is an abstract data type that can store unique values.

Curent implementation

  • Is a dynamic set. It implements actions to Add() or Remove() elements from it among others.
  • Is ordered. Instead the generic set, this implementation is insertion ordered, meaning that when iterating over its elements, it will return them in order they where inserted originally.

Example

package main

import (
	"github.com/goombaio/orderedset"
)

func main() {
	s := orderedset.NewOrderedSet()
	s.Add("First element")
	s.Add("Second element")
	s.Add("Last element")

	for _, entry := range s.Values() {
		fmt.Println(entry)
	}
	// Output:
	// First element
	// Second element
	// Last element
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OrderedSet

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

OrderedSet represents a dynamic, insertion-ordered, set abstract data type.

Example
package main

import (
	"fmt"

	"github.com/goombaio/orderedset"
)

func main() {
	s := orderedset.NewOrderedSet()
	s.Add("First element")
	s.Add("Second element")
	s.Add("Last element")

	for _, entry := range s.Values() {
		fmt.Println(entry)
	}
}
Output:

First element
Second element
Last element

func NewOrderedSet

func NewOrderedSet() *OrderedSet

NewOrderedSet creates a new empty OrderedSet.

func (*OrderedSet) Add

func (s *OrderedSet) Add(items ...interface{})

Add adds items to the set.

If an item is found in the set it replaces it.

func (*OrderedSet) Contains

func (s *OrderedSet) Contains(items ...interface{}) bool

Contains return if set contains the specified items or not.

func (*OrderedSet) Empty

func (s *OrderedSet) Empty() bool

Empty return if the set in empty or not.

func (*OrderedSet) Remove

func (s *OrderedSet) Remove(items ...interface{})

Remove deletes items from the set.

If an item is not found in the set it doesn't fails, just does nothing.

func (*OrderedSet) Size

func (s *OrderedSet) Size() int

Size return the set number of elements.

func (*OrderedSet) String

func (s *OrderedSet) String() string

String implements Stringer interface.

Prints the set string representation, a concatenated string of all its string representation values in insertion order.

func (*OrderedSet) Values

func (s *OrderedSet) Values() []interface{}

Values return the set values in insertion order.

Jump to

Keyboard shortcuts

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