Skip to content

Commit f6ec6c1

Browse files
authored
Merge pull request #1 from NeutrinoCorp/beta
Beta Release
2 parents a571582 + d826694 commit f6ec6c1

Some content is hidden

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

70 files changed

+4615
-232
lines changed

.github/workflows/publish.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Publish Go Module
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Force Go package publishing
14+
run: make publish-pkg version="${{github.ref_name}}" module_name=streams

.github/workflows/test-build.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Continuous Integration
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
env:
12+
GO111MODULE: 'on'
13+
14+
permissions:
15+
contents: read
16+
pull-requests: read
17+
checks: write
18+
19+
jobs:
20+
lint:
21+
name: Run Go Linter
22+
strategy:
23+
matrix:
24+
os: ['ubuntu-latest']
25+
go-version: ['1.21', '1.22']
26+
runs-on: ${{ matrix.os }}
27+
steps:
28+
- uses: actions/checkout@v4
29+
- name: Set up Go
30+
uses: actions/setup-go@v5
31+
with:
32+
go-version: ${{ matrix.go-version }}
33+
cache: true
34+
35+
- name: Run linter
36+
uses: golangci/golangci-lint-action@v6
37+
with:
38+
version: v1.58
39+
40+
unit-testing:
41+
name: Run Unit Tests
42+
strategy:
43+
matrix:
44+
os: [ 'ubuntu-latest' ]
45+
go-version: ['1.21', '1.22' ]
46+
runs-on: ${{ matrix.os }}
47+
steps:
48+
- uses: actions/checkout@v4
49+
- name: Set up Go
50+
uses: actions/setup-go@v5
51+
with:
52+
go-version: ${{ matrix.go-version }}
53+
cache: true
54+
55+
- name: Run Unit Testing
56+
run: go test ./... -cover
57+
58+
integration-testing:
59+
name: Run Integration Tests
60+
strategy:
61+
matrix:
62+
os: [ 'ubuntu-latest' ]
63+
go-version: ['1.21', '1.22' ]
64+
runs-on: ${{ matrix.os }}
65+
needs: ['unit-testing']
66+
steps:
67+
- uses: actions/checkout@v4
68+
69+
- name: Set up Go
70+
uses: actions/setup-go@v5
71+
with:
72+
go-version: ${{ matrix.go-version }}
73+
cache: true
74+
75+
- name: Run Integration Testing
76+
run: go test ./... -tags=integration -cover

.golangci.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Refer to golangci-lint's example config file for more options and information:
2+
# https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml
3+
4+
run:
5+
tests: true
6+
timeout: 5m
7+
allow-parallel-runners: true
8+
modules-download-mode: readonly
9+
10+
output:
11+
formats:
12+
- format: github-actions
13+
14+
linters:
15+
enable:
16+
- goimports
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
36+
37+
issues:
38+
exclude-use-default: false
39+
max-issues-per-linter: 0
40+
max-same-issues: 0
41+
fix: true

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
run-test:
2+
go test ./... -cover

README.md

