asciiset is an ASCII character bitset.
Bitsets are fast and memory-efficient data structures for storing and retrieving information using bitwise operations.
asciiset is an extension of the asciiSet data structure from the Go Standard library source code.
Possible applications include checking strings for prohibited ASCII characters, and counting unique ASCII characters in a string.
Spot any bugs? Report them here.
go get github.com/elliotwutingfeng/asciiset
make tests
# Alternatively, run tests without race detection
# Useful for systems that do not support the -race flag like windows/386
# See https://tip.golang.org/src/cmd/dist/test.go
make tests_without_race
make bench
CPU: AMD Ryzen 7 5800X
Time in nanoseconds (ns) | Lower is better
ASCIISet
Add() โ 891 ๐ฆ๐ฆ๐ฆ 11x faster
Contains() โ 580 ๐ฆ๐ฆ 28x faster
Remove() โ 1570 ๐ฆ๐ฆ๐ฆ๐ฆ 1.5x faster
Size() โ 313 ๐ฆ equivalent
Visit() โ 1421 ๐ฆ๐ฆ๐ฆ๐ฆ 3.5x faster
map[byte]struct{}
Add() โ 9850 ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ
Contains() โ16605 ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ
Remove() โ 2510 ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ
Size() โ 318 ๐ฅ
Visit() โ 5085 ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ
go test -bench . -benchmem -cpu 1
goos: linux
goarch: amd64
pkg: github.com/elliotwutingfeng/asciiset
cpu: AMD Ryzen 7 5800X 8-Core Processor
BenchmarkASCIISet/ASCIISet_Add() 1340958 891.8 ns/op 0 B/op 0 allocs/op
BenchmarkASCIISet/ASCIISet_Contains() 2058140 580.9 ns/op 0 B/op 0 allocs/op
BenchmarkASCIISet/ASCIISet_Remove() 762636 1570 ns/op 0 B/op 0 allocs/op
BenchmarkASCIISet/ASCIISet_Size() 3808866 313.2 ns/op 0 B/op 0 allocs/op
BenchmarkASCIISet/ASCIISet_Visit() 840808 1421 ns/op 0 B/op 0 allocs/op
BenchmarkMapSet/map_Add 122043 9850 ns/op 0 B/op 0 allocs/op
BenchmarkMapSet/map_Contains 72583 16605 ns/op 0 B/op 0 allocs/op
BenchmarkMapSet/map_Remove 451785 2510 ns/op 0 B/op 0 allocs/op
BenchmarkMapSet/map_Size 3789381 318.3 ns/op 0 B/op 0 allocs/op
BenchmarkMapSet/map_Visit 235515 5085 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/elliotwutingfeng/asciiset 14.438s