seeds/

directory
v0.0.0-...-cf38f87 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2017 License: Apache-2.0

README

Seeds for GenX.

Usage

➤ genx -seed set -t T=string -n main -o ./string_set.go
➤ genx -seed set -t T=uint64 -n main -o ./string_uint64.go

# or
➤ genx -seed atomicMap -t KT=string,VT=uint64 -n main -o ./amap_string_uint64.go

Available Seeds

set
  • A very simple set with Set/Unset/Has/Merge/Keys() support.
  • Generate with: genx -seeds set -t T=YourType -n package-name -o ./set_YourType.go
  • Usage: s := NewYourTypeSet()
atomicValue
  • Typed sync/atomic.Value with Swap/CompareAndSwap support (using a sync.RWMutex).
  • Generate with: genx -seeds atomicValue -t T=YourType -n package-name -o ./atomic_YourType.go
  • Usage: v := NewAtomicYourType(some initial value) or v := &AtomicYourType{}; old := v.Swap(new value)
atomicMap
  • The code generated from this seed is under The Go BSD-style license.
  • A modified version of sync.Map to support code gen.
  • Generate with: genx -seeds atomicMap -t KT=YourKeyType,VT=YourValueType -n package-name -o ./somename.go
  • Generate with (change name): genx -seeds atomicMap -t KT=YourKeyType,VT=YourValueType,MapKTVT=somethingPrivate -n package-name -o ./somename.go
  • Usage: var m somethingPrivate; v, loaded := m.LoadOrStore(some key, some default value)
sort
  • The code generated from this seed is under The Go BSD-style license.
  • Shows how to target native types vs other types with tags.
  • For builtin types, it uses builtin-types.go.
  • For other types, it expects a func(i, j int) bool func, and uses other-types.go.
  • A modified version of sort.Slice/sort.SliceStable to support code gen.
  • Generate with: genx -seeds sort -t T=YourType -n package-name -o ./sort_YourType.go
  • Usage with a builtin comparable type (genx -seeds sort -t T=string ...): SortStrings(stringSlice, true or false for reverse sort).
  • Usage with other types (genx -seeds sort -t T=*YourType ...):
SortYourType(yourSlice, func(i, j) bool { return yourSlice[i].X < yourSlice[j].X })
// for reverse sort
SortYourType(yourSlice, func(j, i) bool { return yourSlice[i].X < yourSlice[j].X })

Todo

  • Documention for each seed.

Directories

Path Synopsis
atomicMap is a seed based on sync.Map in the stdlib.
atomicMap is a seed based on sync.Map in the stdlib.
utils
sort is copied from stdlib, most functions made public to support generic sorters.
sort is copied from stdlib, most functions made public to support generic sorters.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL