-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved pkg from github.com/osspkg/goppy
- Loading branch information
Showing
91 changed files
with
3,540 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, build with `go test -c` | ||
*.db | ||
*.db-journal | ||
*.mmdb | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
.idea | ||
.tools | ||
.idea/ | ||
.vscode/ | ||
.tools/ | ||
|
||
coverage.txt | ||
coverage.out | ||
|
||
bin/ | ||
vendor/ | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
author: "Mikhail Knyazhev <markus621@yandex.ru>" | ||
author: "Mikhail Knyazhev <markus621@yandex.com>" | ||
lic_short: "BSD 3-Clause" | ||
lic_file: LICENSE | ||
lic_file: LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
**Use issues for everything** | ||
|
||
- For a small change, just send a PR. | ||
- For bigger changes open an issue for discussion before sending a PR. | ||
- PR should have: | ||
- Test case | ||
- Documentation | ||
- Example (If it makes sense) | ||
- You can also contribute by: | ||
- Reporting issues | ||
- Suggesting new features or enhancements | ||
- Improve/fix documentation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,5 @@ | ||
# Algorithms | ||
|
||
Algorithmic calculation methods | ||
|
||
[![Coverage Status](https://coveralls.io/repos/github/osspkg/go-algorithms/badge.svg?branch=master)](https://coveralls.io/github/osspkg/go-algorithms?branch=master) | ||
[![Release](https://img.shields.io/github/release/osspkg/go-algorithms.svg?style=flat-square)](https://github.com/osspkg/go-algorithms/releases/latest) | ||
[![Go Report Card](https://goreportcard.com/badge/github.com/osspkg/go-algorithms)](https://goreportcard.com/report/github.com/osspkg/go-algorithms) | ||
[![CI](https://github.com/osspkg/go-algorithms/actions/workflows/ci.yml/badge.svg)](https://github.com/osspkg/go-algorithms/actions/workflows/ci.yml) | ||
|
||
## Install | ||
|
||
```shell | ||
go get -u go.osspkg.com/algorithms | ||
``` | ||
|
||
## List | ||
|
||
- Graph | ||
- Topological sorting | ||
- [Kahn's Algorithm](graph/kahn/type.go) | ||
- Information compression | ||
- [Reducing numbers](shorten/shorten.go) | ||
- Sorting algorithm | ||
- [Bubble sort](sorts/bubble.go) | ||
- [Cocktail shaker sort](sorts/cocktail.go) | ||
- [Insertion sort](sorts/insertion.go) | ||
- [Merge sort](sorts/merge.go) | ||
- [Selection sort](sorts/selection.go) | ||
- [Heapsort](sorts/heapsort.go) | ||
- Filtering algorithms | ||
- [Bloom filter](filters/bloom/bloom.go) | ||
# goX | ||
|
||
## License | ||
|
||
BSD-3-Clause License. See the LICENSE file for details | ||
BSD-3-Clause License. See the LICENSE file for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Algorithms | ||
|
||
Algorithmic calculation methods | ||
|
||
## Install | ||
|
||
```shell | ||
go get -u go.osspkg.com/x/algorithms | ||
``` | ||
|
||
## License | ||
|
||
BSD-3-Clause License. See the LICENSE file for details |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) 2019-2024 Mikhail Knyazhev <[email protected]>. All rights reserved. | ||
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file. | ||
*/ | ||
|
||
package base62 | ||
|
||
import "go.osspkg.com/x/algorithms/sorts" | ||
|
||
const size = 62 | ||
|
||
type Base62 struct { | ||
enc []byte | ||
dec map[byte]uint64 | ||
} | ||
|
||
func New(alphabet string) *Base62 { | ||
if len(alphabet) != size { | ||
panic("encoding alphabet is not 62-bytes long") | ||
} | ||
v := &Base62{ | ||
enc: []byte(alphabet), | ||
dec: make(map[byte]uint64, size), | ||
} | ||
for i, b := range v.enc { | ||
v.dec[b] = uint64(i) | ||
} | ||
return v | ||
} | ||
|
||
func (v *Base62) Encode(id uint64) string { | ||
result := make([]byte, 0, 11) | ||
for id > 0 { | ||
result = append(result, v.enc[id%size]) | ||
id /= size | ||
} | ||
sorts.Reverse(result) | ||
return string(result) | ||
} | ||
|
||
func (v *Base62) Decode(data string) uint64 { | ||
var id uint64 | ||
for _, b := range []byte(data) { | ||
id = id*size + v.dec[b] | ||
} | ||
return id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright (c) 2019-2024 Mikhail Knyazhev <[email protected]>. All rights reserved. | ||
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file. | ||
*/ | ||
|
||
package base62 | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
"testing" | ||
|
||
"go.osspkg.com/x/test" | ||
) | ||
|
||
func TestEncode_EncodeDecode(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
id uint64 | ||
want string | ||
}{ | ||
{name: "Case1", id: 1, want: "p"}, | ||
{name: "Case1", id: 2, want: "L"}, | ||
{name: "Case1", id: 3, want: "K"}, | ||
{name: "Case1", id: 4, want: "G"}, | ||
{name: "Case1", id: 5, want: "R"}, | ||
{name: "Case1", id: 6, want: "S"}, | ||
{name: "Case1", id: 7, want: "u"}, | ||
{name: "Case1", id: 8, want: "D"}, | ||
{name: "Case1", id: 9, want: "v"}, | ||
{name: "Case2", id: 10, want: "o"}, | ||
{name: "Case3", id: 100, want: "pH"}, | ||
{name: "Case4", id: 1000, want: "PD"}, | ||
{name: "Case5", id: 10000, want: "LIn"}, | ||
{name: "Case6", id: 100000, want: "c0k"}, | ||
{name: "Case7", id: 1000000000, want: "pRmUWP"}, | ||
{name: "Case8", id: 999999, want: "Glvp"}, | ||
{name: "Case20", id: math.MaxUint64, want: "XNWjtpSoji4"}, | ||
} | ||
|
||
v := New("0pLKGRSuDvorlO14Pjnd7XgQw9c8YhaIJ5iqtIHy3mWxM6C2TeAbFVBUkZfsNz") | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
h := v.Encode(tt.id) | ||
test.Equal(t, tt.want, h) | ||
id := v.Decode(h) | ||
test.Equal(t, tt.id, id) | ||
}) | ||
} | ||
} | ||
|
||
func TestEncode_Encode(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
str string | ||
want uint64 | ||
}{ | ||
{name: "Case1", str: "a", want: 30}, | ||
{name: "Case2", str: "aa", want: 1890}, | ||
{name: "Case3", str: "aaaaaaaa", want: 107380379795850}, | ||
} | ||
|
||
v := New("0pLKGRSuDvorlO14Pjnd7XgQw9c8YhaIJ5iqtIHy3mWxM6C2TeAbFVBUkZfsNz") | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
h := v.Decode(tt.str) | ||
fmt.Println(h) | ||
test.Equal(t, tt.want, h) | ||
}) | ||
} | ||
} | ||
|
||
func Benchmark_base62(b *testing.B) { | ||
v := New("0pLKGRSuDvorlO14Pjnd7XgQw9c8YhaIJ5iqtIHy3mWxM6C2TeAbFVBUkZfsNz") | ||
|
||
b.ReportAllocs() | ||
b.ResetTimer() | ||
|
||
b.RunParallel(func(pb *testing.PB) { | ||
for pb.Next() { | ||
v.Decode(v.Encode(math.MaxUint64)) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module go.osspkg.com/x/algorithms | ||
|
||
go 1.20 | ||
|
||
replace go.osspkg.com/x/test => ./../test |
File renamed without changes.
Oops, something went wrong.