ojrsticky.blogg.se

Triplea map creator program
Triplea map creator program













Then write whatever implementation you can write the fastest and just move on.ONLY once you have written your application and you have found that your composite key implementation does not filter on the first key very fast, or that the map of maps is taking too much memory should you go and optimise.Premature optimisation is the root of all evil.Not abstracting is worse.

Triplea map creator program

Create a DoubleKeyedMap interface with all the methods you need on it and use that in your code. They do not differ in their functionality: They both take two values and return the previously 'put' value.As they are functionally equivalent, the first thing you should do is to abstract over them. This is less to do with 'what implementation is best' and more to do with 'what abstraction should I be working with'.Both the composite key and the map of maps have their strengths and their weaknesses, all of which reside within the domain of performance (ie, speed/memory usage). Getting all prices for a specific key component for instance, but you're more likely to query that result straight from the database rather than distilling it from the Map. Let me provide the loyal opposition:Composite map keys work great when you're looking up a specific known item.Nested maps work well when you need to rapidly find all the variations, kinds, and subtypes of type A.

Triplea map creator program

Bowmore gives a pro argument for composite keys, and a con argument for nested maps.

Triplea map creator program

Both nested and combined keys have their places.

Triplea map creator program

So we had on the DB a table looking like this: PRICEStype AmountA 20B 15C.D.At first we only had 4 different types of prices, so in the code, we had something like this: Map prices = new HashMap Where the keys were the price type.Recently, they added a new business rule that adds 3 subtypes to every price type, so now we have something like this: PRICEStype subtype AmountA 1 20A 2 15A 3.B 1.B 2.Which of the following two options do you think is better and why? Nested Maps Map prices where the keys are the price type and subtype: prices.get(type).get(subtype) Combined KeysThe same map than originally: Map prices And concatenate the keys to index the different prices: prices.get(type+'+subtype). In the project I am currently working on we had three different types of prices depending on the age of the user (adult, child, etc.).















Triplea map creator program