Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LUCENE-8126: Spatial prefix tree based on S2 geometry #302

Closed
wants to merge 34 commits into from

Conversation

iverase
Copy link
Contributor

@iverase iverase commented Jan 10, 2018

No description provided.

Copy link
Contributor

@dsmiley dsmiley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey this looks super impressive Ignacio!

if (cellId == null) { //World cell
return tree.getSpatialContext().getWorldBounds();
}
return tree.s2ShapeFactory.getS2CellShape(cellId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you meant to cache to this.shape instead?

/**
* Cache level of cell.
*/
private void setLevel() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it'd be simpler of getLevel had this logic.... is the s2's cellId.level() not trivially fast and so you want to effectively cache it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method cellId.level() is probably efficient but because it can be called several times I think we are saving some ticks on the clock by caching it.

/*Tokens are used to serialize cells*/
private static final byte[] TOKENS;
/*Map containing mapping between tokens and integer values*/
private static final Map<Byte,Integer> PIXELS;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this map has a small set of fixed values that have numeric equivalents, perhaps we can do direct addressing into an array?

public Cell readCell(BytesRef term, Cell scratch) {
S2PrefixTreeCell cell = (S2PrefixTreeCell) scratch;
if (cell == null)
cell = (S2PrefixTreeCell) getWorldCell();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: our code style in Lucene/Solr is to always use braces

if (cellId == null){ // this is the world cell
children = FACES;
}
else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: our code style in Lucene/Solr is for an else statement to be on the same line as the previous closing brace

return;
}
int length = getLevel() + 1;
byte[] b = new byte[length];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the bref parameter may already have bytes that is of this length. If it is, reuse it thus avoiding object allocation. BytesRef exists to avoid object allocation and copying.

@Override
public boolean equals(Object o) {
S2PrefixTreeCell cell = (S2PrefixTreeCell)o;
if (cellId == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see Objects.equals(...)


@Override
public double getDistanceForLevel(int level) {
return S2Projections.MAX_WIDTH.getValue(level -1) * DistanceUtils.RADIANS_TO_DEGREES;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: put space after that minus operator

Point p = (Point) shape;
S2CellId id = S2CellId.fromLatLng(S2LatLng.fromDegrees(p.getY(), p.getX())).parent(detailLevel-1);
List<Cell> cells = new ArrayList<>(detailLevel);
for (int i=0; i < detailLevel -1; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: put a space after that minus operator

@@ -50,8 +53,20 @@
private RecursivePrefixTreeStrategy rptStrategy;

private void setupGeohashGrid() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is now named inappropriately

this.grid = new QuadPrefixTree(ctx, 5);//A fairly shallow grid
this.rptStrategy = newRPT();
}
else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove CR

@@ -29,6 +29,8 @@
<artifact name="spatial4j" type="test" ext="jar" maven:classifier="tests" />
</dependency>

<dependency org="io.sgr" name="s2-geometry-library-java" rev="1.0.0" conf="test"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead you're supposed to reference the version via ivy-versions.properties. Also run "ant jar-checksums" to add the checksum file.

@dsmiley
Copy link
Contributor

dsmiley commented Feb 28, 2018

BTW when you're finally ready to merge into master & 7.3 please add just one commit with all these changes; don't rebase or merge all these commits onto the ASF git repo. This will keep the history clean/simple.

@iverase iverase closed this Mar 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants