diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..43937e7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.html +*.out \ No newline at end of file diff --git a/README.md b/README.md index 7e8c6b3..2e56f1c 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,15 @@ Once you have [installed Go][golang-install], run this command to install the `bit` package: go get github.com/yourbasic/bit - + +### Testing + + go test -v -coverprofile coverage.out && go tool cover -html coverage.out -o coverage.html + +### Benchmarking + + go test -bench . -benchmem -cpu 1 + ### Documentation There is an online reference for the package at diff --git a/example_test.go b/example_test.go index 6381f6f..88b69b5 100644 --- a/example_test.go +++ b/example_test.go @@ -2,8 +2,9 @@ package bit_test import ( "fmt" - "github.com/yourbasic/bit" "math" + + "github.com/yourbasic/bit" ) // Create, combine, compare and print bit sets. @@ -25,7 +26,12 @@ func Example_basics() { if X.Equal(Y) { fmt.Println(X) } + + // Compute A ∩ B + Z := A.And(B) + fmt.Println(Z) // Output: {1..49 100..149 200} + // {0 50..99} } // Create the set of all primes less than n in O(n log log n) time. diff --git a/example_union_test.go b/example_union_test.go index 5de52f8..80743a9 100644 --- a/example_union_test.go +++ b/example_union_test.go @@ -2,6 +2,7 @@ package bit_test import ( "fmt" + "github.com/yourbasic/bit" ) diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..efd5d38 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/yourbasic/bit + +go 1.9 diff --git a/set.go b/set.go index 0abebcb..1a539c6 100644 --- a/set.go +++ b/set.go @@ -1,15 +1,16 @@ +//go:build !go1.9 // +build !go1.9 // Package bit provides a bit array implementation. // -// Bit set +// # Bit set // // A bit set, or bit array, is an efficient set data structure // that consists of an array of 64-bit words. Because it uses // bit-level parallelism, limits memory access, and efficiently uses // the data cache, a bit set often outperforms other data structures. // -// Tutorial +// # Tutorial // // The Basics example shows how to create, combine, compare and // print bit sets. @@ -19,7 +20,6 @@ // // Union is a more advanced example demonstrating how to build // an efficient variadic Union function using the SetOr method. -// package bit import ( diff --git a/set_1_10.go b/set_1_10.go index 0dfd3c6..af3189f 100644 --- a/set_1_10.go +++ b/set_1_10.go @@ -1,15 +1,16 @@ +//go:build go1.10 // +build go1.10 // Package bit provides a bit array implementation. // -// Bit set +// # Bit set // // A bit set, or bit array, is an efficient set data structure // that consists of an array of 64-bit words. Because it uses // bit-level parallelism, limits memory access, and efficiently uses // the data cache, a bit set often outperforms other data structures. // -// Tutorial +// # Tutorial // // The Basics example shows how to create, combine, compare and // print bit sets. @@ -19,7 +20,6 @@ // // Union is a more advanced example demonstrating how to build // an efficient variadic Union function using the SetOr method. -// package bit import ( diff --git a/set_1_9.go b/set_1_9.go index 70e5f07..797c41a 100644 --- a/set_1_9.go +++ b/set_1_9.go @@ -1,16 +1,16 @@ -// +build go1.9 -// +build !go1.10 +//go:build go1.9 && !go1.10 +// +build go1.9,!go1.10 // Package bit provides a bit array implementation. // -// Bit set +// # Bit set // // A bit set, or bit array, is an efficient set data structure // that consists of an array of 64-bit words. Because it uses // bit-level parallelism, limits memory access, and efficiently uses // the data cache, a bit set often outperforms other data structures. // -// Tutorial +// # Tutorial // // The Basics example shows how to create, combine, compare and // print bit sets. @@ -20,7 +20,6 @@ // // Union is a more advanced example demonstrating how to build // an efficient variadic Union function using the SetOr method. -// package bit import ( diff --git a/set_test.go b/set_test.go index 755909b..475eb88 100644 --- a/set_test.go +++ b/set_test.go @@ -299,11 +299,11 @@ func TestVisit(t *testing.T) { t.Errorf("%v.Visit(func(n int) { s.DeleteRange(0, n+1); s += Itoa(n) }) -> s=%q; want %q", s, res, x.res) } } - s := New(1, 2) + s := New(1, 2, 3) count := 0 aborted := s.Visit(func(n int) (skip bool) { count++ - if n == 1 { + if n == 2 { skip = true return } @@ -312,7 +312,7 @@ func TestVisit(t *testing.T) { if aborted == false { t.Errorf("Visit returned false when aborted.") } - if count > 1 { + if count > 2 { t.Errorf("Visit didn't abort.") } count = 0 @@ -323,7 +323,7 @@ func TestVisit(t *testing.T) { if aborted == true { t.Errorf("Visit returned true when not aborted.") } - if count != 2 { + if count != 3 { t.Errorf("Visit aborted.") } }