-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Puzzle about the iterative sequence #93
Comments
@danielzhangy that behaviour is by design, I just have to write that in the documentation. Not sure why java does it this way, but I used their ideology: https://docs.oracle.com/javase/7/docs/api/java/util/LinkedHashMap.html
I followed their documentation as not to be "smart" about it, but it can be implemented either way. |
@emirpasic I think the reason that java does it this way is that java wants the iterative sequence of LinkedHashMap to be close to the k-v entry input order, it is more ergonomic. |
@danielzhangy yes, I suppose it all depends at how we define "insertion". Does placing the same element into set or map constitute insertion? According to Java, they don't treat it as a new insertion. I am really not sure about this one, might get philosophical :D I will leave this question open in case somebody else has an opinion on this, for now I leave it with the Java's idea of what "insertion" really means. |
@emirpasic yes, it depends on the definition of "insertion". Thanks to your reminder, I read the source code of Java 11. Java treats the same element placing in two different ways, it depends on the initial condition named accessOrder. If accessOrder is false, Java treats the same element placing as updating, otherwise, Java treats it as a special new insertion(updating the value of mapping key and moving the element to the tail of order list).
|
@danielzhangy thanks for the research, it gave me an idea that it's best to have both. I think I'll add that option also to the LinkedHashSet and LinkedHashMap to configure this behavior or specialized functions that behave in one or the other way. Hwever, oI am still not sure what the default behavior should be, should the same element be evicted upon reinsertion and added to the end or should the default behavior follow Java's default behavior, i.e. no change in insertion order. |
@emirpasic I prefer to choose current implementation as default behavior, and make another way as optional, by considering the performance of operation. So what do you think? |
@danielzhangy i agree with you and i'll leave the current implementation as default, but will provide a way to modify this behavior. |
A pleasure that LinkedHashMap has been added.
While I have a different point about the iterative sequence. The sequence should order by the key last time put in instead of the first time put in.
This situation is caused by the func named LinkedHashMap.Put:
Test case as follows:
I except the output like
, but the result is
.
The text was updated successfully, but these errors were encountered: