MultiDimension
A tool to help an application execute multi-dimensional range queries.
The algorithm used is database independent, the only requirement
is that the engine supports a range index (for example b-tree).
Methods |
static MultiDimension |
getInstance()
Get the singleton.
|
static MultiDimension |
getInstance()
Get the singleton.
Returns:
the singleton
|
int |
compare(long[] a, long[] b)
|
int |
compare(long[] a, long[] b)
|
int |
deinterleave(int dimensions, long scalar, int dim)
Gets one of the original multi-dimensional values from a scalar value.
|
int |
deinterleave(int dimensions, long scalar, int dim)
Gets one of the original multi-dimensional values from a scalar value.
Parameters:
dimensions - the number of dimensions
scalar - the scalar value
dim - the dimension of the returned value (starting from 0)
Returns:
the value
|
String |
generatePreparedQuery(String table, String scalarColumn, String[] columns)
Generates an optimized multi-dimensional range query.
|
String |
generatePreparedQuery(String table, String scalarColumn, String[] columns)
Generates an optimized multi-dimensional range query. The query contains
parameters. It can only be used with the H2 database.
Parameters:
table - the table name
columns - the list of columns
scalarColumn - the column name of the computed scalar column
Returns:
the query
|
int |
getMaxValue(int dimensions)
Get the maximum value for the given dimension count.
|
int |
getMaxValue(int dimensions)
Get the maximum value for the given dimension count. For two dimensions,
each value must contain at most 32 bit, for 3: 21 bit, 4: 16 bit, 5: 12
bit, 6: 10 bit, 7: 9 bit, 8: 8 bit.
Parameters:
dimensions - the number of dimensions
Returns:
the maximum value
|
ResultSet |
getResult(PreparedStatement prep, int[] min, int[] max)
Executes a prepared query that was generated using generatePreparedQuery.
|
ResultSet |
getResult(PreparedStatement prep, int[] min, int[] max) throws SQLException
Executes a prepared query that was generated using generatePreparedQuery.
Parameters:
prep - the prepared statement
min - the lower values
max - the upper values
Returns:
the result set
|
long |
interleave(int... values)
Convert the multi-dimensional value into a one-dimensional (scalar)
value.
|
long |
interleave(int... values)
Convert the multi-dimensional value into a one-dimensional (scalar)
value. This is done by interleaving the bits of the values. Each values
must be between 0 (including) and the maximum value for the given number
of dimensions (getMaxValue, excluding). To normalize values to this
range, use the normalize function.
Parameters:
values - the multi-dimensional value
Returns:
the scalar value
|
long |
interleave(int x, int y)
Convert the two-dimensional value into a one-dimensional (scalar) value.
|
long |
interleave(int x, int y)
Convert the two-dimensional value into a one-dimensional (scalar) value.
This is done by interleaving the bits of the values.
Each values must be between 0 (including) and the maximum value
for the given number of dimensions (getMaxValue, excluding).
To normalize values to this range, use the normalize function.
Parameters:
x - the value of the first dimension, normalized
y - the value of the second dimension, normalized
Returns:
the scalar value
|
int |
normalize(int dimensions, double value, double min, double max)
Normalize a value so that it is between the minimum and maximum for the
given number of dimensions.
|
int |
normalize(int dimensions, double value, double min, double max)
Normalize a value so that it is between the minimum and maximum for the
given number of dimensions.
Parameters:
dimensions - the number of dimensions
value - the value (must be in the range min..max)
min - the minimum value
max - the maximum value (must be larger than min)
Returns:
the normalized value in the range 0..getMaxValue(dimensions)
|
|