문제

I've created many Geodata objects (name,postalCode,lat,lon). Now I want to put them into a collection to search for different entries later.

Everything should happen objectOriented/in-memory, so there shouln't be a need for a relational database.

Such a Query looks like:

  • Find lat and lon by name or plz
  • Find objects between LAT1,LAT2 and LON1,LON2

What collection is the best one for such a "simple" datastructure?

What complexity is needed for such a query? Can multithreading be a benefit? If it is, which collection is used at best for thread safety?

Is there a chance to write such queries in a key=>value database?

도움이 되었습니까?

해결책

You could use an in-memory database.

This is good as relational databases are good for relational queries like these.... :-)


For home-made pure Java, you could use:

  1. Map, with the name as key
  2. Map, with the plz as key
  3. List<List<"object">> with LAT for the first list, LON for the second list.
    Both are sorted, so for each you can search for a value using binary-search, and return an interval efficiently with subList.

This amounts to a duplication for the keys, but not for all objects, as you can reuse the same instance objects in all of these cases.

Multi-threading is acceptable (if your need it for other reasons), but I doubt you need to introduce it to improve the performance of a single search. The data structures mentioned should deliver the correct answers in less than a millisecond !

Thread-safety is not a problem for these data structures, as your use case seem to be read-only. If you need to modify the "objects" in some case, then you can only protect the "objects" themselves, not the data structures used for searching.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top