Skip to content

Commit d826694

Browse files
committed
Major improvements
- Improve Collections API testing and interfaces - Refactor concurrency package - Add converter module - Redefine functional interfaces - Add task scheduler and process API - Add value utils module
1 parent 6d3e9ff commit d826694

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+3622
-609
lines changed

.github/workflows/test-build.yml

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,58 +8,66 @@ on:
88
branches:
99
- master
1010

11+
env:
12+
GO111MODULE: 'on'
13+
14+
permissions:
15+
contents: read
16+
pull-requests: read
17+
checks: write
18+
1119
jobs:
1220
lint:
1321
name: Run Go Linter
1422
strategy:
1523
matrix:
1624
os: ['ubuntu-latest']
17-
go-version: ['1.20','1.21', '1.22']
25+
go-version: ['1.21', '1.22']
1826
runs-on: ${{ matrix.os }}
1927
steps:
20-
- uses: actions/checkout@v3
28+
- uses: actions/checkout@v4
2129
- name: Set up Go
22-
uses: actions/setup-go@v4
30+
uses: actions/setup-go@v5
2331
with:
2432
go-version: ${{ matrix.go-version }}
25-
cache: false
33+
cache: true
2634

2735
- name: Run linter
28-
uses: golangci/golangci-lint-action@v3
36+
uses: golangci/golangci-lint-action@v6
2937
with:
30-
version: v1.54
38+
version: v1.58
3139

3240
unit-testing:
3341
name: Run Unit Tests
3442
strategy:
3543
matrix:
3644
os: [ 'ubuntu-latest' ]
37-
go-version: [ '1.20','1.21', '1.22' ]
45+
go-version: ['1.21', '1.22' ]
3846
runs-on: ${{ matrix.os }}
3947
steps:
40-
- uses: actions/checkout@v3
48+
- uses: actions/checkout@v4
4149
- name: Set up Go
42-
uses: actions/setup-go@v4
50+
uses: actions/setup-go@v5
4351
with:
4452
go-version: ${{ matrix.go-version }}
4553
cache: true
4654

4755
- name: Run Unit Testing
48-
run: go test ./... -cover -v
56+
run: go test ./... -cover
4957

5058
integration-testing:
5159
name: Run Integration Tests
5260
strategy:
5361
matrix:
5462
os: [ 'ubuntu-latest' ]
55-
go-version: [ '1.20','1.21', '1.22' ]
63+
go-version: ['1.21', '1.22' ]
5664
runs-on: ${{ matrix.os }}
5765
needs: ['unit-testing']
5866
steps:
59-
- uses: actions/checkout@v3
67+
- uses: actions/checkout@v4
6068

6169
- name: Set up Go
62-
uses: actions/setup-go@v4
70+
uses: actions/setup-go@v5
6371
with:
6472
go-version: ${{ matrix.go-version }}
6573
cache: true

.golangci.yml

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,40 @@
22
# https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml
33

44
run:
5-
tests: false
5+
tests: true
66
timeout: 5m
7+
allow-parallel-runners: true
78
modules-download-mode: readonly
89

910
output:
10-
format: github-actions
11+
formats:
12+
- format: github-actions
1113

1214
linters:
1315
enable:
14-
- errcheck
1516
- goimports
16-
- golint
17-
- govet
18-
- staticcheck
17+
presets:
18+
- bugs
19+
- comment
20+
- complexity
21+
- error
22+
- metalinter
23+
- module
24+
- performance
25+
- style
26+
- test
27+
- unused
28+
29+
#linters:
30+
# enable:
31+
# - errcheck
32+
# - goimports
33+
# - golint
34+
# - govet
35+
# - staticcheck
1936

2037
issues:
2138
exclude-use-default: false
2239
max-issues-per-linter: 0
23-
max-same-issues: 0
40+
max-same-issues: 0
41+
fix: true

collection/bag/bag.go

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,3 @@
11
package bag
22

3-
import (
4-
"github.com/neutrinocorp/nolan/collection"
5-
"github.com/neutrinocorp/nolan/collection/set"
6-
)
7-
8-
// Bag Defines a collection that counts the number of times an object appears in
9-
// the collection.
10-
type Bag[T any] interface {
11-
collection.Collection[T]
12-
AddCopies(v T, numberCopies int) bool
13-
GetCount(v T) int
14-
}
15-
16-
// NewUniqueSet Returns a set.Set of unique elements in the Bag.
17-
func NewUniqueSet[T comparable](src Bag[T]) set.Set[T] {
18-
buf := set.HashSet[T]{}
19-
iter := src.NewIterator()
20-
for iter.HasNext() {
21-
item := iter.Next()
22-
buf.Add(item)
23-
}
24-
return buf
25-
}
3+
// TODO: IMPLEMENT ME

collection/bag/hash.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package bag
2+
3+
// TODO: IMPLEMENT ME

collection/collection.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
package collection
22

