1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-12 05:20:26 +00:00

Start implementing memdb-driven hyphae

This commit is contained in:
bouncepaw 2021-01-03 01:52:23 +05:00
parent 4d2be01b85
commit 301592ad7d
5 changed files with 118 additions and 1 deletions

1
.gitignore vendored
View File

@ -1,2 +1 @@
hypha
mycorrhiza

1
go.mod
View File

@ -5,5 +5,6 @@ go 1.14
require (
github.com/adrg/xdg v0.2.2
github.com/gorilla/feeds v1.1.1
github.com/hashicorp/go-memdb v1.3.0
github.com/valyala/quicktemplate v1.6.3
)

8
go.sum
View File

@ -4,6 +4,14 @@ github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gorilla/feeds v1.1.1 h1:HwKXxqzcRNg9to+BbvJog4+f3s/xzvtZXICcQGutYfY=
github.com/gorilla/feeds v1.1.1/go.mod h1:Nk0jZrvPFZX1OBe5NPiddPw7CfwF6Q9eqzaBbaightA=
github.com/hashicorp/go-immutable-radix v1.3.0 h1:8exGP7ego3OmkfksihtSouGMZ+hQrhxx+FVELeXpVPE=
github.com/hashicorp/go-immutable-radix v1.3.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-memdb v1.3.0 h1:xdXq34gBOMEloa9rlGStLxmfX/dyIK8htOv36dQUwHU=
github.com/hashicorp/go-memdb v1.3.0/go.mod h1:Mluclgwib3R93Hk5fxEfiRhB+6Dar64wWh71LpNSe3g=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.11.0/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=

33
hypha/count.go Normal file
View File

@ -0,0 +1,33 @@
package hypha
import (
"sync"
)
type count struct {
value uint
sync.Mutex
}
// Count is a global variable. Its value is number of all existing hyphae. Hypha mutators are expected to manipulate the value. It is concurrent-safe.
var Count = count{}
// Increment the value of Count.
func (c *count) Increment() {
c.Lock()
c.value++
c.Unlock()
}
// Decrement the value of Count.
func (c *count) Decrement() {
c.Lock()
c.value--
c.Unlock()
}
// Get value of Count.
func (c *count) Value() uint {
// it is concurrent-safe to not lock here, right?
return c.value
}

76
hypha/hypha.go Normal file
View File

@ -0,0 +1,76 @@
package hypha
import (
"errors"
"github.com/hashicorp/go-memdb"
)
type Hypha struct {
Name string
Exists bool
TextPath string
BinaryPath string
OutLinks []string
BackLinks []string
}
func AddHypha(h Hypha) error {
return errors.New("Not implemented")
}
// Create the DB schema
var schema = &memdb.DBSchema{
Tables: map[string]*memdb.TableSchema{
"hyphae": &memdb.TableSchema{
Name: "hyphae",
Indexes: map[string]*memdb.IndexSchema{
"name": &memdb.IndexSchema{
Name: "name",
Unique: true,
Indexer: &memdb.StringFieldIndex{Field: "Name"},
},
"exists": &memdb.IndexSchema{
Name: "exists",
Unique: false,
AllowEmpty: true,
Indexer: &memdb.BoolFieldIndex{Field: "Exists"},
},
"text-path": &memdb.IndexSchema{
Name: "text-path",
Unique: true,
AllowEmpty: true,
Indexer: &memdb.StringFieldIndex{Field: "TextPath"},
},
"binary-path": &memdb.IndexSchema{
Name: "binary-path",
Unique: true,
AllowEmpty: true,
Indexer: &memdb.StringFieldIndex{Field: "BinaryPath"},
},
"out-links": &memdb.IndexSchema{
Name: "out-links",
Unique: false,
AllowEmpty: true,
Indexer: &memdb.StringSliceFieldIndex{Field: "OutLinks"},
},
"back-links": &memdb.IndexSchema{
Name: "back-links",
Unique: false,
AllowEmpty: true,
Indexer: &memdb.StringSliceFieldIndex{Field: "BackLinks"},
},
},
},
},
}
var db *memdb.MemDB
func init() {
var err error
db, err = memdb.NewMemDB(schema)
if err != nil {
panic(err)
}
}