Return backed values and keys arrays on Maps

Issue #56 new
NemesisMate created an issue

It would be great to have access to the original arrays on maps to avoid a new array creation. For example, for serialization purposes.

Comments (9)

  1. Rob Eden

    My head swims just thinking of the bug reports that would be opened from people claiming things were broken when they'd manually changed their key array. Very doubtful I'd do this... but I'll leave it open for a bit for others to chime in.

  2. NemesisMate reporter

    For current codes using them can be lot of troubles, yes, but easy to fix. The java.util maps works giving the backed collection when using .values() or .keys() so, for people using this library this change would give them troubles but for people adapting their code from java.util to use with Trove would save lot of them.

  3. NemesisMate reporter

    Another big use of this change is for Android devices. Using iterators for iterate is just too much for the Android gc so this would allow to iterate through the backed array without affecting at all the gc.

  4. NemesisMate reporter

    I don't really like functional programming (I can't yet see the advantages). Is this "forEach with a reused procedure" avoiding completely the creation of new instances (what really kills Android's gc)?

  5. Rob Eden

    It can, yes. Depending on your use case, you might be able to only use one instance of a procedure to iterate through the data.

    So, one advantage would be: Trove supports it. ;-)

  6. NemesisMate reporter

    The problem here is that you need that instance once for each time you iterate, doesn't it?, so, for example, to iterate through a collection on a game loop it would create an instance per loop (and this, for many entities, could be gc killing, so much more than if the iteration was through the backed array ;-))

  7. NemesisMate reporter

    Yes, you are right (I just didn't see this library own forEach methods and the procedure system(I was thinking on java 8 new forEach one)). However, I think that the values() and keys() of maps, or any collection that have it, should return the backed collections as I said (just like the default java.util ones do. I think is the normal "object oriented" behaviour). For copies, once you have the backed collection if you want a copy you clone it.

    Thanks very much for the forEach with a reused procedure tip, it can save me (or Androids gc xD) lot of work.

  8. Log in to comment