/** * Will crawl the weak hash maps and make sure we always have the latest * information on the availability of messages. * * This method is only intended to be used from within * {@link LogWatchStorageSweeper}. * * @return ID of the very first message that is reachable by any follower in * this logWatch. -1 when there are no reachable messages. */ protected synchronized int getFirstReachableMessageId() { final boolean followersRunning = !this.runningFollowerStartMarks.isEmpty(); if (!followersRunning && this.terminatedFollowerRanges.isEmpty()) { // no followers present; no reachable messages return -1; } final IntSortedSet set = new IntAVLTreeSet(this.runningFollowerStartMarks.values()); if (!set.isEmpty()) { final int first = this.messages.getFirstPosition(); if (set.firstInt() <= first) { /* * cannot go below first position; any other calculation * unnecessary */ return first; } } set.addAll(this.terminatedFollowerRanges.values().stream().map(pair -> pair[0]).collect(Collectors.toList())); return set.firstInt(); }
public void testMerge( int n0, int n1 ) { Random r = new Random(); int x0[] = new int[ n0 ]; int x1[] = new int[ n1 ]; int i, p = 0; // Generate for ( i = 0; i < n0; i++ ) p = x0[ i ] = p + r.nextInt( 10 ); p = 0; for ( i = 0; i < n1; i++ ) p = x1[ i ] = p + (int)( Math.random() * 10 ); IntAVLTreeSet s0 = new IntAVLTreeSet( x0 ); IntAVLTreeSet s1 = new IntAVLTreeSet( x1 ); IntAVLTreeSet res = new IntAVLTreeSet( s0 ); res.addAll( s1 ); MergedIntIterator m = new MergedIntIterator( LazyIntIterators.lazy( s0.iterator() ), LazyIntIterators.lazy( s1.iterator() ) ); IntIterator it = res.iterator(); int x; while ( ( x = m.nextInt() ) != -1 ) assertEquals( it.nextInt(), x ); assertEquals( Boolean.valueOf( it.hasNext() ), Boolean.valueOf( m.nextInt() != -1 ) ); }
private String buildInputDataPartitionSchema(List<JCL_result> r, int numOfJCLThreads){ IntSet sorted = new IntAVLTreeSet(); long totalF=0; Int2LongMap map = new Int2LongOpenHashMap(); for(JCL_result oneR:r){ try{ @SuppressWarnings("unchecked") List<String> l = (List<String>) oneR.getCorrectResult(); for(String s : l){ String[] args = s.split(":"); int key = Integer.parseInt(args[0]); long freq = Long.parseLong(args[1]); sorted.add(key); if(map.containsKey(key)){ freq+=map.get(key); totalF+=map.get(key); } else totalF+=freq; map.put(key, freq); } }catch(Exception e){} } long load=0; int b; String result = ""; for(int ac:sorted){ load += map.get(ac); if(load > (totalF/(numOfJCLThreads))){ b=ac; result += b + ":"; load=0; } } return result; }
public List<String> phase1(int id, String name, int numJCLThreads) { Int2LongMap values = new Int2LongOpenHashMap(1000000); long totalF = 0; System.err.println("file: " + name); try { File f = new File("../" + name + "/" + name + ".bin"); InputStream in = new BufferedInputStream(new FileInputStream(f)); FastBufferedInputStream fb = new FastBufferedInputStream(in); byte[] i = new byte[4]; while (fb.read(i) == 4) { int k = java.nio.ByteBuffer.wrap(i).getInt(); if (!values.containsKey(k)) values.put(k, 1); else { long aux = values.get(k); aux++; values.put(k, aux); } totalF++; } fb.close(); in.close(); // primeira modificacao //for (long v : values.values()) // totalF += v; IntSet sorted = new IntAVLTreeSet(values.keySet()); long acumula = 0; int b = 0; List<String> result = new LinkedList<>(); long blinha = 0; int last = 0; for (int ac : sorted) { blinha = values.get(ac); acumula += blinha; if (acumula > (totalF / (numJCLThreads))) { b = ac; result.add(b + ":" + acumula); acumula = 0; } last = ac; } // segunda modificacao if(acumula != 0) result.add(last + ":" + acumula); JCL_facade jcl = JCL_FacadeImpl.getInstanceLambari(); jcl.instantiateGlobalVar(id, values); sorted.clear(); sorted = null; return result; } catch (Exception e) { e.printStackTrace(); return null; } }