示例#1
0
func TestPriorityQueueRemove(t *testing.T) {
	input := make([]int64, 5, 5)
	input[0] = 3
	input[1] = 4
	input[2] = 1
	input[3] = 20
	input[4] = 13
	expectedResult := make([]int64, 3, 3)
	expectedResult[0] = 3
	expectedResult[1] = 4
	expectedResult[2] = 20
	testQueue := utils.NewInt64PriorityQueue()
	for _, value := range input {
		testQueue.Enqueue(value, value)
	}
	testQueue.Remove(1)
	testQueue.Remove(13)
	if testQueue.Size() != len(expectedResult) {
		t.Errorf("priorityQueue is not the correct size expected length: %v, actual length: %v", len(input), testQueue.Size())
	}
	for i, expectedValue := range expectedResult {
		actualValue := testQueue.Poll()
		if actualValue != expectedValue {
			t.Errorf("priorityQueue did not output the correct value at index: %v, expected: %v, actual %v.", i, expectedValue, actualValue)
		}
	}
}
func NewKHHCountMinSketch(m int) *KHHCountMinSketch {
	k := int(float64(m) * math.Log(float64(m)))
	seed := int64(time.Now().UnixNano() / int64(time.Millisecond))
	items := make(map[int64]int64)
	var sketchTable [depth][width]int64
	hashVector := make([]int64, depth)
	random := rand.New(rand.NewSource(seed))
	for i := 0; i < depth; i++ {
		hashVector[i] = random.Int63n(math.MaxInt64)
	}
	result := new(KHHCountMinSketch)
	result.k = k
	result.items = items
	result.sketchTable = sketchTable
	result.width = width
	result.depth = depth
	result.size = 0
	result.hashVector = hashVector
	result.priorityQueue = utils.NewInt64PriorityQueue()
	result.topCentroid = nil
	return result
}