vigna / fastutil

fastutil extends the Java™ Collections Framework by providing type-specific maps, sets, lists and queues.
Apache License 2.0
1.81k stars 199 forks source link

Supporting set() for ListIterator returned by *LinkedOpenHashMap.values().iterator() #287

Closed rionda closed 1 year ago

rionda commented 1 year ago

This may be a silly question, but would it be, at least theoretically, possible (and possibly not too hard) to support set(K e) for the ListIterator returned by, e.g., Int2IntLinkedOpenHashMap.values().iterator()?

I understand why the one for keySet().iterator() can't/should not support set, but for the values() view, it should be possible to support set(), or am I grossly mistaken?

vigna commented 1 year ago

Intanto ciao come va? 😂 Well, the standard way to do that is to use an entry iterator and call Entry.setValue(). Is there any particular reason you don't want to do that? The standard interface (and implementation) does not provide that kind of access because in general it does not make much sense to change a value if you don't know the key (albeit I can make up scenarios, such as scaling counts).

rionda commented 1 year ago

Ciao caro, perdonami =) Tutto bene, e spero anche tu.

Yeah, I think I misinterpreted what Int2IntLinkedOpenHashMap.values().iterator().nextIndex() and previousIndex() would return: I thought it would return the key corresponding to the next() and previous() values, but that doesn't seem to be the case (please correct me if I'm wrong).

I can definitively use an entry iterator, I didn't think about it.

vigna commented 1 year ago

Nope, these are standard method from the JDK Collection library that return the index in the list of the next/Prev element.

Note that hash maps have a fast entry operator that reuses the same entry at each iteration.

rionda commented 1 year ago

Sounds good. I'm sure I can figure it out =)

Thank you Seba!