algorithm - in java we can use list.remove(int index) to remove the items in that index, what if the list is huge and we can only use long to store the index? -


when use "sieve of eratosthenes" generate prime number encountered problem. want create method takes in list , remove every 3rd list after 3: [2, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29...] -> [2, 3, 5, 7, 11, 13, 17, 19, 23, 25, 29...].and here code:

  private static void removethird(list<long> l) {      int = 1;     int count = 0;     while (i < l.size()) {        // system.out.print(count + ":"); //debug       // system.out.print(l.get(i) + " ");       if (count == 3) {         l.remove(i);         count = 1;       }       ++;       count ++;     }   } 

this code works, because want generate huge amount of prime numbers need long size list. therefore if want able access , modify each item in list need long type store index. changed int = 0 long = 0, , code doesn't work. , viewed docs list class , realized can call list.remove(int index). wonder if want call list.remove(long index)? there way so? thanks!

list , implementations usable lists size fits in positive half of int. e.g., "only" 4,294,967,296 entries (indexes 0 - 4294967295, inclusive).

if need have list that's longer that, you'll need find non-jdk list type or implement own.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -