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 api(api *gin.RouterGroup) {
	api.POST("/point", func(c *gin.Context) {
		p := point.Point{}
		err := c.Bind(&p)
		hash, err := hash.NewHashPoint(p)
		if err != nil || !p.IsValid() {
			c.JSON(http.StatusBadRequest, "Invalid point")
		} else {
			c.JSON(http.StatusOK, gin.H{
				"point":  p,
				"hash":   reverseString(hash.String),
				"zorder": reverseString(hash.GetZorder().HashString(32)),
			})
		}
	})

	api.POST("/hash", func(c *gin.Context) {
		hash := &hash.Hash{}
		err := c.Bind(&hash)
		hash.String = reverseString(hash.String)
		if err != nil || hash.InitFromString() != nil {
			c.JSON(http.StatusBadRequest, "Invalid hash")
		} else {
			c.JSON(http.StatusOK, gin.H{
				"hash":   reverseString(hash.String),
				"point":  hash.GenPoint(),
				"zorder": reverseString(hash.GetZorder().HashString(32)),
			})
		}
	})
}
Example #3
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)
}