Questions tagged [treemap]

An implementation of a mapping (dictionary) using a tree. This tag is also used for treemapping, an information visualization method for displaying hierarchical data with nested rectangles.

A map implemented as a tree

A map (also called dictionary or associative array) can be represented as a tree, typically a binary search tree. This tag can be used for such implementations, especially the TreeMap class in Java.

Treemapping visualisation technique

A treemap is a method for displaying tree-structured data in two dimensions. Each element is represented as a rectangle, with the children of a tree displayed as sub-rectangles inside their parent's rectangle.

Treemap example http://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/Tree_Map.png/305px-Tree_Map.png

1568 questions
16
votes
3 answers

how to encode this data to parent / children structure in JSON

I am working with d3.js to visualise families of animals (organisms) (up to 4000 at a time) as a tree graph, though the data source could just as well be a directory listing, or list of namespaced objects. my data looks like: json = { …
johowie
  • 2,475
  • 6
  • 26
  • 42
14
votes
5 answers

Avoiding TreeMap ConcurrentModificationException?

I am calling function that returns TreeMap instance, and in the calling code I wanted to modify the TreeMap. However, I am getting a ConcurrentModificationException. Here is my code: public Map function1() { Map
Nagappa L M
  • 1,452
  • 4
  • 20
  • 33
13
votes
8 answers

A TreeSet or TreeMap that allow duplicates

I need a Collection that sorts the element, but does not removes the duplicates. I have gone for a TreeSet, since TreeSet actually adds the values to a backed TreeMap: public boolean add(E e) { return m.put(e, PRESENT)==null; } And the TreeMap…
Zeeshan
  • 11,851
  • 21
  • 73
  • 98
13
votes
5 answers

What is 'natural ordering' in a TreeMap?

Possible Duplicate: How can I sort the keys of a Map in Java? In class TreeMap the Java API says: A Red-Black tree based NavigableMap implementation. The map is sorted according to the natural ordering of its keys, or by a Comparator provided at…
John Threepwood
  • 15,593
  • 27
  • 93
  • 149
12
votes
1 answer

TreeMap collection views iterators time-complexity?

Time-complexity of all 3 collection view iterators for HashMap (myHashMap.entrySet().iterator().next() and myHashMap.keySet().iterator().next() and myHashMap.values().iterator().next()) is well-documented in javadoc, it is O(n+c) for all those 3…
12
votes
1 answer

Creating a custom d3 layout

I need to create a custom d3 layout that is somewhat close to a treemap but in a triangular style. Here's a screenshot so that you can understand: Pyramid layout As you can see, it works pretty neat and fits my need. To code it, i've based the code…
user1804450
  • 121
  • 1
  • 3
12
votes
2 answers

Adding a title attribute to svg:g element in D3.js

I'm building an app with D3.js that displays a data in a tree-map. Ideally what I would like to is give the tree-map a tool-tip to display more info on each node of the tree-map. The tree-map is fed data from a .JSON file. I am currently working…
accraze
  • 1,522
  • 7
  • 20
  • 46
11
votes
3 answers

sorting treemap based on key, where key is variable

I want to sort the tree map based on the key where key is a variable,so sorting should be based on variable value, How can we achieve this? I want use in built sort method rathar implementing it through code, any reply with example is of great help.…
sachin
  • 115
  • 1
  • 1
  • 8
11
votes
5 answers

How to retrieve the key with a maximum value in a TreeMap in Java?

I have a tree map declared as follows: TreeMap tree = new TreeMap(); How do I retrieve the key with the maximum value. Is there an O(1) way of achieving this. I know that maximum and minimum keys can be retrieved…
Spider Man
  • 415
  • 4
  • 10
  • 26
11
votes
3 answers

Can I use images as the background rectangles for d3 treemaps?

Is it possible to make a treemap in d3 with the background of each rectangle be an image? I am looking for something similar to what was done in Silverlight here, but for d3. If it is possible, are there any recommended tutorials that walk through…
Matt
  • 113
  • 1
  • 1
  • 5
11
votes
4 answers

Why Doesn't Java's TreeMap Allow an Initial Size?

Loading 1 000 000 numbers takes 2 seconds to load into a treemap (binary search tree), but takes milliseconds to load into a hashmap (in java). The only difference between the two is that I can see is I can set a hashmap's initial size so it does…
user2316667
  • 5,444
  • 13
  • 49
  • 71
11
votes
1 answer

Scala: Why does SortedMap's mapValues returns a Map and not a SortedMap?

I'm new to Scala. I'm using SortedMap in my code, and I wanted to use mapValues to create a new map with some transformation on the values. Instead of returning a new SortedMap, the mapValues function returns a new Map, which I then have to convert…
Oren
  • 2,767
  • 3
  • 25
  • 37
11
votes
4 answers

TreeSet internally uses TreeMap, so is it required to implement Hashcode method when using Treeset?

I would like to know what it means when javadocs for TreeSet says This class implements the Set interface, backed by a TreeMap instance? In the below example, I haven't implemented the Hashcode method and still it is working as per expectation…
Metalhead
  • 1,429
  • 3
  • 15
  • 34
10
votes
2 answers

Is there a Scala version of NavigableMap?

In Java 1.6, the NavigableMap (and the NavigableSet) interfaces were introduced and TreeMap was updated to implement the new interface. Among other things, NavigableMap is useful for asking questions like "Which element in the collection is closest…
Jim Hurne
  • 7,187
  • 4
  • 44
  • 44
10
votes
5 answers

Best way to store Country codes, names, and Continent in Java

I want to have a List or Array of some sort, storing this information about each country: 2 letter code Country name such as Brazil Continent/region of the world such as Eastern Europe, North America, etc. I will classify each country into the…
Ali
  • 261,656
  • 265
  • 575
  • 769