Skip to content
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

modification at time of iteration #9

Open
Yaffle opened this issue Jan 17, 2013 · 2 comments
Open

modification at time of iteration #9

Yaffle opened this issue Jan 17, 2013 · 2 comments
Assignees

Comments

@Yaffle
Copy link

Yaffle commented Jan 17, 2013

Hello

var set = new Set();
set.add(1);
set.add(2);
set.add(3);
set.add(4);

var iterator = set.iterate ? set.iterate() : set.iterator();
var k = 0;

while (true) {
  next = iterator.next();
  console.log(next);
  if (k === 0) {
    set.delete(2);
    set.delete(1);
    set.delete(0);        
  }
  k++;
}
set.add(1, 1);

this code prints "1; 3; 4" in FF 18 with "native" Set and
"1; 2; 3; 4" with your code

could you please document how your iteration works with modification

@kriskowal
Copy link
Member

Thanks for surfacing the issue. While I’m at it, I probably ought to abandon the fight for "iterate" over "iterator".

@kriskowal
Copy link
Member

I will need to revisit this. Neither behavior makes much sense. At present, Set is a combination of a FastSet and a List. The List dictates iteration order and allows modifications during iteration. I think this is a bug caused by the iterator walking links of the list that are no longer associated with the Set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants