Documentation ¶
Overview ¶
Package treemap provides a generic key-sorted map. It uses red-black tree under the hood. You can use it as a template to generate a sorted map with specific key and value types. Iterators are designed after C++.
Example:
package main import "fmt" //go:generate gotemplate "github.com/ncw/gotemplate/treemap" "intStringTreeMap(int, string)" func less(x, y int) bool { return x < y } func main() { tr := newIntStringTreeMap(less) tr.Set(0, "Hello") tr.Set(1, "World") for it := tr.Iterator(); it.Valid(); it.Next() { fmt.Println(it.Key(), it.Value()) } }
Index ¶
- Variables
- type DatabaseLeaderboardStore
- func (d *DatabaseLeaderboardStore) CreateScoreSubmissions(submission server.Submission) error
- func (d *DatabaseLeaderboardStore) CreateUserProfile(user server.User) (server.User, error)
- func (d *DatabaseLeaderboardStore) CreateUserProfiles(submission server.Submission) error
- func (d *DatabaseLeaderboardStore) GetUserProfile(userId string) (server.User, error)
- func (d *DatabaseLeaderboardStore) GetUserRankings() []server.User
- func (d *DatabaseLeaderboardStore) GetUserRankingsFiltered(country string) []server.User
- func (d *DatabaseLeaderboardStore) InitializeConnection() func()
- func (d *DatabaseLeaderboardStore) InitializeRedisCache()
- func (d *DatabaseLeaderboardStore) SubmitUserScore(score server.Score) (server.Score, error)
- type ForwardIteratorRankingMap
- type InMemoryLeaderboardStore
- func (i *InMemoryLeaderboardStore) CreateUserProfile(user server.User) error
- func (i *InMemoryLeaderboardStore) GetUserProfile(name string) (server.User, error)
- func (i *InMemoryLeaderboardStore) GetUserRankings() []server.User
- func (i *InMemoryLeaderboardStore) GetUserRankingsFiltered(country string) []server.User
- func (i *InMemoryLeaderboardStore) SubmitUserScore(score server.Score) (server.Score, error)
- type InMemoryRankingLeaderboardStore
- func (i *InMemoryRankingLeaderboardStore) CreateScoreSubmissions(submission server.Submission) error
- func (i *InMemoryRankingLeaderboardStore) CreateUserProfile(user server.User) (server.User, error)
- func (i *InMemoryRankingLeaderboardStore) CreateUserProfiles(submission server.Submission) error
- func (i *InMemoryRankingLeaderboardStore) GetUserProfile(userId string) (server.User, error)
- func (i *InMemoryRankingLeaderboardStore) GetUserRankings() []server.User
- func (i *InMemoryRankingLeaderboardStore) GetUserRankingsFiltered(country string) []server.User
- func (i *InMemoryRankingLeaderboardStore) SubmitUserScore(score server.Score) (server.Score, error)
- type Ranking
- type RankingMap
- func (t *RankingMap) Clear()
- func (t *RankingMap) Contains(id float64) bool
- func (t *RankingMap) Del(key float64)
- func (t *RankingMap) Get(id float64) (map[string]int, bool)
- func (t *RankingMap) Iterator() ForwardIteratorRankingMap
- func (t *RankingMap) Len() int
- func (t *RankingMap) LowerBound(key float64) ForwardIteratorRankingMap
- func (t *RankingMap) Range(from, to float64) (ForwardIteratorRankingMap, ForwardIteratorRankingMap)
- func (t *RankingMap) Reverse() ReverseIteratorRankingMap
- func (t *RankingMap) Set(key float64, value map[string]int)
- func (t *RankingMap) UpperBound(key float64) ForwardIteratorRankingMap
- type ReverseIteratorRankingMap
- type UserRank
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type DatabaseLeaderboardStore ¶
type DatabaseLeaderboardStore struct { MongoClient *mongo.Client RedisClient *redis.Client // contains filtered or unexported fields }
func NewDatabaseLeaderboardStore ¶
func NewDatabaseLeaderboardStore(config server.ConfigurationType) *DatabaseLeaderboardStore
func (*DatabaseLeaderboardStore) CreateScoreSubmissions ¶
func (d *DatabaseLeaderboardStore) CreateScoreSubmissions(submission server.Submission) error
func (*DatabaseLeaderboardStore) CreateUserProfile ¶
func (*DatabaseLeaderboardStore) CreateUserProfiles ¶
func (d *DatabaseLeaderboardStore) CreateUserProfiles(submission server.Submission) error
func (*DatabaseLeaderboardStore) GetUserProfile ¶
func (d *DatabaseLeaderboardStore) GetUserProfile(userId string) (server.User, error)
func (*DatabaseLeaderboardStore) GetUserRankings ¶
func (d *DatabaseLeaderboardStore) GetUserRankings() []server.User
func (*DatabaseLeaderboardStore) GetUserRankingsFiltered ¶
func (d *DatabaseLeaderboardStore) GetUserRankingsFiltered(country string) []server.User
func (*DatabaseLeaderboardStore) InitializeConnection ¶
func (d *DatabaseLeaderboardStore) InitializeConnection() func()
func (*DatabaseLeaderboardStore) InitializeRedisCache ¶
func (d *DatabaseLeaderboardStore) InitializeRedisCache()
func (*DatabaseLeaderboardStore) SubmitUserScore ¶
type ForwardIteratorRankingMap ¶
type ForwardIteratorRankingMap struct {
// contains filtered or unexported fields
}
ForwardIterator represents a position in a tree map. It is designed to iterate a map in a forward order. It can point to any position from the first element to the one-past-the-end element.
func (ForwardIteratorRankingMap) Key ¶
func (i ForwardIteratorRankingMap) Key() float64
Key returns a key at an iterator's position
func (*ForwardIteratorRankingMap) Next ¶
func (i *ForwardIteratorRankingMap) Next()
Next moves an iterator to the next element. It panics if goes out of bounds.
func (*ForwardIteratorRankingMap) Prev ¶
func (i *ForwardIteratorRankingMap) Prev()
Prev moves an iterator to the previous element. It panics if goes out of bounds.
func (ForwardIteratorRankingMap) Valid ¶
func (i ForwardIteratorRankingMap) Valid() bool
Valid reports if an iterator's position is valid. In other words it returns true if an iterator is not at the one-past-the-end position.
func (ForwardIteratorRankingMap) Value ¶
func (i ForwardIteratorRankingMap) Value() map[string]int
Value returns a value at an iterator's position
type InMemoryLeaderboardStore ¶
type InMemoryLeaderboardStore struct {
// contains filtered or unexported fields
}
func NewInMemoryLeaderboardStore ¶
func NewInMemoryLeaderboardStore() *InMemoryLeaderboardStore
func (*InMemoryLeaderboardStore) CreateUserProfile ¶
func (i *InMemoryLeaderboardStore) CreateUserProfile(user server.User) error
func (*InMemoryLeaderboardStore) GetUserProfile ¶
func (i *InMemoryLeaderboardStore) GetUserProfile(name string) (server.User, error)
func (*InMemoryLeaderboardStore) GetUserRankings ¶
func (i *InMemoryLeaderboardStore) GetUserRankings() []server.User
func (*InMemoryLeaderboardStore) GetUserRankingsFiltered ¶
func (i *InMemoryLeaderboardStore) GetUserRankingsFiltered(country string) []server.User
func (*InMemoryLeaderboardStore) SubmitUserScore ¶
type InMemoryRankingLeaderboardStore ¶
type InMemoryRankingLeaderboardStore struct {
// contains filtered or unexported fields
}
func NewInMemoryRankingStore ¶
func NewInMemoryRankingStore() *InMemoryRankingLeaderboardStore
func (*InMemoryRankingLeaderboardStore) CreateScoreSubmissions ¶
func (i *InMemoryRankingLeaderboardStore) CreateScoreSubmissions(submission server.Submission) error
func (*InMemoryRankingLeaderboardStore) CreateUserProfile ¶
func (*InMemoryRankingLeaderboardStore) CreateUserProfiles ¶
func (i *InMemoryRankingLeaderboardStore) CreateUserProfiles(submission server.Submission) error
func (*InMemoryRankingLeaderboardStore) GetUserProfile ¶
func (i *InMemoryRankingLeaderboardStore) GetUserProfile(userId string) (server.User, error)
func (*InMemoryRankingLeaderboardStore) GetUserRankings ¶
func (i *InMemoryRankingLeaderboardStore) GetUserRankings() []server.User
func (*InMemoryRankingLeaderboardStore) GetUserRankingsFiltered ¶
func (i *InMemoryRankingLeaderboardStore) GetUserRankingsFiltered(country string) []server.User
func (*InMemoryRankingLeaderboardStore) SubmitUserScore ¶
type RankingMap ¶
type RankingMap struct { // Less returns a < b Less func(a float64, b float64) bool // contains filtered or unexported fields }
TreeMap is the red-black tree based map
func NewRankingMap ¶
func NewRankingMap(less func(a float64, b float64) bool) *RankingMap
New creates and returns new TreeMap. Parameter less is a function returning a < b.
func (*RankingMap) Contains ¶
func (t *RankingMap) Contains(id float64) bool
Contains checks if key exists in a map. Complexity: O(log N)
func (*RankingMap) Del ¶
func (t *RankingMap) Del(key float64)
Del deletes the value. Complexity: O(log N).
func (*RankingMap) Get ¶
func (t *RankingMap) Get(id float64) (map[string]int, bool)
Get retrieves a value from a map for specified key and reports if it exists. Complexity: O(log N).
func (*RankingMap) Iterator ¶
func (t *RankingMap) Iterator() ForwardIteratorRankingMap
Iterator returns an iterator for tree map. It starts at the first element and goes to the one-past-the-end position. You can iterate a map at O(N) complexity. Method complexity: O(1)
func (*RankingMap) Len ¶
func (t *RankingMap) Len() int
Len returns total count of elements in a map. Complexity: O(1).
func (*RankingMap) LowerBound ¶
func (t *RankingMap) LowerBound(key float64) ForwardIteratorRankingMap
LowerBound returns an iterator pointing to the first element that is not less than the given key. Complexity: O(log N).
func (*RankingMap) Range ¶
func (t *RankingMap) Range(from, to float64) (ForwardIteratorRankingMap, ForwardIteratorRankingMap)
Range returns a pair of iterators that you can use to go through all the keys in the range [from, to]. More specifically it returns iterators pointing to lower bound and upper bound. Complexity: O(log N).
func (*RankingMap) Reverse ¶
func (t *RankingMap) Reverse() ReverseIteratorRankingMap
Reverse returns a reverse iterator for tree map. It starts at the last element and goes to the one-before-the-start position. You can iterate a map at O(N) complexity. Method complexity: O(log N)
func (*RankingMap) Set ¶
func (t *RankingMap) Set(key float64, value map[string]int)
Set sets the value and silently overrides previous value if it exists. Complexity: O(log N).
func (*RankingMap) UpperBound ¶
func (t *RankingMap) UpperBound(key float64) ForwardIteratorRankingMap
UpperBound returns an iterator pointing to the first element that is greater than the given key. Complexity: O(log N).
type ReverseIteratorRankingMap ¶
type ReverseIteratorRankingMap struct {
// contains filtered or unexported fields
}
ReverseIterator represents a position in a tree map. It is designed to iterate a map in a reverse order. It can point to any position from the one-before-the-start element to the last element.
func (ReverseIteratorRankingMap) Key ¶
func (i ReverseIteratorRankingMap) Key() float64
Key returns a key at an iterator's position
func (*ReverseIteratorRankingMap) Next ¶
func (i *ReverseIteratorRankingMap) Next()
Next moves an iterator to the next element in reverse order. It panics if goes out of bounds.
func (*ReverseIteratorRankingMap) Prev ¶
func (i *ReverseIteratorRankingMap) Prev()
Prev moves an iterator to the previous element in reverse order. It panics if goes out of bounds.
func (ReverseIteratorRankingMap) Valid ¶
func (i ReverseIteratorRankingMap) Valid() bool
Valid reports if an iterator's position is valid. In other words it returns true if an iterator is not at the one-before-the-start position.
func (ReverseIteratorRankingMap) Value ¶
func (i ReverseIteratorRankingMap) Value() map[string]int
Value returns a value at an iterator's position