Skip to content

Commit

Permalink
Add actions workflow and fix some minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
zyedidia committed Mar 19, 2023
1 parent a371993 commit 0e4b88a
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 23 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
on: [push, pull_request]
name: Test
jobs:
test:
strategy:
matrix:
go-version: [1.19.x]
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v3

- name: Format
run: if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then exit 1; fi

- name: Vet
run: "go vet ./..."

- name: Install Staticcheck
uses: dominikh/staticcheck-action@v1.2.0
with:
version: "2022.1.1"
install-go: false
cache-key: ${{ matrix.go-version }}
- name: Staticcheck
run: "staticcheck ./..."

- name: Test
run: "go test ./..."
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generic Data Structures

![Test Workflow](https://github.com/zyedidia/generic/actions/workflows/test.yaml/badge.svg)
[![Go Reference](https://pkg.go.dev/badge/github.com/zyedidia/generic.svg)](https://pkg.go.dev/github.com/zyedidia/generic)
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/zyedidia/generic/blob/master/LICENSE)

Expand Down
12 changes: 6 additions & 6 deletions interval/itree.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
// following operations, where 'n' is the number of
// intervals in the tree:
//
// * Put: add an interval to the tree. Complexity: O(lg n).
// - Put: add an interval to the tree. Complexity: O(lg n).
//
// * Get: find an interval with a given starting position. Complexity O(lg n).
// - Get: find an interval with a given starting position. Complexity O(lg n).
//
// * Overlaps: find all intervals that overlap with a given interval. Complexity:
// O(lg n + m), where 'm' is the size of the result (number of overlapping
// intervals found).
// - Overlaps: find all intervals that overlap with a given interval. Complexity:
// O(lg n + m), where 'm' is the size of the result (number of overlapping
// intervals found).
//
// * Remove: remove the interval at a given position. Complexity: O(lg n).
// - Remove: remove the interval at a given position. Complexity: O(lg n).
package interval

import (
Expand Down
2 changes: 1 addition & 1 deletion mapset/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (s Set[K]) Size() int {

// Each calls 'fn' on every item in the set in no particular order.
func (s Set[K]) Each(fn func(key K)) {
for k, _ := range s.m {
for k := range s.m {
fn(k)
}
}
10 changes: 5 additions & 5 deletions multimap/avl.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ func (m *avlMultiMap[K, V, C]) EachAssociation(fn func(key K, values []V)) {
}

// NewAvlSlice creates a MultiMap using AVL tree and builtin slice.
// - Value type must be comparable.
// - Duplicate entries are permitted.
// - Keys are sorted, but values are unsorted.
// - Value type must be comparable.
// - Duplicate entries are permitted.
// - Keys are sorted, but values are unsorted.
func NewAvlSlice[K any, V comparable](keyLess g.LessFn[K]) MultiMap[K, V] {
m := &avlMultiMap[K, V, *valuesSlice[V]]{
keyLess: keyLess,
Expand All @@ -104,8 +104,8 @@ func NewAvlSlice[K any, V comparable](keyLess g.LessFn[K]) MultiMap[K, V] {
}

// NewAvlSet creates a MultiMap using AVL tree and AVL set.
// - Duplicate entries are not permitted.
// - Both keys and values are sorted.
// - Duplicate entries are not permitted.
// - Both keys and values are sorted.
func NewAvlSet[K, V any](keyLess g.LessFn[K], valueLess g.LessFn[V]) MultiMap[K, V] {
m := &avlMultiMap[K, V, valuesSet[V]]{
keyLess: keyLess,
Expand Down
12 changes: 6 additions & 6 deletions multimap/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ func (m *mapMultiMap[K, V, C]) EachAssociation(fn func(key K, values []V)) {
}

// NewMapSlice creates a MultiMap using builtin map and builtin slice.
// - Both key type and value type must be comparable.
// - Duplicate entries are permitted.
// - Both keys and values are unsorted.
// - Both key type and value type must be comparable.
// - Duplicate entries are permitted.
// - Both keys and values are unsorted.
func NewMapSlice[K, V comparable]() MultiMap[K, V] {
m := &mapMultiMap[K, V, *valuesSlice[V]]{
makeValues: func() *valuesSlice[V] {
Expand All @@ -102,9 +102,9 @@ func NewMapSlice[K, V comparable]() MultiMap[K, V] {
}

// NewMapSet creates a MultiMap using builtin map and AVL set.
// - Key type must be comparable.
// - Duplicate entries are not permitted.
// - Values are sorted, but keys are unsorted.
// - Key type must be comparable.
// - Duplicate entries are not permitted.
// - Values are sorted, but keys are unsorted.
func NewMapSet[K comparable, V any](valueLess g.LessFn[V]) MultiMap[K, V] {
m := &mapMultiMap[K, V, valuesSet[V]]{
makeValues: func() valuesSet[V] {
Expand Down
6 changes: 3 additions & 3 deletions multimap/multimap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
//
// There are four implementations of the MultiMap data structure, identified by separate New* functions.
// They differ in the following ways:
// - whether key type and value type must be comparable.
// - whether duplicate entries (same key and same value) are permitted.
// - whether keys and values are sorted or unsorted in Get, Each, and EachAssociation methods.
// - whether key type and value type must be comparable.
// - whether duplicate entries (same key and same value) are permitted.
// - whether keys and values are sorted or unsorted in Get, Each, and EachAssociation methods.
package multimap

// MultiMap is an associative container that contains a list of key-value pairs, while permitting multiple entries with the same key.
Expand Down
1 change: 0 additions & 1 deletion prope/prope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func check(p *prope.Node[byte], r *rope.Node[byte], t *testing.T) {
if r.Len() != p.Len() {
t.Errorf("incorrect length: %d %d", r.Len(), p.Len())
}
return
}

const datasz = 5000
Expand Down
2 changes: 1 addition & 1 deletion queue/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestQueueTryPeek(t *testing.T) {
wantValue := 1
wantOk := true

if gotOk != gotOk {
if wantOk != gotOk {
t.Errorf("got ok %v, want ok %v", gotOk, wantOk)
}
if gotValue != wantValue {
Expand Down

0 comments on commit 0e4b88a

Please sign in to comment.