You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: allocator_scorer.go
    path of file: ./repos/cockroach/pkg/kv/kvserver/allocator/allocatorimpl
    
    the code of the file until where you have to start completion: // Copyright 2016 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package allocatorimpl

import (
	"bytes"
	"context"
	"fmt"
	"math"
	"sort"
	"time"

	"github.com/cockroachdb/cockroach/pkg/kv/kvserv
    
func (c candidate) compare(o candidate) float64 {
	if !o.valid {
		return 600
	}
	if !c.valid {
		return -600
	}
	if o.fullDisk {
		return 500
	}
	if c.fullDisk {
		return -500
	}
	if c.necessary != o.necessary {
		if c.necessary {
			return 400
		}
		return -400
	}
	if c.voterNecessary != o.voterNecessary {
		if c.voterNecessary {
			return 350
		}
		return -350
	}
	if !scoresAlmostEqual(c.diversityScore, o.diversityScore) {
		if c.diversityScore > o.diversityScore {
			return 300
		}
		return -300
	}
	// If both o and c are IO overloaded, then we prefer the
	// candidate with the lower IO overload score.
	if o.ioOverloaded && c.ioOverloaded {
		if o.ioOverloadScore > c.ioOverloadScore {
			return 250
		}
	}
	if c.ioOverloaded {
		return -250
	}
	if o.ioOverloaded {
		return 250
	}

	if c.convergesScore != o.convergesScore {
		if c.convergesScore > o.convergesScore {
			return 200 + float64(c.convergesScore-o.convergesScore)/10.0
		}
		return -(200 + float64(o.convergesScore-c.convergesScore)/10.0)
	}
	if c.balanceScore != o.balanceScore {
		if c.balanceScore > o.balanceScore {
			return 150 + (float64(c.balanceScore-o.balanceScore))/10.0
		}
		return -(150 + (float64(o.balanceScore-c.balanceScore))/10.0)
	}
	if c.hasNonVoter != o.hasNonVoter {
		if c.hasNonVoter {
			return 100
		}
		return -100
	}
	// Sometimes we compare partially-filled in candidates, e.g. those with
	// diversity scores filled in but not balance scores or range counts. This
	// avoids returning NaN in such cases.
	if c.rangeCount == 0 && o.rangeCount == 0 {
		return 0
	}
	if c.rangeCount < o.rangeCount {
		return float64(o.rangeCount-c.rangeCount) / float64(o.rangeCount)
	}
	return -float64(c.rangeCount-o.rangeCount) / float64(c.rangeCount)
}