Exemple #1
0
		}

		var idx *bitindex.Index

		if idx, err = bitindex.LoadIndex(f); err != nil {
			cmd.Println("Error loading index file:", err)
			os.Exit(1)
		}

		http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
			w.Header().Set("content-type", "application/json")

			v := map[string]interface{}{
				"domain_size":    idx.Domain.Size(),
				"table_size":     idx.Table.Size(),
				"index_sparsity": idx.Sparsity(),
			}

			if err := json.NewEncoder(w).Encode(v); err != nil {
				w.WriteHeader(http.StatusInternalServerError)
				fmt.Fprint(w, err)
				return
			}
		})

		http.HandleFunc("/query", func(w http.ResponseWriter, r *http.Request) {
			w.Header().Set("content-type", "application/json")

			// Expected up to 4 keys, one for each operator.
			q := query{}
Exemple #2
0
	Use: "stats <index>",

	Short: "Outputs the stats of a bitindex.",

	Run: func(cmd *cobra.Command, args []string) {
		if len(args) != 1 {
			cmd.Println("An index file is required.")
			os.Exit(1)
		}

		f, err := os.Open(args[0])

		if err != nil {
			cmd.Println("Error opening file:", err)
			os.Exit(1)
		}

		var idx *bitindex.Index

		if idx, err = bitindex.LoadIndex(f); err != nil {
			cmd.Println("Error loading index file:", err)
			os.Exit(1)
		}

		cmd.Println("Statistics")
		cmd.Println("* Domain size:", idx.Domain.Size())
		cmd.Println("* Table size:", idx.Table.Size())
		cmd.Println("* Sparsity:", idx.Sparsity()*100)
	},
}