base62.go19
1:9package-comments
base62.go:1:9
package ksuid17:2no-package-var
base62.go:17:2
var ( errShortBuffer = errors.New("the output buffer is too small to hold to decoded value"))22:2single-case-switch
base62.go:22:2
func base62Value(digit byte) byte { switch { case digit >= '0' && digit <= '9':60:16redundant-conversion
base62.go:60:16
quotient := bq[:0] remainder := uint64(0)63:25redundant-conversion
base62.go:63:25
for _, c := range bp { value := uint64(c) + uint64(remainder)*srcBase digit := value / dstBase67:7optimize-operands-order
base62.go:67:7
if len(quotient) != 0 || digit != 0 { quotient = append(quotient, uint32(digit))75:3modifies-parameter
base62.go:75:3
n-- dst[n] = base62Characters[remainder] bp = quotient89:2modifies-parameter
base62.go:89:2
func fastAppendEncodeBase62(dst []byte, src []byte) []byte { dst = reserve(dst, stringEncodedLength) n := len(dst)102:6cognitive-complexity
base62.go:102:6
// Any unused bytes in dst will be set to zero.func fastDecodeBase62(dst []byte, src []byte) error { const srcBase = 62148:16redundant-conversion
base62.go:148:16
quotient := bq[:0] remainder := uint64(0)151:25redundant-conversion
base62.go:151:25
for _, c := range bp { value := uint64(c) + uint64(remainder)*srcBase digit := value / dstBase155:7optimize-operands-order
base62.go:155:7
if len(quotient) != 0 || digit != 0 { quotient = append(quotient, byte(digit))164:3modifies-parameter
base62.go:164:3
dst[n-4] = byte(remainder >> 24) dst[n-3] = byte(remainder >> 16)165:3modifies-parameter
base62.go:165:3
dst[n-4] = byte(remainder >> 24) dst[n-3] = byte(remainder >> 16) dst[n-2] = byte(remainder >> 8)166:3modifies-parameter
base62.go:166:3
dst[n-3] = byte(remainder >> 16) dst[n-2] = byte(remainder >> 8) dst[n-1] = byte(remainder)167:3modifies-parameter
base62.go:167:3
dst[n-2] = byte(remainder >> 8) dst[n-1] = byte(remainder) n -= 4179:2modifies-parameter
base62.go:179:2
func fastAppendDecodeBase62(dst []byte, src []byte) []byte { dst = reserve(dst, byteLength) n := len(dst)181:2discarded-error-result
base62.go:181:2
n := len(dst) fastDecodeBase62(dst[n:n+byteLength], src) return dst[:n+byteLength]198:3modifies-parameter
base62.go:198:3
copy(b, dst) dst = b }base62_test.go22
1:1format
base62_test.go:1:1
package ksuid- Fix (safe): run `strider fmt base62_test.go`
10:6test-parallelism
base62_test.go:10:6
func TestBase10ToBase62AndBack(t *testing.T) { number := []byte{1, 2, 3, 4}20:6test-parallelism
base62_test.go:20:6
func TestBase256ToBase62AndBack(t *testing.T) { number := []byte{255, 254, 253, 251}30:6test-parallelism
base62_test.go:30:6
func TestEncodeAndDecodeBase62(t *testing.T) { helloWorld := []byte("hello world")41:20add-constant
base62_test.go:41:20
if bytes.Compare(helloWorld, decoded) != 0 { t.Fatal(decoded, " != ", helloWorld) }45:6test-parallelism
base62_test.go:45:6
func TestLexographicOrdering(t *testing.T) { unsortedStrings := make([]string, 256)65:6test-parallelism
base62_test.go:65:6
func TestBase62Value(t *testing.T) { s := base62Characters79:6test-parallelism
base62_test.go:79:6
func TestFastAppendEncodeBase62(t *testing.T) { for i := 0; i != 1000; i++ {98:6test-parallelism
base62_test.go:98:6
func TestFastAppendDecodeBase62(t *testing.T) { for i := 0; i != 1000; i++ {108:10add-constant
base62_test.go:108:10
t.Error("bad binary representation of", string(b0)) t.Log("<<<", b1) t.Log(">>>", b2)109:10add-constant
base62_test.go:109:10
t.Log("<<<", b1) t.Log(">>>", b2) }169:9ineffective-bitwise-zero
base62_test.go:169:9
acc := int(bs[i]) + remainder*inBase d := acc/outBase | 0 remainder = acc % outBase172:7optimize-operands-order
base62_test.go:172:7
if len(quotient) > 0 || d > 0 { quotient = append(quotient, byte(d))179:3modifies-parameter
base62_test.go:179:3
// returned by the function. dst = append(dst, byte(remainder)) bs = quotient193:2modifies-parameter
base62_test.go:193:2
off := len(dst) dst = appendBase2Base(dst, src, 256, 62) for i, c := range dst[off:] {195:3modifies-parameter
base62_test.go:195:3
for i, c := range dst[off:] { dst[off+i] = base62Characters[c] }209:3modifies-parameter
base62_test.go:209:3
// O(1)... technically. Has better real-world perf than a map src[i] = byte(strings.IndexByte(base62Characters, b)) }226:3modifies-parameter
base62_test.go:226:3
for i < j { b[i], b[j] = b[j], b[i] i++226:9modifies-parameter
base62_test.go:226:9
for i < j { b[i], b[j] = b[j], b[i] i++233:5modifies-parameter
base62_test.go:233:5
func leftpad(b []byte, c byte, n int) []byte { if n -= len(b); n > 0 { for i := 0; i != n; i++ {235:4modifies-parameter
base62_test.go:235:4
for i := 0; i != n; i++ { b = append(b, c) }241:4modifies-parameter
base62_test.go:241:4
for i := 0; i != n; i++ { b[i] = c }cmd/ksuid/main.go25
1:1format
cmd/ksuid/main.go:1:1
package main- Fix (safe): run `strider fmt cmd/ksuid/main.go`
1:9package-comments
cmd/ksuid/main.go:1:9
package main18:2no-package-var
cmd/ksuid/main.go:18:2
var ( count int format string19:2no-package-var
cmd/ksuid/main.go:19:2
count int format string tpltxt string20:2no-package-var
cmd/ksuid/main.go:20:2
format string tpltxt string verbose bool21:2no-package-var
cmd/ksuid/main.go:21:2
tpltxt string verbose bool)24:6no-init
cmd/ksuid/main.go:24:6
func init() { flag.IntVar(&count, "n", 1, "Number of KSUIDs to generate when called with no other arguments.")31:6cognitive-complexity
cmd/ksuid/main.go:31:6
func main() { flag.Parse()31:6cyclomatic-complexity
cmd/ksuid/main.go:31:6
func main() { flag.Parse()35:6redefines-builtin-id
cmd/ksuid/main.go:35:6
var print func(ksuid.KSUID) switch format {36:2single-case-switch
cmd/ksuid/main.go:36:2
var print func(ksuid.KSUID) switch format { case "string":52:3discarded-error-result
cmd/ksuid/main.go:52:3
default: fmt.Println("Bad formatting function:", format) os.Exit(1)62:6slice-preallocation
cmd/ksuid/main.go:62:6
var ids []ksuid.KSUID for _, arg := range args {66:4discarded-error-result
cmd/ksuid/main.go:66:4
if err != nil { fmt.Printf("Error when parsing %q: %s\n\n", arg, err) flag.PrintDefaults()75:4discarded-error-result
cmd/ksuid/main.go:75:4
if verbose { fmt.Printf("%s: ", id) }77:3use-fmt-print
cmd/ksuid/main.go:77:3
} print(id) }82:2discarded-error-result
cmd/ksuid/main.go:82:2
func printString(id ksuid.KSUID) { fmt.Println(id.String())}99:2discarded-error-result
cmd/ksuid/main.go:99:2
` fmt.Printf(inspectFormat, id.String(),109:2discarded-error-result
cmd/ksuid/main.go:109:2
func printTime(id ksuid.KSUID) { fmt.Println(id.Time())}113:2discarded-error-result
cmd/ksuid/main.go:113:2
func printTimestamp(id ksuid.KSUID) { fmt.Println(id.Timestamp())}117:2discarded-error-result
cmd/ksuid/main.go:117:2
func printPayload(id ksuid.KSUID) { os.Stdout.Write(id.Payload())}121:2discarded-error-result
cmd/ksuid/main.go:121:2
func printRaw(id ksuid.KSUID) { os.Stdout.Write(id.Bytes())}127:2discarded-error-result
cmd/ksuid/main.go:127:2
t := template.Must(template.New("").Parse(tpltxt)) t.Execute(b, struct { String string127:15nested-structs
cmd/ksuid/main.go:127:15
t := template.Must(template.New("").Parse(tpltxt)) t.Execute(b, struct { String string141:2discarded-error-result
cmd/ksuid/main.go:141:2
b.WriteByte('\n') io.Copy(os.Stdout, b)}ksuid.go76
1:1format
ksuid.go:1:1
package ksuid- Fix (safe): run `strider fmt ksuid.go`
1:9package-comments
ksuid.go:1:9
package ksuid40:1doc-comment-period
ksuid.go:40:1
// KSUIDs are 20 bytes:// 00-03 byte: uint32 BE UTC timestamp with custom epoch43:6exported-declaration-comment
ksuid.go:43:6
// 04-19 byte: random "payload"type KSUID [byteLength]byte45:1top-level-declaration-order
ksuid.go:45:1
var ( rander = rand.Reader46:2no-package-var
ksuid.go:46:2
var ( rander = rand.Reader randMutex = sync.Mutex{}47:2no-package-var
ksuid.go:47:2
rander = rand.Reader randMutex = sync.Mutex{} randBuffer = [payloadLengthInBytes]byte{}48:2no-package-var
ksuid.go:48:2
randMutex = sync.Mutex{} randBuffer = [payloadLengthInBytes]byte{}50:2no-package-var
ksuid.go:50:2
errSize = fmt.Errorf("Valid KSUIDs are %v bytes", byteLength) errStrSize = fmt.Errorf("Valid encoded KSUIDs are %v characters", stringEncodedLength)50:30error-strings
ksuid.go:50:30
errSize = fmt.Errorf("Valid KSUIDs are %v bytes", byteLength) errStrSize = fmt.Errorf("Valid encoded KSUIDs are %v characters", stringEncodedLength)51:2no-package-var
ksuid.go:51:2
errSize = fmt.Errorf("Valid KSUIDs are %v bytes", byteLength) errStrSize = fmt.Errorf("Valid encoded KSUIDs are %v characters", stringEncodedLength) errStrValue = fmt.Errorf("Valid encoded KSUIDs are bounded by %s and %s", minStringEncoded, maxStringEncoded)51:30error-strings
ksuid.go:51:30
errSize = fmt.Errorf("Valid KSUIDs are %v bytes", byteLength) errStrSize = fmt.Errorf("Valid encoded KSUIDs are %v characters", stringEncodedLength) errStrValue = fmt.Errorf("Valid encoded KSUIDs are bounded by %s and %s", minStringEncoded, maxStringEncoded)52:2no-package-var
ksuid.go:52:2
errStrSize = fmt.Errorf("Valid encoded KSUIDs are %v characters", stringEncodedLength) errStrValue = fmt.Errorf("Valid encoded KSUIDs are bounded by %s and %s", minStringEncoded, maxStringEncoded) errPayloadSize = fmt.Errorf("Valid KSUID payloads are %v bytes", payloadLengthInBytes)52:30error-strings
ksuid.go:52:30
errStrSize = fmt.Errorf("Valid encoded KSUIDs are %v characters", stringEncodedLength) errStrValue = fmt.Errorf("Valid encoded KSUIDs are bounded by %s and %s", minStringEncoded, maxStringEncoded) errPayloadSize = fmt.Errorf("Valid KSUID payloads are %v bytes", payloadLengthInBytes)53:2no-package-var
ksuid.go:53:2
errStrValue = fmt.Errorf("Valid encoded KSUIDs are bounded by %s and %s", minStringEncoded, maxStringEncoded) errPayloadSize = fmt.Errorf("Valid KSUID payloads are %v bytes", payloadLengthInBytes)53:30error-strings
ksuid.go:53:30
errStrValue = fmt.Errorf("Valid encoded KSUIDs are bounded by %s and %s", minStringEncoded, maxStringEncoded) errPayloadSize = fmt.Errorf("Valid KSUID payloads are %v bytes", payloadLengthInBytes)55:2doc-comment-period
ksuid.go:55:2
// Represents a completely empty (invalid) KSUID Nil KSUID56:2exported-declaration-comment
ksuid.go:56:2
// Represents a completely empty (invalid) KSUID Nil KSUID // Represents the highest value a KSUID can have56:2no-package-var
ksuid.go:56:2
// Represents a completely empty (invalid) KSUID Nil KSUID // Represents the highest value a KSUID can have57:2doc-comment-period
ksuid.go:57:2
Nil KSUID // Represents the highest value a KSUID can have Max = KSUID{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}58:2exported-declaration-comment
ksuid.go:58:2
// Represents the highest value a KSUID can have Max = KSUID{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255})58:2no-package-var
ksuid.go:58:2
// Represents the highest value a KSUID can have Max = KSUID{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255})63:16exported-declaration-comment
ksuid.go:63:16
// potentially larger memory area.func (i KSUID) Append(b []byte) []byte { return fastAppendEncodeBase62(b, i[:])67:1doc-comment-period
ksuid.go:67:1
// The timestamp portion of the ID as a Time objectfunc (i KSUID) Time() time.Time {68:16exported-declaration-comment
ksuid.go:68:16
// The timestamp portion of the ID as a Time objectfunc (i KSUID) Time() time.Time { return correctedUTCTimestampToTime(i.Timestamp())74:16exported-declaration-comment
ksuid.go:74:16
// for KSUID's special epoch.func (i KSUID) Timestamp() uint32 { return binary.BigEndian.Uint32(i[:timestampLengthInBytes])78:1doc-comment-period
ksuid.go:78:1
// The 16-byte random payload without the timestampfunc (i KSUID) Payload() []byte {79:16exported-declaration-comment
ksuid.go:79:16
// The 16-byte random payload without the timestampfunc (i KSUID) Payload() []byte { return i[timestampLengthInBytes:]83:1doc-comment-period
ksuid.go:83:1
// String-encoded representation that can be passed through Parse()func (i KSUID) String() string {88:1doc-comment-period
ksuid.go:88:1
// Raw byte representation of KSUIDfunc (i KSUID) Bytes() []byte {89:16exported-declaration-comment
ksuid.go:89:16
// Raw byte representation of KSUIDfunc (i KSUID) Bytes() []byte { // Safe because this is by-value94:1doc-comment-period
ksuid.go:94:1
// IsNil returns true if this is a "nil" KSUIDfunc (i KSUID) IsNil() bool {101:16exported-declaration-comment
ksuid.go:101:16
// part of of the command line options of a program.func (i KSUID) Get() interface{} { return i101:22use-any
ksuid.go:101:22
// part of of the command line options of a program.func (i KSUID) Get() interface{} { return i107:17exported-declaration-comment
ksuid.go:107:17
// part of of the command line options of a program.func (i *KSUID) Set(s string) error { return i.UnmarshalText([]byte(s))111:16exported-declaration-comment
ksuid.go:111:16
func (i KSUID) MarshalText() ([]byte, error) { return []byte(i.String()), nil115:16exported-declaration-comment
ksuid.go:115:16
func (i KSUID) MarshalBinary() ([]byte, error) { return i.Bytes(), nil119:7marshal-receiver
ksuid.go:119:7
func (i *KSUID) UnmarshalText(b []byte) error { id, err := Parse(string(b))119:17exported-declaration-comment
ksuid.go:119:17
func (i *KSUID) UnmarshalText(b []byte) error { id, err := Parse(string(b))128:7marshal-receiver
ksuid.go:128:7
func (i *KSUID) UnmarshalBinary(b []byte) error { id, err := FromBytes(b)128:17exported-declaration-comment
ksuid.go:128:17
func (i *KSUID) UnmarshalBinary(b []byte) error { id, err := FromBytes(b)139:16exported-declaration-comment
ksuid.go:139:16
// directly use the KSUID as parameter to a SQL query.func (i KSUID) Value() (driver.Value, error) { if i.IsNil() {141:3nil-value-with-nil-error
ksuid.go:141:3
if i.IsNil() { return nil, nil }149:17exported-declaration-comment
ksuid.go:149:17
// another type will return an error.func (i *KSUID) Scan(src interface{}) error { switch v := src.(type) {149:26use-any
ksuid.go:149:26
// another type will return an error.func (i *KSUID) Scan(src interface{}) error { switch v := src.(type) {158:21error-strings
ksuid.go:158:21
default: return fmt.Errorf("Scan: unable to scan type %T into KSUID", v) }162:17confusing-naming
ksuid.go:162:17
func (i *KSUID) scan(b []byte) error { switch len(b) {163:2single-case-switch
ksuid.go:163:2
func (i *KSUID) scan(b []byte) error { switch len(b) { case 0:176:1doc-comment-period
ksuid.go:176:1
// Parse decodes a string-encoded representation of a KSUID objectfunc Parse(s string) (KSUID, error) {196:6exported-declaration-comment
ksuid.go:196:6
// Same behavior as Parse, but returns a Nil KSUID on error.func ParseOrNil(s string) KSUID { ksuid, err := Parse(s)214:6exported-declaration-comment
ksuid.go:214:6
// can't be read, it will panic.func New() KSUID { ksuid, err := NewRandom()222:1doc-comment-period
ksuid.go:222:1
// Generates a new KSUIDfunc NewRandom() (ksuid KSUID, err error) {223:6exported-declaration-comment
ksuid.go:223:6
// Generates a new KSUIDfunc NewRandom() (ksuid KSUID, err error) { return NewRandomWithTime(time.Now())227:6exported-declaration-comment
ksuid.go:227:6
func NewRandomWithTime(t time.Time) (ksuid KSUID, err error) { // Go's default random number generators are not safe for concurrent use by240:3no-naked-return
ksuid.go:240:3
ksuid = Nil // don't leak random bytes on error return }245:2no-naked-return
ksuid.go:245:2
binary.BigEndian.PutUint32(ksuid[:timestampLengthInBytes], ts) return}248:1doc-comment-period
ksuid.go:248:1
// Constructs a KSUID from constituent partsfunc FromParts(t time.Time, payload []byte) (KSUID, error) {249:6exported-declaration-comment
ksuid.go:249:6
// Constructs a KSUID from constituent partsfunc FromParts(t time.Time, payload []byte) (KSUID, error) { if len(payload) != payloadLengthInBytes {266:6exported-declaration-comment
ksuid.go:266:6
// Same behavior as FromParts, but returns a Nil KSUID on error.func FromPartsOrNil(t time.Time, payload []byte) KSUID { ksuid, err := FromParts(t, payload)274:1doc-comment-period
ksuid.go:274:1
// Constructs a KSUID from a 20-byte binary representationfunc FromBytes(b []byte) (KSUID, error) {275:6exported-declaration-comment
ksuid.go:275:6
// Constructs a KSUID from a 20-byte binary representationfunc FromBytes(b []byte) (KSUID, error) { var ksuid KSUID288:6exported-declaration-comment
ksuid.go:288:6
// Same behavior as FromBytes, but returns a Nil KSUID on error.func FromBytesOrNil(b []byte) KSUID { ksuid, err := FromBytes(b)300:6exported-declaration-comment
ksuid.go:300:6
// on ordering.func SetRand(r io.Reader) { if r == nil {308:1doc-comment-period
ksuid.go:308:1
// Implements comparison for KSUID typefunc Compare(a, b KSUID) int {309:6exported-declaration-comment
ksuid.go:309:6
// Implements comparison for KSUID typefunc Compare(a, b KSUID) int { return bytes.Compare(a[:], b[:])313:1doc-comment-period
ksuid.go:313:1
// Sorts the given slice of KSUIDsfunc Sort(ids []KSUID) {318:1doc-comment-period
ksuid.go:318:1
// IsSorted checks whether a slice of KSUIDs is sortedfunc IsSorted(ids []KSUID) bool {321:3redefines-builtin-id
ksuid.go:321:3
if len(ids) != 0 { min := ids[0] for _, id := range ids[1:] {332:6cognitive-complexity
ksuid.go:332:6
func quickSort(a []KSUID, lo int, hi int) { if lo < hi {340:5modifies-parameter
ksuid.go:340:5
i++ a[i], a[j] = a[j], a[i] }340:11modifies-parameter
ksuid.go:340:11
i++ a[i], a[j] = a[j], a[i] }346:4modifies-parameter
ksuid.go:346:4
if bytes.Compare(a[hi][:], a[i][:]) < 0 { a[i], a[hi] = a[hi], a[i] }346:10modifies-parameter
ksuid.go:346:10
if bytes.Compare(a[hi][:], a[i][:]) < 0 { a[i], a[hi] = a[hi], a[i] }355:7receiver-naming
ksuid.go:355:7
// Next returns the next KSUID after id.func (id KSUID) Next() KSUID { zero := makeUint128(0, 0)370:7receiver-naming
ksuid.go:370:7
// Prev returns the previoud KSUID before id.func (id KSUID) Prev() KSUID { max := makeUint128(math.MaxUint64, math.MaxUint64)371:2redefines-builtin-id
ksuid.go:371:2
func (id KSUID) Prev() KSUID { max := makeUint128(math.MaxUint64, math.MaxUint64)ksuid_test.go38
1:1format
ksuid_test.go:1:1
package ksuid- Fix (safe): run `strider fmt ksuid_test.go`
14:6test-parallelism
ksuid_test.go:14:6
func TestConstructionTimestamp(t *testing.T) { x := New()19:5time-value-equality
ksuid_test.go:19:5
if xTime != nowTime { t.Fatal(xTime, "!=", nowTime)24:6test-parallelism
ksuid_test.go:24:6
func TestNil(t *testing.T) { if !Nil.IsNil() {29:10discarded-error-result
ksuid_test.go:29:10
x, _ := FromBytes(make([]byte, byteLength)) if !x.IsNil() {35:6test-parallelism
ksuid_test.go:35:6
func TestEncoding(t *testing.T) { x, _ := FromBytes(make([]byte, byteLength))36:10discarded-error-result
ksuid_test.go:36:10
func TestEncoding(t *testing.T) { x, _ := FromBytes(make([]byte, byteLength)) if !x.IsNil() {49:6test-parallelism
ksuid_test.go:49:6
func TestPadding(t *testing.T) { b := make([]byte, byteLength)55:10discarded-error-result
ksuid_test.go:55:10
x, _ := FromBytes(b) xEncoded := x.String()64:6test-parallelism
ksuid_test.go:64:6
func TestParse(t *testing.T) { _, err := Parse("123")92:11add-constant
ksuid_test.go:92:11
if err != nil { t.Fatal("Unexpected error", err) }100:6test-parallelism
ksuid_test.go:100:6
func TestIssue25(t *testing.T) { // https://github.com/segmentio/ksuid/issues/25113:6test-parallelism
ksuid_test.go:113:6
func TestEncodeAndDecode(t *testing.T) { x := New()125:6test-parallelism
ksuid_test.go:125:6
func TestMarshalText(t *testing.T) { var id1 = New()144:6test-parallelism
ksuid_test.go:144:6
func TestMarshalBinary(t *testing.T) { var id1 = New()153:16add-constant
ksuid_test.go:153:16
if id1 != id2 { t.Fatal(id1, "!=", id2) }163:6test-parallelism
ksuid_test.go:163:6
func TestMashalJSON(t *testing.T) { var id1 = New()176:6test-parallelism
ksuid_test.go:176:6
func TestFlag(t *testing.T) { var id1 = New()192:6test-parallelism
ksuid_test.go:192:6
func TestSqlValuer(t *testing.T) { id, _ := Parse(maxStringEncoded)193:11discarded-error-result
ksuid_test.go:193:11
func TestSqlValuer(t *testing.T) { id, _ := Parse(maxStringEncoded)204:6test-parallelism
ksuid_test.go:204:6
func TestSqlValuerNilValue(t *testing.T) { if v, err := Nil.Value(); err != nil {212:6test-parallelism
ksuid_test.go:212:6
func TestSqlScanner(t *testing.T) { id1 := New()216:13nested-structs
ksuid_test.go:216:13
tests := []struct { ksuid KSUID218:9use-any
ksuid_test.go:218:9
ksuid KSUID value interface{} }{226:40range-value-capture
ksuid_test.go:226:40
for _, test := range tests { t.Run(fmt.Sprintf("%T", test.value), func(t *testing.T) { var id KSUID226:40test-parallelism
ksuid_test.go:226:40
for _, test := range tests { t.Run(fmt.Sprintf("%T", test.value), func(t *testing.T) { var id KSUID242:6test-parallelism
ksuid_test.go:242:6
func TestAppend(t *testing.T) { for _, repr := range []string{"0pN1Own7255s7jwpwy495bAZeEa", "aWgEPTl1tmebfsQzFP4bxwgy80V"} {244:11discarded-error-result
ksuid_test.go:244:11
for _, repr := range []string{"0pN1Own7255s7jwpwy495bAZeEa", "aWgEPTl1tmebfsQzFP4bxwgy80V"} { k, _ := Parse(repr) a := make([]byte, 0, stringEncodedLength)256:6test-parallelism
ksuid_test.go:256:6
func TestSort(t *testing.T) { ids1 := [11]KSUID{}265:2use-slices-sort
ksuid_test.go:265:2
ids2 = ids1 sort.Slice(ids2[:], func(i, j int) bool { return Compare(ids2[i], ids2[j]) < 0282:6test-parallelism
ksuid_test.go:282:6
func TestPrevNext(t *testing.T) { tests := []struct {283:13nested-structs
ksuid_test.go:283:13
func TestPrevNext(t *testing.T) { tests := []struct { id KSUID301:27range-value-capture
ksuid_test.go:301:27
for _, test := range tests { t.Run(test.id.String(), func(t *testing.T) { testPrevNext(t, test.id, test.prev, test.next)301:27test-parallelism
ksuid_test.go:301:27
for _, test := range tests { t.Run(test.id.String(), func(t *testing.T) { testPrevNext(t, test.id, test.prev, test.next)307:6test-parallelism
ksuid_test.go:307:6
func TestGetTimestamp(t *testing.T) { nowTime := time.Now()309:10discarded-error-result
ksuid_test.go:309:10
nowTime := time.Now() x, _ := NewRandomWithTime(nowTime) xTime := int64(x.Timestamp())317:6confusing-naming
ksuid_test.go:317:6
func testPrevNext(t *testing.T, id, prev, next KSUID) { id1 := id.Prev()349:3discarded-error-result
ksuid_test.go:349:3
for i := 0; i != b.N; i++ { Parse(maxStringEncoded) }rand.go11
1:1format
rand.go:1:1
package ksuid- Fix (safe): run `strider fmt rand.go`
1:9package-comments
rand.go:1:9
package ksuid4:2import-alias-naming
rand.go:4:2
import ( cryptoRand "crypto/rand" "encoding/binary"14:5exported-declaration-comment
rand.go:14:5
// cryptographically secure KSUIDs and are generating a lot of them.var FastRander = newRBG()14:5no-package-var
rand.go:14:5
// cryptographically secure KSUIDs and are generating a lot of them.var FastRander = newRBG()28:3no-naked-return
rand.go:28:3
if seed, err = readCryptoRandomSeed(); err != nil { return }31:52unchecked-type-assertion
rand.go:31:52
r = &randSourceReader{source: rand.NewSource(seed).(rand.Source64)} return32:2no-naked-return
rand.go:32:2
r = &randSourceReader{source: rand.NewSource(seed).(rand.Source64)} return}39:3no-naked-return
rand.go:39:3
if _, err = io.ReadFull(cryptoRand.Reader, b[:]); err != nil { return }43:2no-naked-return
rand.go:43:2
seed = int64(binary.LittleEndian.Uint64(b[:])) return}46:1top-level-declaration-order
rand.go:46:1
type randSourceReader struct { source rand.Source64sequence.go5
1:9package-comments
sequence.go:1:9
package ksuid31:22exported-declaration-comment
sequence.go:31:22
// sequence has been exhausted.func (seq *Sequence) Next() (KSUID, error) { id := seq.Seed // copy44:22exported-declaration-comment
sequence.go:44:22
// returned min value is equal to the max.func (seq *Sequence) Bounds() (min KSUID, max KSUID) { count := seq.count44:32redefines-builtin-id
sequence.go:44:32
// returned min value is equal to the max.func (seq *Sequence) Bounds() (min KSUID, max KSUID) { count := seq.count44:43redefines-builtin-id
sequence.go:44:43
// returned min value is equal to the max.func (seq *Sequence) Bounds() (min KSUID, max KSUID) { count := seq.countsequence_test.go7
1:1format
sequence_test.go:1:1
package ksuid- Fix (safe): run `strider fmt sequence_test.go`
9:6cognitive-complexity
sequence_test.go:9:6
func TestSequence(t *testing.T) { seq := Sequence{Seed: New()}9:6test-parallelism
sequence_test.go:9:6
func TestSequence(t *testing.T) { seq := Sequence{Seed: New()}12:5redefines-builtin-id
sequence_test.go:12:5
if min, max := seq.Bounds(); min == max { t.Error("min and max of KSUID range must differ when no ids have been generated")12:10redefines-builtin-id
sequence_test.go:12:10
if min, max := seq.Bounds(); min == max { t.Error("min and max of KSUID range must differ when no ids have been generated")30:5redefines-builtin-id
sequence_test.go:30:5
if min, max := seq.Bounds(); min != max { t.Error("after all KSUIDs were generated the min and max must be equal")30:10redefines-builtin-id
sequence_test.go:30:10
if min, max := seq.Bounds(); min != max { t.Error("after all KSUIDs were generated the min and max must be equal")set.go28
1:1format
set.go:1:1
package ksuid- Fix (safe): run `strider fmt set.go`
1:9package-comments
set.go:1:9
package ksuid30:26exported-declaration-comment
set.go:30:26
// the set.func (set CompressedSet) GoString() string { b := bytes.Buffer{}54:6exported-declaration-comment
set.go:54:6
// as arguments.func Compress(ids ...KSUID) CompressedSet { c := 1 + byteLength + (len(ids) / 5)67:6cognitive-complexity
set.go:67:6
// to waste.func AppendCompressed(set []byte, ids ...KSUID) CompressedSet { if len(ids) != 0 {67:6exported-declaration-comment
set.go:67:6
// to waste.func AppendCompressed(set []byte, ids ...KSUID) CompressedSet { if len(ids) != 0 {76:3modifies-parameter
set.go:76:3
// point for all deltas. set = append(set, byte(rawKSUID)) set = append(set, ids[0][:]...)76:21redundant-conversion
set.go:76:21
// point for all deltas. set = append(set, byte(rawKSUID)) set = append(set, ids[0][:]...)77:3modifies-parameter
set.go:77:3
set = append(set, byte(rawKSUID)) set = append(set, ids[0][:]...)97:5modifies-parameter
set.go:97:5
set = append(set, timeDelta|byte(n)) set = appendVarint32(set, d, n)98:5modifies-parameter
set.go:98:5
set = append(set, timeDelta|byte(n)) set = appendVarint32(set, d, n) set = append(set, id[timestampLengthInBytes:]...)99:5modifies-parameter
set.go:99:5
set = appendVarint32(set, d, n) set = append(set, id[timestampLengthInBytes:]...)108:6modifies-parameter
set.go:108:6
set = append(set, payloadDelta|byte(n)) set = appendVarint128(set, d, n)109:6modifies-parameter
set.go:109:6
set = append(set, payloadDelta|byte(n)) set = appendVarint128(set, d, n) } else {115:6modifies-parameter
set.go:115:6
set = append(set, payloadRange|byte(n)) set = appendVarint64(set, m, n)116:6modifies-parameter
set.go:116:6
set = append(set, payloadRange|byte(n)) set = appendVarint64(set, m, n)131:6cognitive-complexity
set.go:131:6
func rangeLength(ids []KSUID, timestamp uint32, lastKSUID KSUID, lastValue uint128) (length int, count int) { one := makeUint128(0, 1)143:4no-naked-return
set.go:143:4
count = i return }150:4no-naked-return
set.go:150:4
count = i return }153:3modifies-parameter
set.go:153:3
lastKSUID = id lastValue = v154:3modifies-parameter
set.go:154:3
lastKSUID = id lastValue = v length++159:2no-naked-return
set.go:159:2
count = len(ids) return}205:2single-case-switch
set.go:205:2
func varintLength64(v uint64) int { switch { case (v & 0xFFFFFFFFFFFFFF00) == 0:226:2single-case-switch
set.go:226:2
func varintLength32(v uint32) int { switch { case (v & 0xFFFFFF00) == 0:238:1top-level-declaration-order
set.go:238:1
const ( rawKSUID = 0257:6exported-declaration-comment
set.go:257:6
// goroutines.type CompressedSetIter struct { // KSUID is modified by calls to the Next method to hold the KSUID loaded272:30exported-declaration-comment
set.go:272:30
// or false if the iterator as reached the end of the set it was created from.func (it *CompressedSetIter) Next() bool { if it.seqlength != 0 {292:2single-case-switch
set.go:292:2
switch tag { case rawKSUID:set_test.go27
1:1format
set_test.go:1:1
package ksuid- Fix (safe): run `strider fmt set_test.go`
8:6test-parallelism
set_test.go:8:6
func TestCompressedSet(t *testing.T) { tests := []struct {9:13nested-structs
set_test.go:9:13
func TestCompressedSet(t *testing.T) { tests := []struct { scenario string61:12discarded-error-result
set_test.go:61:12
func testCompressedSetString(t *testing.T) { id1, _ := Parse("0uHjRkQoL2JKAQIULPdqqb5fOkk") id2, _ := Parse("0uHjRvkOG5CbtoXW5oCEp3L2xBu")62:12discarded-error-result
set_test.go:62:12
id1, _ := Parse("0uHjRkQoL2JKAQIULPdqqb5fOkk") id2, _ := Parse("0uHjRvkOG5CbtoXW5oCEp3L2xBu") id3, _ := Parse("0uHjSJ4Pe5606kT2XWixK6dirlo")63:12discarded-error-result
set_test.go:63:12
id2, _ := Parse("0uHjRvkOG5CbtoXW5oCEp3L2xBu") id3, _ := Parse("0uHjSJ4Pe5606kT2XWixK6dirlo")73:12discarded-error-result
set_test.go:73:12
func testCompressedSetGoString(t *testing.T) { id1, _ := Parse("0uHjRkQoL2JKAQIULPdqqb5fOkk") id2, _ := Parse("0uHjRvkOG5CbtoXW5oCEp3L2xBu")74:12discarded-error-result
set_test.go:74:12
id1, _ := Parse("0uHjRkQoL2JKAQIULPdqqb5fOkk") id2, _ := Parse("0uHjRvkOG5CbtoXW5oCEp3L2xBu") id3, _ := Parse("0uHjSJ4Pe5606kT2XWixK6dirlo")75:12discarded-error-result
set_test.go:75:12
id2, _ := Parse("0uHjRvkOG5CbtoXW5oCEp3L2xBu") id3, _ := Parse("0uHjSJ4Pe5606kT2XWixK6dirlo")84:6cognitive-complexity
set_test.go:84:6
func testCompressedSetSparse(t *testing.T) { now := time.Now()94:18discarded-error-result
set_test.go:94:18
for i := range ksuids { ksuids[i], _ = NewRandomWithTime(times[i%len(times)]) }113:6cognitive-complexity
set_test.go:113:6
func testCompressedSetPacked(t *testing.T) { sequences := [10]Sequence{}121:18discarded-error-result
set_test.go:121:18
for i := range ksuids { ksuids[i], _ = sequences[i%len(sequences)].Next() }140:6cognitive-complexity
set_test.go:140:6
func testCompressedSetMixed(t *testing.T) { now := time.Now()150:14discarded-error-result
set_test.go:150:14
for i := range sequences { seed, _ := NewRandomWithTime(times[i%len(times)]) sequences[i] = Sequence{Seed: seed}156:18discarded-error-result
set_test.go:156:18
for i := range ksuids { ksuids[i], _ = sequences[i%len(sequences)].Next() }163:12add-constant
set_test.go:163:12
if i >= len(ksuids) { t.Error("too many KSUIDs were produced by the set iterator") break167:13add-constant
set_test.go:167:13
if ksuids[i] != it.KSUID { t.Errorf("bad KSUID at index %d: expected %s but found %s", i, ksuids[i], it.KSUID) }175:6cognitive-complexity
set_test.go:175:6
func testCompressedSetDuplicates(t *testing.T) { sequence := Sequence{Seed: New()}180:18discarded-error-result
set_test.go:180:18
for i := range ksuids[:10] { ksuids[i], _ = sequence.Next() // exercise dedupe on the id range code path }189:25nested-structs
set_test.go:189:25
miss := make(map[KSUID]struct{}) uniq := make(map[KSUID]struct{})190:25nested-structs
set_test.go:190:25
miss := make(map[KSUID]struct{}) uniq := make(map[KSUID]struct{})193:14nested-structs
set_test.go:193:14
for _, id := range ksuids { miss[id] = struct{}{} }202:20nested-structs
set_test.go:202:20
} uniq[it.KSUID] = struct{}{} delete(miss, it.KSUID)246:15discarded-error-result
set_test.go:246:15
for i := 0; i < 5; i++ { ids[i], _ = seq.Next() }260:12error-strings
set_test.go:260:12
if index != 5 { t.Errorf("Expected 5 ids, got %d", index) }297:6cognitive-complexity
set_test.go:297:6
func BenchmarkCompressedSet(b *testing.B) { ksuids1 := [1000]KSUID{}uint128.go7
1:1format
uint128.go:1:1
package ksuid- Fix (safe): run `strider fmt uint128.go`
1:9package-comments
uint128.go:1:9
package ksuid31:2no-naked-return
uint128.go:31:2
binary.BigEndian.PutUint64(out[12:], v[0]) // low return}37:2no-naked-return
uint128.go:37:2
binary.BigEndian.PutUint64(out[8:], v[0]) return}64:2no-naked-return
uint128.go:64:2
z[1], _ = bits.Add64(x[1], y[1], c) return}71:2no-naked-return
uint128.go:71:2
z[1], _ = bits.Sub64(x[1], y[1], b) return}78:2no-naked-return
uint128.go:78:2
z[1] = x[1] + c return}uint128_test.go13
8:6test-parallelism
uint128_test.go:8:6
func TestCmp128(t *testing.T) { tests := []struct {9:13nested-structs
uint128_test.go:9:13
func TestCmp128(t *testing.T) { tests := []struct { x uint12842:55range-value-capture
uint128_test.go:42:55
for _, test := range tests { t.Run(fmt.Sprintf("cmp128(%s,%s)", test.x, test.y), func(t *testing.T) { if k := cmp128(test.x, test.y); k != test.k {42:55test-parallelism
uint128_test.go:42:55
for _, test := range tests { t.Run(fmt.Sprintf("cmp128(%s,%s)", test.x, test.y), func(t *testing.T) { if k := cmp128(test.x, test.y); k != test.k {50:6test-parallelism
uint128_test.go:50:6
func TestAdd128(t *testing.T) { tests := []struct {51:13nested-structs
uint128_test.go:51:13
func TestAdd128(t *testing.T) { tests := []struct { x uint12889:55range-value-capture
uint128_test.go:89:55
for _, test := range tests { t.Run(fmt.Sprintf("add128(%s,%s)", test.x, test.y), func(t *testing.T) { if z := add128(test.x, test.y); z != test.z {89:55test-parallelism
uint128_test.go:89:55
for _, test := range tests { t.Run(fmt.Sprintf("add128(%s,%s)", test.x, test.y), func(t *testing.T) { if z := add128(test.x, test.y); z != test.z {97:6test-parallelism
uint128_test.go:97:6
func TestSub128(t *testing.T) { tests := []struct {98:13nested-structs
uint128_test.go:98:13
func TestSub128(t *testing.T) { tests := []struct { x uint128136:55range-value-capture
uint128_test.go:136:55
for _, test := range tests { t.Run(fmt.Sprintf("sub128(%s,%s)", test.x, test.y), func(t *testing.T) { if z := sub128(test.x, test.y); z != test.z {136:55test-parallelism
uint128_test.go:136:55
for _, test := range tests { t.Run(fmt.Sprintf("sub128(%s,%s)", test.x, test.y), func(t *testing.T) { if z := sub128(test.x, test.y); z != test.z {138:16add-constant
uint128_test.go:138:16
if z := sub128(test.x, test.y); z != test.z { t.Error(z, "!=", test.z) }