Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. public class FastHashMap
  2. {
  3. public static class Loader extends Thread
  4. {
  5. private int from;
  6. private int to;
  7. private HashMap<Long, String> data;
  8.  
  9. public Loader( final HashMap<Long, String> data, int from, int to )
  10. {
  11. this.data = data;
  12. this.from = from;
  13. this.to = to;
  14. start();
  15. }
  16. @Override
  17. public void run()
  18. {
  19. for( int i=from;i<=to;i++) {
  20. data.put( new Long(i), "#" + String.valueOf( i ) );
  21. }
  22. }
  23. }
  24.  
  25. public static void main(String[] args)
  26. {
  27. HashMap<Long, String> data = new HashMap<Long, String>();
  28. new Loader( data, 1, 150 );
  29. new Loader( data, 100, 200 );
  30.  
  31. try { Thread.sleep( 3000 ); } catch (InterruptedException noCare) {}
  32.  
  33. System.out.println( data.size() );
  34. int miss = 0;
  35. for( int i=1;i<=200;i++)
  36. {
  37. if( !data.containsKey( new Long(i) ) ) miss++;
  38. }
  39. System.out.println( miss );
  40. }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement