Struct hilbert::point::Point[][src]

pub struct Point { /* fields omitted */ }
Expand description

An immutable, N-dimensional point with unsigned integer coordinates and an optimized distance function.

If the Point was created using make_points_i32 or make_points_f64 from the point_list module, or if the caller took special care to ensure the coordinate values are in the desired range for the Hilbert Curve, then the Point is fit to be converted into a Hilbert Index using the hilbert_transform method.

Use hilbert_sort if you are uninterested in the Hilbert Index and merely need many points sorted by the index.

Examples

        use crate::hilbert::point::Point;
        use crate::hilbert::point_list;
 
        // 1. Create two 3-D points and get the square of the distance between them.
        let p1 = Point::new(0, &[3, 4, 5]);
        let p2 = Point::new(1, &[0, 8, 10]);
        let sqr_dist = p1.square_distance(&p2);
        assert!(sqr_dist == 50, "Square distance should be 50");
 
        // 2. Perform the Hilbert Transform on a single point,
        //    using 5 bits per dimension (which assumes no coordinate exceeds 31).
        let index1 = p1.hilbert_transform(5);
 
        // 3. Create several points and normalize them.
        //    This will ensure that the ids begin at zero and that all values
        //    are multiplied by 10.0 before being rounded to the nearest integer,
        //    to preserve the predetermined precision.
        let point_data : Vec<Vec<f64>> = vec![
           vec![-10.5, 5.27, 3.66],
           vec![-4.802, 20.2, 100.19],
           vec![42.0, -100.0, 0.0]
        ];
        let (mut points, bits) = point_list::make_points_f64(&point_data, 0, None, None, 10.0);
 
        // 4. Sort the points by the Hilbert Curve, using 11 bits per dimension,
        //    because the range of data is 200.19, multiplied by the scale of 10 
        //  yields 2001.9, ceiling of that yields 2002, which is between 1024 (2^10) 
        //  and 2048 (2^11), so 11 bits are required to store the 
        //  highest coordinate value.
        Point::hilbert_sort(&mut points, 11);

Implementations

Construct a new Point with the given id.

Note: It is the caller’s duty to ensure that ids remain unique.

Apply a permutation to the Point to generate a new Point where the coordinate values have been reordered, but the id is the same.

Number of dimensions for the Point.

Gets the id for the Point.

Gets the coordinate values for the point.

Square of the Cartesian distance between the two points. This is optimized by using the following algebra:

 
 //    (A - B)² = A² + B² - 2·A·B

If you extend this to entire vectors, then:

  • A² is the square magnitude of vector A,
  • B² is the square magnitude of vector B,
  • 2·A·B is twice the dot product of A and B. This saves about N subtractions.

For the purpose of demonstrating benchmark improvement compared to square_distance_no_loop_unrolling.

For the purpose of demonstrating benchmark regression compared to square_distance_loop_unrolling.

Compares the coordinates of the two Points to see if they match in value and sequence.

This comparison ignores the ids of the Points.

Perform a Hilbert transform from a single N-dimensional point to a 1-Dimensional index.

  • bits_per_dimension - Number of bits used to encode each coordinate of the Point. This value must be at least one. The BigUint Hilbert Index for the Point will be composed of enough bytes to hold N * bits_per_dimension bits, where N is the number of points. If any coordinate of the Point has a value c >= 2^ bits_per_dimension, results are undefined and will be incorrect.

Note: This should not be called for Points with fewer than two dimensions.

Create a point from its Hilbert index, by performing the inverse Hilbert transform.

  • hilbert_index - One-dimensional distance along the Hilbert curve to get to the desired N-Dimensional point.
  • bits_per_dimension - Number of bits used to encode each coordinate of the Point. This value must be at least one. The BigUint Hilbert Index for the Point will be composed of enough bytes to hold N * bits_per_dimension bits, where N is the number of points. If any coordinate of the Point has a value c >= 2^ bits_per_dimension, results are undefined and will be incorrect.
  • dimensions - number of dimensions in the point.

Sort a collection of Points in ascending Hilbert Index order.

This method discards the Hilbert indices when done.

  • points - Points to sort.
  • bits_per_dimension - Number of bits used to encode each dimension. The BigUint Hilbert Index for each point will be composed of enough bytes to hold N * bits_per_dimension bits, where N is the number of points. If any coordinate of any Point has a value c >= 2^ bits_per_dimension, results are undefined and will be incorrect.

The points are sorted in place.

Sort a collection of Points in ascending Hilbert Index order after applying a Permutation to each point. This has the effect of generating a rotated or reflected Hilbert curve. For N-dimensional points, there are N! variations of the Hilbert curve that can be generated in this way. One curve among these may be more useful than another for a given purpose.

This method discards the Hilbert indices when done.

  • points - Points to sort.
  • bits_per_dimension - Number of bits used to encode each dimension. The BigUint Hilbert Index for each point will be composed of enough bytes to hold N * bits_per_dimension bits, where N is the number of points. If any coordinate of any Point has a value c >= 2^ bits_per_dimension, results are undefined and will be incorrect.
  • permutation - Defines how to reorder the many coordinates in a repeatable way.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

To remain consistent with equals, this incorporates the id and square_magnitude into the hash.

Feeds a slice of this type into the given Hasher. Read more

Define equality to only compare the id and square_magnitude, for speed.

Note: To compare all the coordinate values, use are_coordinates_identical instead.

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.