diff --git a/nptime/nptime.go b/nptime/nptime.go deleted file mode 100644 index a22a280..0000000 --- a/nptime/nptime.go +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) 2018, The GoKi Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -/* -Package nptime provides a non-pointer version of the time.Time struct -that does not have the location pointer information that time.Time has, -which is more efficient from a memory management perspective, in cases -where you have a lot of time values being kept: https://segment.com/blog/allocation-efficiency-in-high-performance-go-services/ -*/ -package nptime - -import "time" - -// Time represents the value of time.Time without using any pointers for the -// location information, so it is more memory efficient when lots of time -// values are being stored. -type Time struct { - - // time.Time.Unix() seconds since 1970 - Sec int64 `desc:"time.Time.Unix() seconds since 1970"` - - // time.Time.Nanosecond() -- nanosecond offset within second, *not* UnixNano() - NSec uint32 `desc:"time.Time.Nanosecond() -- nanosecond offset within second, *not* UnixNano()"` -} - -// TimeZero is the uninitialized zero time value -- use to check whether -// time has been set or not -var TimeZero Time - -// IsZero returns true if the time is zero and has not been initialized -func (t Time) IsZero() bool { - return t == TimeZero -} - -// Time returns the time.Time value for this nptime.Time value -func (t Time) Time() time.Time { - return time.Unix(t.Sec, int64(t.NSec)) -} - -// SetTime sets the nptime.Time value based on the time.Time value -func (t *Time) SetTime(tt time.Time) { - t.Sec = tt.Unix() - t.NSec = uint32(tt.Nanosecond()) -} - -// Now sets the time value to time.Now() -func (t *Time) Now() { - t.SetTime(time.Now()) -} diff --git a/nptime/nptime_test.go b/nptime/nptime_test.go deleted file mode 100644 index a992f3b..0000000 --- a/nptime/nptime_test.go +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) 2018, The GoKi Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package nptime - -import ( - "testing" - "time" -) - -func TestTime(t *testing.T) { - tn := time.Now() - tp := Time{} - tp.SetTime(tn) - tnr := tp.Time() - - if !tn.Equal(tnr) { - t.Errorf("time was not reconstructed properly: %v vs. %v\n", tn, tnr) - } -} diff --git a/runes/runes.go b/runes/runes.go deleted file mode 100644 index 19f8545..0000000 --- a/runes/runes.go +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright (c) 2018, The GoKi Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -/* -Package runes provides a small subset of functions that are found in strings, bytes -standard packages, for rune slices. For rendering, and other logic, it is best to -keep raw data in runes, and not having to convert back and forth to byte or string -is more efficient. - -These are largely copied from strings or bytes packages. -*/ -package runes - -import ( - "unicode" - "unicode/utf8" -) - -// EqualFold reports whether s and t are equal under Unicode case-folding. -// copied from strings.EqualFold -func EqualFold(s, t []rune) bool { - for len(s) > 0 && len(t) > 0 { - // Extract first rune from each string. - var sr, tr rune - sr, s = s[0], s[1:] - tr, t = t[0], t[1:] - // If they match, keep going; if not, return false. - - // Easy case. - if tr == sr { - continue - } - - // Make sr < tr to simplify what follows. - if tr < sr { - tr, sr = sr, tr - } - // Fast check for ASCII. - if tr < utf8.RuneSelf { - // ASCII only, sr/tr must be upper/lower case - if 'A' <= sr && sr <= 'Z' && tr == sr+'a'-'A' { - continue - } - return false - } - - // General case. SimpleFold(x) returns the next equivalent rune > x - // or wraps around to smaller values. - r := unicode.SimpleFold(sr) - for r != sr && r < tr { - r = unicode.SimpleFold(r) - } - if r == tr { - continue - } - return false - } - - // One string is empty. Are both? - return len(s) == len(t) -} - -// Index returns the index of given rune string in the text, returning -1 if not found. -func Index(txt, find []rune) int { - fsz := len(find) - if fsz == 0 { - return -1 - } - tsz := len(txt) - if tsz < fsz { - return -1 - } - mn := tsz - fsz - for i := 0; i <= mn; i++ { - found := true - for j := range find { - if txt[i+j] != find[j] { - found = false - break - } - } - if found { - return i - } - } - return -1 -} - -// IndexFold returns the index of given rune string in the text, using case folding -// (i.e., case insensitive matching). Returns -1 if not found. -func IndexFold(txt, find []rune) int { - fsz := len(find) - if fsz == 0 { - return -1 - } - tsz := len(txt) - if tsz < fsz { - return -1 - } - mn := tsz - fsz - for i := 0; i <= mn; i++ { - if EqualFold(txt[i:i+fsz], find) { - return i - } - } - return -1 -} - -// Repeat returns a new rune slice consisting of count copies of b. -// -// It panics if count is negative or if -// the result of (len(b) * count) overflows. -func Repeat(r []rune, count int) []rune { - if count == 0 { - return []rune{} - } - // Since we cannot return an error on overflow, - // we should panic if the repeat will generate - // an overflow. - // See Issue golang.org/issue/16237. - if count < 0 { - panic("runes: negative Repeat count") - } else if len(r)*count/count != len(r) { - panic("runes: Repeat count causes overflow") - } - - nb := make([]rune, len(r)*count) - bp := copy(nb, r) - for bp < len(nb) { - copy(nb[bp:], nb[:bp]) - bp *= 2 - } - return nb -} diff --git a/sliceclone/sliceclone.go b/sliceclone/sliceclone.go deleted file mode 100644 index 02bdf61..0000000 --- a/sliceclone/sliceclone.go +++ /dev/null @@ -1,144 +0,0 @@ -// Copyright (c) 2019, The GoKi Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -/* -Package sliceclone provides those basic slice cloning methods that I finally got tired of -rewriting all the time. -*/ -package sliceclone - -// String returns a cloned copy of the given string slice -- returns nil -// if slice has zero length -func String(sl []string) []string { - sz := len(sl) - if sz == 0 { - return nil - } - cp := make([]string, sz) - copy(cp, sl) - return cp -} - -// StringExclude returns a cloned copy of the given string slice -// while excluding the list of specific items -func StringExclude(sl, exclude []string) []string { - sz := len(sl) - if sz == 0 { - return nil - } - if len(exclude) == 0 { - return String(sl) - } - var cp []string - for _, s := range sl { - ex := false - for _, e := range exclude { - if e == s { - ex = true - break - } - } - if ex { - continue - } - cp = append(cp, s) - } - return cp -} - -// Byte returns a cloned copy of the given byte slice -- returns nil -// if slice has zero length -func Byte(sl []byte) []byte { - sz := len(sl) - if sz == 0 { - return nil - } - cp := make([]byte, sz) - copy(cp, sl) - return cp -} - -// Rune returns a cloned copy of the given rune slice -- returns nil -// if slice has zero length -func Rune(sl []rune) []rune { - sz := len(sl) - if sz == 0 { - return nil - } - cp := make([]rune, sz) - copy(cp, sl) - return cp -} - -// Bool returns a cloned copy of the given bool slice -- returns nil -// if slice has zero length -func Bool(sl []bool) []bool { - sz := len(sl) - if sz == 0 { - return nil - } - cp := make([]bool, sz) - copy(cp, sl) - return cp -} - -// Int returns a cloned copy of the given int slice -- returns nil -// if slice has zero length -func Int(sl []int) []int { - sz := len(sl) - if sz == 0 { - return nil - } - cp := make([]int, sz) - copy(cp, sl) - return cp -} - -// Int32 returns a cloned copy of the given int32 slice -- returns nil -// if slice has zero length -func Int32(sl []int32) []int32 { - sz := len(sl) - if sz == 0 { - return nil - } - cp := make([]int32, sz) - copy(cp, sl) - return cp -} - -// Int64 returns a cloned copy of the given int64 slice -- returns nil -// if slice has zero length -func Int64(sl []int64) []int64 { - sz := len(sl) - if sz == 0 { - return nil - } - cp := make([]int64, sz) - copy(cp, sl) - return cp -} - -// Float64 returns a cloned copy of the given float64 slice -- returns nil -// if slice has zero length -func Float64(sl []float64) []float64 { - sz := len(sl) - if sz == 0 { - return nil - } - cp := make([]float64, sz) - copy(cp, sl) - return cp -} - -// Float32 returns a cloned copy of the given float32 slice -- returns nil -// if slice has zero length -func Float32(sl []float32) []float32 { - sz := len(sl) - if sz == 0 { - return nil - } - cp := make([]float32, sz) - copy(cp, sl) - return cp -}