3-
// Collection A collection represents a group of objects, known as its elements. Some collections allow duplicate
4-
// elements and others do not. Some are ordered and others unordered.
3+
// Collection a collection represents a group of objects, known as its elements.
4+
// Some collections allow duplicate elements and others do not.
5+
// Some are ordered and others unordered.
56
type Collection[T any] interface {
67
Iterable[T]
7-
// Add Ensures that this collection contains the specified element.
8+
// Add adds an element into this collection.
89
Add(v T) bool
9-
// AddAll Adds all the elements in the specified collection to this collection.
10+
// AddAll adds all the elements into this collection.
1011
AddAll(src Collection[T]) bool
11-
// AddSlice Adds all the elements in the specified slice (variadic) to this collection.
12+
// AddSlice adds all the elements in the specified slice (variadic) to this collection.
1213
AddSlice(items ...T) bool
13-
// Clear Removes all the elements from this collection.
14+
// Clear removes all the elements from this collection.
1415
Clear()
15-
// Len Returns the number of elements in this collection.
16+
// Len returns the number of elements in this collection.
1617
Len() int
17-
// IsEmpty Returns true if this collection contains no elements.
18+
// IsEmpty returns true if this collection contains no elements.
1819
IsEmpty() bool
19-
// ToSlice Returns all the elements from this collection as a slice of T.
20+
// ToSlice returns all the elements from this collection as a slice of T.
2021
ToSlice() []T
21-
// ForEach Iterates through all the elements from this collection. Use predicate's return value to
22-
// indicate a break of the iteration.
22+
// ForEach traverses through all the elements from this collection.
23+
// Use predicate's return value to indicate a break of the iteration, TRUE meaning a break.
2324
ForEach(predicateFunc IterablePredicateFunc[T])
2425
}

collection/compare.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,26 @@ import (
44
"github.com/neutrinocorp/nolan/function"
55
)
66

7-
// ComparatorFunc A functional interface used to indicate if first argument is greater, less or equals than
8-
// the second. If equals this will return 0, if less -1 and if greater, then it returns 1.
9-
type ComparatorFunc[T any] function.BiPredicate[T, T, int]
7+
// ComparatorFunc a functional interface used to indicate if the first argument is greater, less or equals than
8+
// the second.
9+
// If equals, this will return 0, if less -1 and if greater, then it returns 1.
10+
type ComparatorFunc[T any] function.DelegateBiFunc[T, T, int]
1011

12+
// ComparableCollection a kind of Collection for comparable types.
13+
// Note that nolan offers a functional way to operate with Collection and comparable types
14+
// without the need of this interface (e.g., Contains, ContainsAll, ContainsSlice).
1115
type ComparableCollection[T comparable] interface {
1216
Collection[T]
13-
// Contains Returns true if this collection contains the specified element.
17+
// Contains returns true if this collection contains the specified element.
1418
Contains(v T) bool
15-
// ContainsAll Returns true if this collection contains all the elements in the specified collection.
19+
// ContainsAll returns true if this collection contains all the elements in the specified collection.
1620
ContainsAll(src Collection[T]) bool
17-
// ContainsSlice Returns true if this collection contains all the elements in the specified slice.
21+
// ContainsSlice returns true if this collection contains all the elements in the specified slice.
1822
ContainsSlice(src ...T) bool
1923
}
2024

21-
// used internally to share iterator instances. This helps to reduce malloc as
22-
// we can reuse iterator instances.
25+
// NOTE: This is used internally to share iterator instances.
26+
// This helps to reduce malloc as we can reuse iterator instances.
2327
func containsWithIterator[T comparable](iter Iterator[T], v T) bool {
2428
for iter.HasNext() {
2529
if val := iter.Next(); val == v {
@@ -29,13 +33,13 @@ func containsWithIterator[T comparable](iter Iterator[T], v T) bool {
2933
return false
3034
}
3135

32-
// Contains Returns true if this collection contains the specified element.
36+
// Contains returns true if this collection contains the specified element.
3337
func Contains[T comparable](src Collection[T], v T) bool {
3438
iter := src.NewIterator()
3539
return containsWithIterator[T](iter, v)
3640
}
3741

38-
// ContainsAll Returns true if this collection contains all the elements in the specified collection.
42+
// ContainsAll returns true if this collection contains all the elements in the specified collection.
3943
func ContainsAll[T comparable](src Collection[T], cmpColl Collection[T]) bool {
4044
// Time complexity of O(mn)
4145
srcIter := src.NewIterator()
@@ -51,7 +55,7 @@ func ContainsAll[T comparable](src Collection[T], cmpColl Collection[T]) bool {
5155
return true
5256
}
5357

54-
// ContainsSlice Returns true if this collection contains all the elements in the specified slice.
58+
// ContainsSlice returns true if this collection contains all the elements in the specified slice.
5559
func ContainsSlice[T comparable](src Collection[T], cmpSlice []T) bool {
5660
iter := src.NewIterator()
5761
for _, item := range cmpSlice {

collection/deque.go

Lines changed: 0 additions & 14 deletions
This file was deleted.

collection/doc.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Package collection is a robust package meticulously crafted to provide a rich assortment of
2+
// general-purpose data structures and algorithms. Whether you're working with lists, sets, maps, or more complex
3+
// data types, this package equips you with versatile tools to manage and manipulate data efficiently.
4+
//
5+
// From sorting and search algorithms to key data structures like arrays, linked lists, stacks, and queues,
6+
// 'Collection' offers a comprehensive suite to streamline your development workflow.
7+
package collection

collection/graph/search.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package graph
2+
3+
// TODO: IMPLEMENT ME
4+
// - Add dijkstra algo

collection/heap/binary.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package heap
2+
3+
// TODO: IMPLEMENT ME

0 commit comments

Comments
 (0)