Lines changed: 126 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,126 @@
1-
# nolan
2-
Neutrino core libraries for Go
1+
# Nolan
2+
3+
Welcome `nolan`, a comprehensive toolkit designed to enhance the development of Golang applications by providing a range of modules and utilities that streamline common programming tasks.
4+
5+
## Features
6+
7+
This library includes a variety of modules that offer functionalities such as:
8+
9+
- **Data Manipulation**: Tools for handling and transforming data structures.
10+
- **Concurrency Utilities**: Enhancements for Go's native concurrency model, making goroutine management easier.
11+
- **Process Utilities**: Easy-to-use modules for process scheduling and management.
12+
13+
## Getting Started
14+
15+
To use this library, you need to have Go installed on your machine. You can install Go by following the instructions on the [official Go website](https://golang.org/dl/).
16+
17+
### Installation
18+
19+
Install the library with the following Go command:
20+
21+
```bash
22+
go get github.com/neutrinocorp/nolan
23+
```
24+
25+
### Usage
26+
27+
Here's a simple example of how to use a module from this library:
28+
29+
#### Data Structures
30+
31+
```go
32+
package main
33+
34+
import (
35+
"fmt"
36+
37+
"github.com/neutrinocorp/nolan"
38+
"github.com/neutrinocorp/nolan/collection/list"
39+
"github.com/neutrinocorp/nolan/collection/queue"
40+
)
41+
42+
func main() {
43+
ls := list.NewDoublyLinkedList[int]()
44+
ls.Add(1)
45+
ls.Add(2)
46+
ls.Add(3)
47+
fmt.Println(ls.ToSlice())
48+
49+
deque := queue.NewDequeList[int](ls)
50+
fmt.Println(deque.PollLast()) // 3
51+
fmt.Println(deque.PollLast()) // 2
52+
fmt.Println(deque.PollLast()) // 1
53+
}
54+
```
55+
56+
#### Processing
57+
58+
```go
59+
package main
60+
61+
import (
62+
"context"
63+
"log"
64+
"time"
65+
66+
"github.com/neutrinocorp/nolan"
67+
"github.com/neutrinocorp/nolan/collection/list"
68+
"github.com/neutrinocorp/nolan/collection/queue"
69+
"github.com/neutrinocorp/nolan/function"
70+
"github.com/neutrinocorp/nolan/proc"
71+
)
72+
73+
func main() {
74+
var delegateFunc function.DelegateSafeFuncWithContext[string] = func(ctx context.Context, args string) error {
75+
log.Printf("some args %s", args)
76+
return nil
77+
}
78+
79+
sched := proc.NewTaskScheduler[string](delegateFunc)
80+
go func() {
81+
if err := sched.Start(); err != nil {
82+
panic(err)
83+
}
84+
}()
85+
86+
if err := sched.SubmitWork("some job"); err != nil {
87+
panic(err) // this will return an error if the process is already closed
88+
}
89+
if err := sched.SubmitWork("some job"); err != nil {
90+
panic(err)
91+
}
92+
93+
// ... os.Stdout will print jobs as delegate will get executed
94+
95+
// execute graceful shutdown
96+
ctx, cancelFunc := context.WithTimeout(context.Background(), time.Second * 30)
97+
defer cancelFunc()
98+
if err := sched.Stop(ctx); err != nil {
99+
panic(err) // will return error if context reaches deadline before actual process termination (i.e., interrupted)
100+
}
101+
}
102+
```
103+
104+
## Documentation
105+
106+
For more detailed documentation on each module and its functions, visit the [Documentation](https://github.com/neutrinocorp/nolan/wiki) section of this repository.
107+
108+
## Contributing
109+
110+
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
111+
112+
1. Fork the Project
113+
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
114+
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
115+
4. Push to the Branch (`git push origin feature/AmazingFeature`)
116+
5. Open a Pull Request
117+
118+
## License
119+
120+
Distributed under the Apache 2.0 License. See `LICENSE` for more information.
121+
122+
## Contact
123+
124+
Your Name - [@neutrinocorp](https://twitter.com/neuntrinocorp) - oss@neutrinocorp.org
125+
126+
Project Link: [https://github.com/neuntrinocorp/nolan](https://github.com/neuntrinocorp/nolan)

collection/bag/bag.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/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: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +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-
// Clear Removes all the elements from this collection.
12+
// AddSlice adds all the elements in the specified slice (variadic) to this collection.
13+
AddSlice(items ...T) bool
14+
// Clear removes all the elements from this collection.
1215
Clear()
13-
// Len Returns the number of elements in this collection.
16+
// Len returns the number of elements in this collection.
1417
Len() int
15-
// IsEmpty Returns true if this collection contains no elements.
18+
// IsEmpty returns true if this collection contains no elements.
1619
IsEmpty() bool
17-
// 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.
1821
ToSlice() []T
19-
}
20-
21-
type ComparableCollection[T comparable] interface {
22-
// Contains Returns true if this collection contains the specified element.
23-
Contains(v T) bool
24-
// ContainsAll Returns true if this collection contains all the elements in the specified collection.
25-
ContainsAll(src Collection[T]) bool
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.
24+
ForEach(predicateFunc IterablePredicateFunc[T])
2625
}

collection/compare.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package collection
2+
3+
import (
4+
"github.com/neutrinocorp/nolan/function"
5+
)
6+
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]
11+
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).
15+
type ComparableCollection[T comparable] interface {
16+
Collection[T]
17+
// Contains returns true if this collection contains the specified element.
18+
Contains(v T) bool
19+
// ContainsAll returns true if this collection contains all the elements in the specified collection.
20+
ContainsAll(src Collection[T]) bool
21+
// ContainsSlice returns true if this collection contains all the elements in the specified slice.
22+
ContainsSlice(src ...T) bool
23+
}
24+
25+
// NOTE: This is used internally to share iterator instances.
26+
// This helps to reduce malloc as we can reuse iterator instances.
27+
func containsWithIterator[T comparable](iter Iterator[T], v T) bool {
28+
for iter.HasNext() {
29+
if val := iter.Next(); val == v {
30+
return true
31+
}
32+
}
33+
return false
34+
}
35+
36+
// Contains returns true if this collection contains the specified element.
37+
func Contains[T comparable](src Collection[T], v T) bool {
38+
iter := src.NewIterator()
39+
return containsWithIterator[T](iter, v)
40+
}
41+
42+
// ContainsAll returns true if this collection contains all the elements in the specified collection.
43+
func ContainsAll[T comparable](src Collection[T], cmpColl Collection[T]) bool {
44+
// Time complexity of O(mn)
45+
srcIter := src.NewIterator()
46+
cmpCollIter := cmpColl.NewIterator()
47+
for cmpCollIter.HasNext() {
48+
item := cmpCollIter.Next()
49+
wasFound := containsWithIterator[T](srcIter, item)
50+
if !wasFound {
51+
return false
52+
}
53+
srcIter.Reset()
54+
}
55+
return true
56+
}
57+
58+
// ContainsSlice returns true if this collection contains all the elements in the specified slice.
59+
func ContainsSlice[T comparable](src Collection[T], cmpSlice []T) bool {
60+
iter := src.NewIterator()
61+
for _, item := range cmpSlice {
62+
wasFound := containsWithIterator[T](iter, item)
63+
if !wasFound {
64+
return false
65+
}
66+
iter.Reset()
67+
}
68+
return true
69+
}

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

0 commit comments

Comments
 (0)