daily pastebin goal
38%
SHARE
TWEET

Untitled

a guest Sep 25th, 2018 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.ArrayList;
  2. import java.util.Collections;
  3. import java.util.HashSet;
  4. import java.util.concurrent.ThreadLocalRandom;
  5.  
  6. class Main {
  7.   public static void main(String[] args) {
  8.     MaxBag b = new MaxBag();
  9.     HashSet<Integer> s = new HashSet<Integer>();
  10.     Integer N = 10000;
  11.     Integer M = 1000000;
  12.  
  13.     ArrayList<Integer> to_add = new ArrayList<Integer>();
  14.     ArrayList<Integer> to_delete = new ArrayList<Integer>();
  15.     ArrayList<Integer> max_bs = new ArrayList<Integer>();
  16.     ArrayList<Integer> max_ss = new ArrayList<Integer>();
  17.  
  18.     for (int i = 0; i < N; i++) {
  19.       to_add.add(ThreadLocalRandom.current().nextInt(0, M));
  20.       to_delete.add(ThreadLocalRandom.current().nextInt(0, M));
  21.     }
  22.  
  23.     long lStartTime = System.nanoTime();
  24.     for (int i = 0; i < N; i++) {
  25.       b.add(to_add.get(i));
  26.     }
  27.  
  28.     for (int i = 0; i < N; i++) {
  29.       b.remove(to_delete.get(i));
  30.       max_bs.add(b.get_max());
  31.     }
  32.     System.out.println("B time in ms: " + (System.nanoTime() - lStartTime) / 1000000);
  33.    
  34.     lStartTime = System.nanoTime();
  35.     for (int i = 0; i < N; i++) {
  36.       s.add(to_add.get(i));
  37.     }
  38.  
  39.     for (int i = 0; i < N; i++) {
  40.       s.remove(to_delete.get(i));
  41.       max_ss.add(Collections.max(s));
  42.     }
  43.  
  44.     System.out.println("S time in ms: " + (System.nanoTime() - lStartTime) / 1000000);
  45.  
  46.     for (int i = 0; i < N; i++) {
  47.       assert max_bs.get(i) == max_ss.get(i);
  48.     }
  49.   }
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top