Documentation
¶
Overview ¶
The redistore package defines a Redis store that fulfills the RandomWalkStore interface in models.
Index ¶
- Constants
- Variables
- func KeyWalksVisiting(nodeID uint32) string
- type RWSFields
- type RandomWalkStore
- func GenerateRWS(cl *redis.Client, nodesNum, walksNum int) (*RandomWalkStore, error)
- func NewRWS(ctx context.Context, cl *redis.Client, alpha float32, walksPerNode uint16) (*RandomWalkStore, error)
- func NewRWSConnection(ctx context.Context, cl *redis.Client) (*RandomWalkStore, error)
- func SetupRWS(cl *redis.Client, RWSType string) (*RandomWalkStore, error)
- func (RWS *RandomWalkStore) AddWalks(ctx context.Context, walks ...models.RandomWalk) error
- func (RWS *RandomWalkStore) Alpha(ctx context.Context) float32
- func (RWS *RandomWalkStore) PruneGraftWalk(ctx context.Context, walkID uint32, cutIndex int, ...) error
- func (RWS *RandomWalkStore) RemoveWalks(ctx context.Context, walkIDs ...uint32) error
- func (RWS *RandomWalkStore) TotalVisits(ctx context.Context) int
- func (RWS *RandomWalkStore) Validate() error
- func (RWS *RandomWalkStore) VisitCounts(ctx context.Context, nodeIDs ...uint32) ([]int, error)
- func (RWS *RandomWalkStore) Walks(ctx context.Context, walkIDs ...uint32) ([]models.RandomWalk, error)
- func (RWS *RandomWalkStore) WalksPerNode(ctx context.Context) uint16
- func (RWS *RandomWalkStore) WalksVisiting(ctx context.Context, limit int, nodeIDs ...uint32) ([]uint32, error)
- func (RWS *RandomWalkStore) WalksVisitingAll(ctx context.Context, nodeIDs ...uint32) ([]uint32, error)
Constants ¶
Variables ¶
var ErrNilClient = errors.New("nil redis client pointer")
Functions ¶
func KeyWalksVisiting ¶
KeyWalksVisiting() returns the Redis key for the nodeWalkIDs with specified nodeID
Types ¶
type RWSFields ¶
type RWSFields struct { Alpha float32 `redis:"alpha"` WalksPerNode uint16 `redis:"walksPerNode"` LastWalkID int `redis:"lastWalkID"` TotalVisits int `redis:"totalVisits"` }
RWSFields are the fields of the RWS in Redis. This struct is used for serialize and deserialize.
type RandomWalkStore ¶
type RandomWalkStore struct {
// contains filtered or unexported fields
}
RandomWalkStore implements the omonimus interface defined in models.
func GenerateRWS ¶
func GenerateRWS(cl *redis.Client, nodesNum, walksNum int) (*RandomWalkStore, error)
GenerateRWS() randomly generates walks and adds them to the RWS.
func NewRWS ¶
func NewRWS(ctx context.Context, cl *redis.Client, alpha float32, walksPerNode uint16) (*RandomWalkStore, error)
NewRWS creates a new instance of RandomWalkStore using the provided Redis client, and overwrites alpha, walksPerNode, nextNodeID, and nextWalkID in a Redis hash named "rws".
func NewRWSConnection ¶
func NewRWSConnection(ctx context.Context, cl *redis.Client) (*RandomWalkStore, error)
NewRWSConnection() loads the instance of RandomWalkStore using the provided Redis client
func SetupRWS ¶
func SetupRWS(cl *redis.Client, RWSType string) (*RandomWalkStore, error)
SetupRWS returns a RandomWalkStore ready to be used in tests.
func (*RandomWalkStore) AddWalks ¶
func (RWS *RandomWalkStore) AddWalks(ctx context.Context, walks ...models.RandomWalk) error
AddWalks() adds all the specified walks to the RWS. If at least one of the walks is invalid, no walk gets added.
func (*RandomWalkStore) Alpha ¶
func (RWS *RandomWalkStore) Alpha(ctx context.Context) float32
Alpha() returns the dampening factor used for the RandomWalks
func (*RandomWalkStore) PruneGraftWalk ¶
func (RWS *RandomWalkStore) PruneGraftWalk(ctx context.Context, walkID uint32, cutIndex int, walkSegment models.RandomWalk) error
PruneGraftWalk() encapsulates the functions of pruning and grafting ( = appending to) a walk. These functions need to be coupled together to leverage the atomicity of Redis transactions.
func (*RandomWalkStore) RemoveWalks ¶
func (RWS *RandomWalkStore) RemoveWalks(ctx context.Context, walkIDs ...uint32) error
RemoveWalks() removes all the specified walks from the RWS. If one walkID is not found, no walk gets removed.
func (*RandomWalkStore) TotalVisits ¶
func (RWS *RandomWalkStore) TotalVisits(ctx context.Context) int
TotalVisits() returns the total number of visits. In case of any error, the default value 0 is returned.
func (*RandomWalkStore) Validate ¶
func (RWS *RandomWalkStore) Validate() error
Validate() checks the fields of the RWS struct and returns the appropriate error.
func (*RandomWalkStore) VisitCounts ¶
VisitCounts() returns the number of times each nodeID was visited by a walk. If nodeID is not found, 0 visits are returned.
func (*RandomWalkStore) Walks ¶
func (RWS *RandomWalkStore) Walks(ctx context.Context, walkIDs ...uint32) ([]models.RandomWalk, error)
Walks() returns the walks associated with the walkIDs.
func (*RandomWalkStore) WalksPerNode ¶
func (RWS *RandomWalkStore) WalksPerNode(ctx context.Context) uint16
WalkPerNode() returns the number of walks to be generated for each node in the DB.
func (*RandomWalkStore) WalksVisiting ¶
func (RWS *RandomWalkStore) WalksVisiting(ctx context.Context, limit int, nodeIDs ...uint32) ([]uint32, error)
WalksVisiting() returns up to limit UNIQUE walkIDs evenly distributed among the specified nodeIDs. In other words, it returns up to limit/len(nodeIDs) walkIDs for each of the nodes.
Note: - If limit = 0, no walk is returned - If limit < nodeIDs, no walk is returned - If limit = -1, all walks for all nodes are returned (USE WITH CAUTION).
func (*RandomWalkStore) WalksVisitingAll ¶
func (RWS *RandomWalkStore) WalksVisitingAll(ctx context.Context, nodeIDs ...uint32) ([]uint32, error)
WalksVisitingAll() returns all the IDs of the walk that visit ALL specified nodes.