porcupine

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GetOp = iota
	PutOp = iota
	DelOp = iota
)

Variables

View Source
var Model = pp.Model[MapState, Input, Output]{
	Init: NewMapState,
	Partition: func(history []pp.Operation[Input, Output]) [][]pp.Operation[Input, Output] {
		indexMap := map[string]int{}
		var partitions [][]pp.Operation[Input, Output]
		for _, op := range history {
			i := op.Input
			ix, found := indexMap[i.Key]
			if !found {
				partitions = append(partitions, []pp.Operation[Input, Output]{op})
				indexMap[i.Key] = len(partitions) - 1
			} else {
				partitions[ix] = append(partitions[ix], op)
			}
		}
		return partitions
	},
	Step: func(s MapState, i Input, o Output) (bool, MapState) {
		stateVal, found := s.m[i.Key]

		switch i.Operation {
		case GetOp:
			if errors.Is(o.Err, simpledb.ErrNotFound) {
				return !found, s
			} else if stateVal == o.Val {
				return true, s
			}
			break
		case PutOp:
			if o.Err == nil {
				s.m[i.Key] = i.Val
				return true, s
			}
			break
		case DelOp:
			if o.Err == nil {
				delete(s.m, i.Key)
				return true, s
			}
			break
		}

		if o.Err != nil {
			log.Printf("unexpected error state found for key: [%s] %v\n", i.Key, o.Err)
			panic(o.Err)
		}

		return false, s
	},
	DescribeOperation: func(i Input, o Output) string {
		opName := ""
		switch i.Operation {
		case GetOp:
			opName = "Get"
			break
		case PutOp:
			opName = "Put"
			break
		case DelOp:
			opName = "Del"
			break
		}

		return fmt.Sprintf("%s(%s) -> %s", opName, i.Key, shorten(o.Val, 5))
	},
}

Functions

func VerifyOperations

func VerifyOperations(t *testing.T, operations []pp.Operation[Input, Output])

Types

type DatabaseClientRecorder

type DatabaseClientRecorder struct {
	// contains filtered or unexported fields
}

func NewDatabaseRecorder

func NewDatabaseRecorder(db simpledb.DatabaseI, clientId int) *DatabaseClientRecorder

func (*DatabaseClientRecorder) Delete

func (d *DatabaseClientRecorder) Delete(key string) error

func (*DatabaseClientRecorder) Get

func (d *DatabaseClientRecorder) Get(key string) (string, error)

func (*DatabaseClientRecorder) Operations

func (*DatabaseClientRecorder) Put

func (d *DatabaseClientRecorder) Put(key, value string) error

type Input

type Input struct {
	Operation uint8
	Key       string
	Val       string
}

type MapState

type MapState struct {
	// contains filtered or unexported fields
}

func NewMapState

func NewMapState() MapState

func (MapState) Clone

func (s MapState) Clone() MapState

func (MapState) Equals

func (s MapState) Equals(otherState MapState) bool

func (MapState) String

func (s MapState) String() string

type Output

type Output struct {
	Key string
	Val string
	Err error
}

Jump to

Keyboard shortcuts

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