<commit_before>package master

import (
	"container/heap"
	. "github.com/KIT-MAMID/mamid/model"
)

type pqMongods struct {
	slice pqSlice
}

type pqMongodItem struct {
	Mongod         *Mongod
	ParentBusyRate float64
}

func pqMongodItemFromMongod(mongod *Mongod) *pqMongodItem {
	return &pqMongodItem{
		Mongod:         mongod,
		ParentBusyRate: slaveBusyRate(mongod.ParentSlave),
	}
}

func (q *pqMongods) PopMongodOnBusiestSlave() *Mongod {

	if q.slice.Len() <= 0 {
		return nil
	}

	item, ok := heap.Pop(&q.slice).(*pqMongodItem)
	if !ok {
		panic("unexpected type in pqMongods")
	}
	return item.Mongod
}

func (c *ClusterAllocator) pqMongods(mongods []*Mongod, p persistence) *pqMongods {

	items := make([]interface{}, len(mongods))
	for _, m := range mongods {
		if slavePersistence(m.ParentSlave) == p {
			items = append(items, pqMongodItemFromMongod(m))
		}
	}

	q := &pqMongods{
		slice: pqSlice{
			items,
			func(i, j interface{}) bool {
				a, a_ok := i.(*pqMongodItem)
				b, b_ok := j.(*pqMongodItem)
				if !a_ok || !b_ok {
					panic("unexpected type in pqMongods")
				}
				return a.ParentBusyRate > b.ParentBusyRate //'>' to have busiest node at top of heap TODO correct
			},
		},
	}<commit_msg>FIX: master: cluster allocator: pqMongods: slice initialization<commit_after>package master

import (
	"container/heap"
	. "github.com/KIT-MAMID/mamid/model"
)

type pqMongods struct {
	slice pqSlice
}

type pqMongodItem struct {
	Mongod         *Mongod
	ParentBusyRate float64
}

func pqMongodItemFromMongod(mongod *Mongod) *pqMongodItem {
	return &pqMongodItem{
		Mongod:         mongod,
		ParentBusyRate: slaveBusyRate(mongod.ParentSlave),
	}
}

func (q *pqMongods) PopMongodOnBusiestSlave() *Mongod {

	if q.slice.Len() <= 0 {
		return nil
	}

	item, ok := heap.Pop(&q.slice).(*pqMongodItem)
	if !ok {
		panic("unexpected type in pqMongods")
	}
	return item.Mongod
}

func (c *ClusterAllocator) pqMongods(mongods []*Mongod, p persistence) *pqMongods {

	items := make([]interface{}, 0, len(mongods))
	for _, m := range mongods {
		if slavePersistence(m.ParentSlave) == p {
			items = append(items, pqMongodItemFromMongod(m))
		}
	}

	q := &pqMongods{
		slice: pqSlice{
			items,
			func(i, j interface{}) bool {
				a, a_ok := i.(*pqMongodItem)
				b, b_ok := j.(*pqMongodItem)
				if !a_ok || !b_ok {
					panic("unexpected type in pqMongods")
				}
				return a.ParentBusyRate > b.ParentBusyRate //'>' to have busiest node at top of heap TODO correct
			},
		},
	}
{'fraction_non_alphanumeric': 0.13309207880981103, 'fraction_numerical': 0.0028146361077603537, 'mean_word_length': 3.6943396226415093, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6256036', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1012, 'n_words': 215}