Skip to content

Commit b61660e

Browse files
committed
Initial version.
1 parent cd1f29e commit b61660e

File tree

74 files changed

+11908
-1
lines changed

Some content is hidden

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

74 files changed

+11908
-1
lines changed

Diff for: .ci/golangci-lint.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
run:
2+
timeout: 5m
3+
tests: false
4+
fast: false
5+
skip-dirs-use-default: true
6+
print-issued-lines: true
7+
print-linter-name: true
8+
9+
linters:
10+
disable-all: true
11+
fast: false
12+
enable:
13+
- deadcode
14+
- errcheck
15+
- errname
16+
- gosimple
17+
- govet
18+
- ineffassign
19+
- staticcheck
20+
- structcheck
21+
- typecheck
22+
- unused
23+
- varcheck
24+
- asciicheck
25+
- bodyclose
26+
- dogsled
27+
- errorlint
28+
- exportloopref
29+
- forbidigo
30+
- forcetypeassert
31+
- goconst
32+
- gocritic
33+
- goerr113
34+
- gofmt
35+
- gofumpt
36+
- goimports
37+
- gomodguard
38+
- goprintffuncname
39+
- gosec
40+
- ifshort
41+
- importas
42+
- misspell
43+
- nakedret
44+
- noctx
45+
- nolintlint
46+
- prealloc
47+
- predeclared
48+
- revive
49+
- rowserrcheck
50+
- sqlclosecheck
51+
- stylecheck
52+
- testpackage
53+
- unconvert
54+
- unparam
55+
- wastedassign
56+
- whitespace
57+
- wrapcheck
58+
59+
issues:
60+
max-issues-per-linter: 1023
61+
max-same-issues: 255
62+
fix: false

Diff for: .github/dependabot.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: gomod
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
time: "09:00"
8+
open-pull-requests-limit: 30

Diff for: .github/workflows/go-test.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: go-test
2+
on:
3+
push:
4+
tags:
5+
- v*
6+
branches-ignore:
7+
- 'doc-*'
8+
- 'doc/*'
9+
pull_request:
10+
branches:
11+
- main
12+
- master
13+
- release
14+
jobs:
15+
go-tests:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/setup-go@v2
19+
with:
20+
go-version: ^1.17
21+
- uses: actions/checkout@v2
22+
- name: go-test
23+
run: |
24+
go test -v -count=1 \
25+
-covermode=count \
26+
-coverpkg=github.com/tunabay/go-bitarray \
27+
-coverprofile=cover.out \
28+
./...
29+
go tool cover -func=cover.out
30+
go tool cover -html=cover.out -o go-test-coverage.html
31+
- uses: actions/upload-artifact@v2
32+
with:
33+
path: go-test-coverage.html
34+
retention-days: 3

Diff for: .github/workflows/golangci-lint.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
tags:
5+
- v*
6+
branches-ignore:
7+
- 'doc-*'
8+
- 'doc/*'
9+
pull_request:
10+
branches:
11+
- main
12+
- master
13+
- release
14+
jobs:
15+
golangci:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/setup-go@v2
19+
with:
20+
go-version: ^1.17
21+
- uses: actions/checkout@v2
22+
- name: golangci-lint
23+
uses: golangci/golangci-lint-action@v2
24+
with:
25+
version: v1.42
26+
only-new-issues: true
27+
skip-go-installation: true
28+
args: >-
29+
--verbose
30+
--issues-exit-code=1
31+
--config=.ci/golangci-lint.yml

Diff for: LICENSE

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Copyright (c) 2021 Hirotsuna Mizuno - https://github.com/tunabay
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of
4+
this software and associated documentation files (the "Software"), to deal in
5+
the Software without restriction, including without limitation the rights to
6+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7+
the Software, and to permit persons to whom the Software is furnished to do so,
8+
subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Diff for: README.md

+55-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,55 @@
1-
# go-bitarray
1+
# go-bitarray
2+
3+
[![Go Reference](https://pkg.go.dev/badge/github.com/tunabay/go-bitarray.svg)](https://pkg.go.dev/github.com/tunabay/go-bitarray)
4+
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)
5+
6+
## Overview
7+
8+
Package bitarray provides data types and functions for manipulating bit arrays,
9+
aka bit strings, of arbitrary length.
10+
11+
This is designed to handle bit arrays across byte boundaries naturally, without
12+
error-prone bitwise operation code such as shifting, masking, and ORing. It may
13+
be useful when dealing with Huffman coding, raw packet of various protocols, and
14+
binary file formats, etc.
15+
16+
## Usage
17+
18+
```
19+
import (
20+
"fmt"
21+
"github.com/tunabay/go-bitarray"
22+
)
23+
24+
func main() {
25+
// Parse string representation
26+
ba1, err := bitarray.Parse("111000")
27+
if err != nil {
28+
panic(err)
29+
}
30+
fmt.Println(ba1) // 111000
31+
32+
// Slice and Repeat
33+
ba2 := ba1.Slice(2, 5).Repeat(2)
34+
fmt.Println(ba2) // 100100
35+
36+
// Append
37+
ba3 := ba2.Append(bitarray.MustParse("101011"))
38+
// alternative formatting
39+
fmt.Printf("% b\n", ba3) // 10010010 1011
40+
41+
// Extract bits from []byte across byte boundary
42+
buf := []byte{0xff, 0x00}
43+
ba4 := bitarray.NewFromBytes(buf, 4, 7)
44+
fmt.Println(ba4) // 1111000
45+
}
46+
```
47+
[Run in Go Playground](https://play.golang.org/)
48+
49+
## Documentation and examples:
50+
51+
- Read the [documentation](https://pkg.go.dev/github.com/tunabay/go-bitarray).
52+
53+
## License
54+
55+
go-bitarray is available under the MIT license. See the [LICENSE](LICENSE) file for more information.

Diff for: alignment.go

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) 2021 Hirotsuna Mizuno. All rights reserved.
2+
// Use of this source code is governed by the MIT license that can be found in
3+
// the LICENSE file.
4+
5+
package bitarray
6+
7+
// Alignment is used in some bitwise operations to specify whether the bits are
8+
// left-aligned or right-aligned. The zero value is AlignLeft.
9+
type Alignment bool
10+
11+
const (
12+
AlignLeft Alignment = false
13+
AlignRight Alignment = true
14+
)
15+
16+
// String returns the string representation of Alignment.
17+
func (a Alignment) String() string {
18+
if a == AlignLeft {
19+
return "align-left"
20+
}
21+
return "align-right"
22+
}

Diff for: alignment_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) 2021 Hirotsuna Mizuno. All rights reserved.
2+
// Use of this source code is governed by the MIT license that can be found in
3+
// the LICENSE file.
4+
5+
package bitarray_test
6+
7+
import (
8+
"testing"
9+
10+
"github.com/tunabay/go-bitarray"
11+
)
12+
13+
func TestAlignment_String(t *testing.T) {
14+
var zero bitarray.Alignment
15+
tcs := []struct {
16+
a bitarray.Alignment
17+
s string
18+
}{
19+
{zero, "align-left"},
20+
{bitarray.AlignLeft, "align-left"},
21+
{bitarray.AlignRight, "align-right"},
22+
}
23+
for _, tc := range tcs {
24+
s := tc.a.String()
25+
if s != tc.s {
26+
t.Errorf("unexpected result: got %q, want %q", s, tc.s)
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)