Skip to content

🎧 Your Personal Streaming Service

Rename WeightedChooser's method Put to Add, a better name

Deluan769e8bedbadc
diff --git a/core/external_metadata.go b/core/external_metadata.go
index 8c8db7d16..37825166e 100644
--- a/core/external_metadata.go
+++ b/core/external_metadata.go
@@ -182,7 +182,7 @@ func (e *externalMetadata) SimilarSongs(ctx context.Context, id string, count in
weight := topCount * (4 + artistWeight)
for _, mf := range topSongs {
- weightedSongs.Put(mf, weight)
+ weightedSongs.Add(mf, weight)
weight -= 4
}
return nil
diff --git a/utils/weighted_random_chooser.go b/utils/weighted_random_chooser.go
index 7f82d0fb6..e7e26cd85 100644
--- a/utils/weighted_random_chooser.go
+++ b/utils/weighted_random_chooser.go
@@ -16,7 +16,7 @@ func NewWeightedRandomChooser() *WeightedChooser {
return &WeightedChooser{}
}
-func (w *WeightedChooser) Put(value interface{}, weight int) {
+func (w *WeightedChooser) Add(value interface{}, weight int) {
w.entries = append(w.entries, value)
w.weights = append(w.weights, weight)
w.totalWeight += weight
diff --git a/utils/weighted_random_chooser_test.go b/utils/weighted_random_chooser_test.go
index 5dae561c8..48c20ffab 100644
--- a/utils/weighted_random_chooser_test.go
+++ b/utils/weighted_random_chooser_test.go
@@ -10,7 +10,7 @@ var _ = Describe("WeightedRandomChooser", func() {
BeforeEach(func() {
w = NewWeightedRandomChooser()
for i := 0; i < 10; i++ {
- w.Put(i, i)
+ w.Add(i, i)
}
})
@@ -23,14 +23,14 @@ var _ = Describe("WeightedRandomChooser", func() {
It("returns the sole item", func() {
w = NewWeightedRandomChooser()
- w.Put("a", 1)
+ w.Add("a", 1)
Expect(w.GetAndRemove()).To(Equal("a"))
})
It("fails when trying to choose from empty set", func() {
w = NewWeightedRandomChooser()
- w.Put("a", 1)
- w.Put("b", 1)
+ w.Add("a", 1)
+ w.Add("b", 1)
Expect(w.GetAndRemove()).To(BeElementOf("a", "b"))
Expect(w.GetAndRemove()).To(BeElementOf("a", "b"))
_, err := w.GetAndRemove()