Created
February 3, 2016 22:40
-
-
Save mithuns/15d4f76da6ff4ac8e0e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is the text editor interface. | |
// Anything you type or change here will be seen by the other person in real time. | |
//phones sending locations- sent every n seconds, package may get drop or arrive out of order, given a timestamp, find out the last location of that driver. | |
// <x,y> 3 <x1,y1> 5 | |
// 4 -> <x,y> | |
// 5,4,3,2,1 | |
//3:30 pm | |
class Location{ | |
double latitude; | |
double longitude; | |
//getters and setters | |
//constructor | |
} | |
class LocationMsg{ | |
private String driverId; | |
private Location loc; | |
private DateTime datetime; | |
} | |
public class LastLocation{ | |
LocationMsg[] locationData; | |
LoationHeap<LocationMsg> heap; | |
public Location getLastLocation(DateTime lastTime, String driverId) { | |
while(heap.findMax().getTime() > lastTime){ | |
} | |
LocationMsg location = heap.findMax(); | |
return location.loc; | |
} | |
public void setLocation(String driverId, Location lastLocation, DateTime timestamp) { | |
//create heap | |
//adding to the heap | |
LocationMsg locMsg = new LocationMsg(driverId,lastLocation,timeStamp); | |
//first time | |
if(heap.getHeapSize()==0){ | |
heap = LocationHeap.crateHeap(locMsg); | |
}else{ | |
addToHeap(locMsg); | |
} | |
} | |
} | |
class Client{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment