This repository was archived by the owner on Sep 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathintergo.go
More file actions
35 lines (29 loc) · 1.28 KB
/
intergo.go
File metadata and controls
35 lines (29 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package intergo
// type ID is used as identifier of items.
// The purpose is to remove item duplication in generated rankings.
type ID string
// Ranking is the interface which all of target ranking should implement.
type Ranking interface {
// GetIDByIndex allows interleaving/multileaving algorithms to access items' identifier
GetIDByIndex(int) ID
// Len is used to get the "length" of the ranking
Len() int
}
// Result is the type of generated ranking's each entity.
type Result struct {
// RankingIndex represents to which ranking the item belongs
RankingIndex int
// ItemIndex represents the item's index in the ranking declared by RankingIndex
ItemIndex int
}
// Interleaving is the interface which every interleaving/multileaving algorithm should implement.
type Interleaving interface {
// GetInterleavedRanking is intended to be used for ranking generation.
//
// First argument "num" is the expected length of a resulted ranking. Ideally,
// if the total number of unique items in given rankings is greater than equal "num",
// the resulted length should equal "num". However, it depends on the implementations.
//
// "rankings" should be your rankings from which you want to generate a multileaved ranking.
GetInterleavedRanking(num int, rankings ...Ranking) ([]*Result, error)
}