spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

Optimization of Rectangle-based Point Search


At this point, is it still more efficient to use the HashMap (in consideration of generation and access) or should another method be used, such as a set of 2-D interval trees?

Nobody can tell except the one who did a measurement. It all depends on how often you need to update the data, how often they change, and how often they get queried.

And also on the size of a Room. With a few points, the HashMap wins in a typical scenario, with thousands of them, the overhead of updating the points dominates.


Can't you use an array for all Points? If so, then it'll be surely way faster then the HashMap, especially for updating (unless it gets really huge).


This may or may not be useful.

Actually, not only each Room has some Points, but also each Point may have one Room (n:1). How it gets implemented, it's a different question.

Given this, we have a standard problem: If you link bidirectionally, then you have to keep both links in sync. The simplest solution is to make the setters ("adders"/"removers") as private as possible and only called them from a method

void link(Room room, Point point) {
    Room oldRoom = point.getRoom();
    if (oldRoom!=null) oldRoom.removePoint(point);
    room.addPoint(point);
    point.setRoom(room);
}

Your linking from Point to Room is external, but this hardly changes anything (except for keeping Point smaller and possibly cleaner and adding the tiny overhead of a HashMap to each access).

It's usually also the fastest as usually there are much more queries than updates. Your problem is that the update cost gets scaled up by the Room size. Without you telling us some figures, no estimate is possible.


With too many points and rooms of not too widely varying size, you could round the point coordinates to a multiple of some n and keep an array holding the set of all rooms intersecting the grid. You could proceed as before, but the update overhead would be lower by nearly a factor given by the room area(*) and the search overhead higher, as you'd have to select the really matching room (if any) from the set.

(*) For rooms not aligned to grid, the number of intersecting rectangles is obviously higher.


Categories : Java

Related to : Optimization of Rectangle-based Point Search
How to extract value from one sheet based on search criteria in another in Google Script?
Not sure what you want to achieve here. If this 'lookup' is part of a wider onFormSubmit, you can create a fuction that is called when needed, passing in the ID and the spreadsheet. function yourMainFunction() { var ss = ... var id = var email = lookupEmail(id, ss) .... ... } function lookupEmail(id, ss) { var lookupSheet = ss.getSheets()[1]; //second sheet

Categories : Google Apps Script
Why does this point-free F# function behave differently from the non-point-free version?
getValFromMapPartial is a true syntactic function. Its signature is val getValFromMapPartial : key:string -> int. Whenever it is called, it uses the current value of someMap. That's why it works in your example; it accesses the version of someMap who has an entry. On the other hand, getValFromMapPartialAndTacit is a lambda-computing function. Its signature is val getValFromMapPartialAndTacit :

Categories : F#
Performance optimization in R
This might be a littler faster... not sure why you were calculating n. calc=function(response, groundTruth, classes, threshold) { type1 = classes[1] type2 = classes[2] predicted = as.factor(ifelse(response<threshold,type1,type2)) I = groundTruth==type1 fp = sum(predicted[I] != type1) / sum(I) I = groundTruth==type2 tp = sum(predicted[I] == type2) / sum(I) return

Categories : R
Add rectangle to highchart
Solution is to use chart.x/yAxis[0].toPixels(value). That will translate from value on a chart, to pixel position: http://jsfiddle.net/qnp5tg0h/1/ var chart = new Highcharts.Chart(options); var x1 = chart.xAxis[0].toPixels(0), x2 = chart.xAxis[0].toPixels(20), y1 = chart.yAxis[0].toPixels(0), y2 = chart.yAxis[0].toPixels(25); chart.ren

Categories : Javascript
iPhone 6/6+ optimization issue
I have found solution for question #1 from iOS 8 NavigationBar BackgroundImage EDITED after @RoboticCat answer UIEdgeInsets stretchablePart = { .left = 0, .right = 50, .top = 0, .bottom = 0 }; [[UINavigationBar appearance] setBackgroundImage:[[UIImage imageNamed:@"navBar"] resizableImageWithCapInsets:stretchablePart resizingMode:UIImageResizingModeStretch] forBarMetrics:UIBarMetricsDefault]; w

Categories : IOS
Recently Add
Redirecting the output directory of 'mvn package' or 'mvn compile' command
No suitable constructor found for ProductoExtranjero
java Composite design pattern(Directory &File)
Java JTree's ui refresh after removing node from parent
First REST Spring application
How to cancel Indexing of a Solr document using Update Request Processor
PowerMock - Mock a Singleton with a Private Constructor
Calling a Postgres stored function SQL error
Where to store Morphlines Java custom command class?
Generic repository using map
How can I scroll a ScrolledComposited in Eclipse SWT Design view?
2 Frames/layout in 1 Activity
Writing a switch differently
Next button opens another activity when its reaches the array limit
Is EclipseLink MOXy capable of applying JSR-303 Bean Validation when unmarshalling XML to object?
Why my jdk can't work,and before the java_home, there is a space that is not from me
How to add List of objects in a Map
How to make notepad++ function like regular notepad in cmd?
Cell renderer and the lost focus
how can I implement iterable for LinkedList>
Disable Androids image-crunch in eclipse (run as) builds
java 8 lambda myMap.stream().count() != myMap.size() after merging myMap
Issue with Calendar calculation that spans 2 calendar years
JSF 2.0 Spring bean injection
Java Regex ReplaceAll with grouping
Getting any word and last word using sed
Clicking on link on JEditorPane throws IOException
printing out difference of two arrays
Spring Bean Alias in JavaConfig
Using Factory Method to Create Generics
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.