Example #1
0
func RunMaxDistancepLng(n, p int) {
	fmt.Printf("\nRunning %v iterations, using %v MAX DISTANCE LNG points...", n, p)
	resultsHilb := make([]float64, n)
	resultsZ := make([]float64, n)
	levenshteinDiff := make([]float64, n)
	for i := 0; i < n; i++ { //Repeat n times
		h1 := make([]hash.Hash, p/2)
		h2 := make([]hash.Hash, p/2)

		rand.Seed(time.Now().UTC().UnixNano())

		for i := 0; i < p/2; i++ { // Create p/2 amount of points on one side
			randLat := rand.Float64() * point.MAX_LATITUDE
			randLng := 1.0 * point.MAX_LONGITUDE
			p := point.NewPoint(randLat, randLng, 0, 0)
			hash, _ := hash.NewHashPoint(p)
			h1[i] = hash
		}
		for i := 0; i < p/2; i++ { // Create p/2 amount of points on other side
			randLat := rand.Float64() * point.MAX_LATITUDE
			randLng := -1.0 * point.MAX_LONGITUDE
			p := point.NewPoint(randLat, randLng, 0, 0)
			hash, _ := hash.NewHashPoint(p)
			h2[i] = hash
		}

		resultsHilb[i], resultsZ[i] = compareHashes(h1, h2, false)
		levenshteinDiff[i] = compareLevenshtein(h1, h2, false)
	}
	PrintResults(resultsHilb, resultsZ, levenshteinDiff)

}
Example #2
0
func (h Hash) GenPoint() point.Point {
	reslng, reslat := float64(0), float64(0)
	lat, lng := float64(point.MAX_LATITUDE), float64(point.MAX_LONGITUDE)
	errLat, errLng := float64(point.MAX_LATITUDE), float64(point.MAX_LONGITUDE)
	for i := uint64(0); i < h.zorder.Len(); i += 2 {
		lng /= 2
		lat /= 2
		errLat /= 2
		errLng /= 2
		switch h.zorder.GetPair(i) {
		case 3:
			reslat += lat
			reslng += lng
		case 2:
			reslat -= lat
			reslng += lng
		case 1:
			reslat += lat
			reslng -= lng
		case 0:
			reslat -= lat
			reslng -= lng
		}
	}
	return point.NewPoint(reslat, reslng, errLat, errLng)
}
Example #3
0
func BenchmarkHash(b *testing.B) {
	rand.Seed(time.Now().UTC().UnixNano())
	latVals := make([]float64, b.N)
	lngVals := make([]float64, b.N)
	for i := 0; i < b.N; i++ {
		latVals[i] = rand.Float64() * 90
		lngVals[i] = rand.Float64() * 180
	}

	b.ResetTimer() // Start benchmark after setup
	for i := 0; i < b.N; i++ {
		p := point.NewPoint(latVals[i], lngVals[i], 0, 0)
		NewHashPoint(p)
	}

}
Example #4
0
func TestHash(t *testing.T) {
	assert := assert.New(t)
	rand.Seed(time.Now().UTC().UnixNano())
	n := 100000

	hashes := make([]Hash, n)

	for i := 0; i < n; i++ {
		lat := rand.Float64() * point.MAX_LATITUDE
		lng := rand.Float64() * point.MAX_LONGITUDE
		p := point.NewPoint(lat, lng, 0, 0)
		hash, err := NewHashPoint(p)
		hashes[i] = hash
		assert.Nil(err, "Err should be nil")
		assert.True(hash.GenPoint().WithinErr(p), "Hash result-point should be within point error")
	}

}
Example #5
0
func RunRandomPoints(n, p int) {
	fmt.Printf("\nRunning %v iterations, using %v RANDOM points...", n, p)
	resultsHilb := make([]float64, n)
	resultsZ := make([]float64, n)
	levenshteinDiff := make([]float64, n)
	for i := 0; i < n; i++ { //Repeat n times
		hashes := make([]hash.Hash, p)
		rand.Seed(time.Now().UTC().UnixNano())

		for i := 0; i < p; i++ { // Use p amount of points
			randLat := rand.Float64() * point.MAX_LATITUDE
			randLng := rand.Float64() * point.MAX_LONGITUDE
			p := point.NewPoint(randLat, randLng, 0, 0)
			hash, _ := hash.NewHashPoint(p)
			hashes[i] = hash
		}

		resultsHilb[i], resultsZ[i] = compareHashes(hashes, hashes, true)
		levenshteinDiff[i] = compareLevenshtein(hashes, hashes, true)

	}
	PrintResults(resultsHilb, resultsZ, levenshteinDiff)
}