Hot answers tagged

13

Why is it confusing? The javadoc for HashMap.put clearly states: Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced. It clearly states what happens when you do a put with a key which was already in the map. The specific case of key == null behaves in the ...


11

map is a fairly well-rounded dictionary-type container that provides several advantages over std::list (linked lists) and std::vector (arrays). Although its not strictly specified, the performance constraints required on a map pretty much forces it to be implemented as some kind of self-balancing binary tree. So if its helpful to you to think about it in ...


10

Exagg'itive Summary (TM) You get a few things. Prototypal inheritance and cloning Dynamic addition of new properties Co-existence of objects of different versions (specification levels) of the same class. Objects belonging to the more recent versions (specification levels) will have extra "optional" properties. Introspection of properties, old and new ...


9

Hash functions are used to convert the input (usually string) to a smaller fixed length (typically) "hashed value" which typically is used somewhat like a array index for the hash table. Ideally this value should be evenly spread throughout its range, and avoid any obvious/significant concentrations. A hash function is any algorithm or subroutine that ...


9

http://gadm.org/ seems to have exactly what you want (and more). GADM database of Global Administrative Areas GADM is a spatial database of the location of the world's administrative areas (or adminstrative boundaries) for use in GIS and similar software. Administrative areas in this database are countries and lower level subdivisions such as ...


8

The definition from wikipedia seems correct and general enough: collection of unique keys and a collection of values, where each key is associated with one value (or set of values) Not a word about order. That should be perfectly fine, as there are many good ways to implement data structures that are perfect associative arrays, only without the "...


7

The programming uses of the verb "map" and the noun "mapper" are largely unrelated to their common uses in English, so this is a very understandable question. The programming use is also very broad, so let's start with the most concrete and well-defined meaning of "map". Namely, the higher-order map function present in most functional programming languages. ...


6

That's an excellent talk by someone who really knows what he's talking about. I recommend readers watch the entire thing. It's only 36 minutes long. One of his main points is that simplicity opens opportunities for change later on. Choosing a class to represent a Person provides the immediate benefit of creating a statically-verifiable API, as you ...


6

Scala is an object-oriented language. In object-oriented languages, methods have special access to a designated "receiver" argument (typically called this or self). This parameter is usually not made explicit in the method signature (Python is an exception). So, you have to remember that the map method is actually defined as a member of a trait or class and ...


5

The best way to approach this is to go to FP Complete's Hoogle and type in the signature you're looking for, (a -> Maybe b) -> [a] -> Maybe [b]. The first hit is a function called mapM which is exactly what you are looking for. In fact it works for all Monads, not just Maybe. (If you want to be even more general you can use traverse)


5

An adapter strategy sounds good enough for this case, i.e., define a common interface and then proceed to implement that interface for each provider. The choice for which map provider to use can be a configurable option in the settings. Also see Mapstraction, a JavaScript library that provides a common interface for several map providers, including Google, ...


5

You want a function with this signature: (a -> Maybe b) -> [a] -> Maybe [b] Entering this into hoogle gives this possibility: Prelude mapM :: Monad m => (a -> m b) -> [a] -> m [b] A look at the Hackage documentation for mapM says it is the same as: mapM f = sequence . map f and that the definition of sequence is: sequence ...


5

If the Map is a HashMap, it will use the Pair's hashCode() and equals() methods to determine equality. These methods can be overridden. The important part is making sure that the order of items doesn't matter. For hashCode(), this can be achieved by xor-ing the hash codes of the pair elements. For equals(), the items must be pairwise equal, or pairwise equal ...


4

It seems to me that the main issue is only including nodes that add significant information about a road. i.e. without your GPS requirement, you could just store nodes at junctions and endings (which I think you call start/end nodes). Obviously including weight/costs etc. One way I can think of approaching this is to first, add all start/end nodes. This is ...


4

The Google Maps API licensing page explains this fairly well, to summarise, there are three types of license: Google Maps API The Google Maps API is a free service that lets you embed Google Maps in your freely accessible web pages or mobile apps. Your service must be freely and publicly accessible to end users. Google Maps API for Business Google ...


