Is it safe to replace some of the treemap with hashmaps in Sable-3.7?

24 views
Skip to first unread message

p...@email.wm.edu

unread,
Nov 19, 2018, 11:39:59 AM11/19/18
to SableCC
Hi All,

I was wondering if it is safe to replace some of the treemaps with hashmaps in sable-3.7. Because I found the set and get operations of treemap take lots of execution time.

Etienne Gagnon

unread,
Nov 19, 2018, 11:50:56 AM11/19/18
to sab...@googlegroups.com
Hi,

It is safe for some collections, but not necessarily all. TreeMap
elements are sorted (when iterating over them). Sometimes, this order
matters. It's also inefficient to iterate over the elements of a
HashMap. There are LinkedHashMaps for efficient iteration, but element
ordering is then determined by insertion order instead of sort order.

One reason I've used TreeMaps (before LinkedHashMap was added to the
standard library) is so that problems could be reproduced, because
ordering is preserved from one execution to the next. But, you can
always try replacing them with LinkedHashMaps which also preserve
ordering from one execution to the next.

Have fun!

Etienne

Etienne Gagnon, Ph.D.
http://sablecc.org

p...@email.wm.edu

unread,
Nov 19, 2018, 12:09:23 PM11/19/18
to SableCC
Thanks for your prompt reply.
Reply all
Reply to author
Forward
0 new messages