4

There is an implementation of MVC objects in Google Maps JavaScript API V3. It allows map objects to store state and update their presentation automatically. There is a DEMO of moving and resizing a circle which may provide what you require. The full tutorial can be seen HERE


4

The decompiler probably has problems in decompiling class names correctly that contain a $ symbol. The symbol you are searching for is named Predef$: import scala.Predef; import scala.Predef$; import scala.Tuple2; import scala.collection.immutable.Map; import scala.collection.mutable.WrappedArray; public class T { @SuppressWarnings({ "rawtypes", "...


4

Your problem lends very nicely to the Command design pattern. So basically you will have a base Command interface and then there would be multiple CommandImpl classes that would implement that interface. The interface essentially needs to just have a a single method doCommand(Args args). You can have the arguments passed in via an instance of Args class. ...


4

This answer is merely provided to reduce the frustration. In general, a person is better advised to learn how to conduct performance benchmarking properly before asking such a question. If your "keys" exclusively consist of consecutive integers, you can use an integer array. Zero-based consecutive integers can be used as array index as-is. Non-zero-based ...


3

Fairly straightforward steps: Include boilerplate generic warnings, as you might see in many other pieces of software, and include them as part of a license agreement for users to agree to before they use your software Add a specific clause to the license agreement, informing users that you are not responsible for the map data that you're providing, and ...


3

If you're using Python 2.x, then that's easily achievable by using cmp, although you have to modify your function to return -1 instead of 0. Something like this: def greater(a, b): if (a % b) % 2 == 0: return 1 return -1 x = [2,7,5,10,30,15] print(sorted(x, cmp=greater)) But if you're using Python 3.x, then it gets a bit more complicated ...


3

As far as I know, usage of Google Maps for desktop apps is forbidden. (Scratch that, it's now OK, so long as it's a publicly available and downloadable app - will rewrite this answer.) If you want this to run within a native desktop application - and not in a normal brower connecting to a web-app, though that could also be one way of doing it - you'll need ...


3

For most purposes the classes from the standard library are likely to outperform any quickly-put-together data structure / container / algorithm you will write. This is assuming you choose the right abstraction (std::vector and std::list have different trade-offs, for example). A lot of time and effort by a lot of smart people has gone into making those ...


3

Your solution 1 may be problematic, as the hashmap is static and will be initialised only once, and is shared by all instances of your class. Is this your intended behavior or you want each instance have its own map? If you one only one map, I would suggest to pass the set to the constructor instead of using a static one, for example: public class Data { ...


3

It depends on the map. Cartographic maps are projections of a (nearly) spherical surface onto a flat, two dimensional surface. That is: (X, Y) = Fproj(Lat, Long) where Fproj() is the projection function. For instance, for a standard Mercator projection with the X axis on the equator, and the Y axis at the 0 Meridian: X = Longitude Y = ln(tan(Latitude) + ...


3

It's a mathematical concept. www.thefreedictionary.com 2. Mathematics The correspondence of elements in one set to elements in the same set or another set. It's to establish a correspondence between two distinct data models. For example, you can say thay the class User is a representation of a row of the database table USER, that would be object-...


2

This will require you to access some database(s) which hold maximum allowed speeds for each road. Looking to purchase such information can turn out to be quite costly, especially if you want to cover wide areas. Combining several different data sources can also result in some extra required effort. Probably it's best to use an existing service, like Google ...


2

I am not aware of any mapping libraries that support highlights outright but if you want to do this with Google Maps or Yahoo GeoService then you can simply record the latitude and longitude of the bounds of the highlight area in a database. On loading the map again, you can restore the highlight area from those bounds by rendering points using the lat/long....


2

No. Your function does not give consistent answers on how to sort numbers, because greater(x, y) != not greater(y, x) for some values of x and y. For example (3 % 4) % 2 == 1, and (4 % 3) % 2 == 1 also! This means that 3 > 4 AND 3 < 4, which is nonsense. If you convert it to a cmp-style function like @SystemDown suggests, you will get inconsistent ...



Only top voted, non community-wiki answers of a minimum length are eligible