Note that there are some explanatory texts on larger screens.

plurals
  1. POOptimization of an Algo
    primarykey
    data
    text
    <p>I have code that reads a text file and creates an input array[] of <code>boolean</code> type. Its size is about 100,000-300,000 items. Now the problem I'm facing is to create all those subsets of size N, 3>=N>=9, that have contiguous true values.</p> <p>E.g. for N=3, [true][true][true] is the required subset if all the 3 trues are in the continuous indexes.</p> <p>Although I have an algorithm created, it's very slow. I need a better solution, which is fast and efficient.</p> <p>Please suggest some ideas.</p> <pre><code> public static void createConsecutivePassingDays() { for (String siteName : sitesToBeTestedList.keySet()) { System.out.println("\n*****************Processing for Site---&gt;"+siteName+" ***********************"); LinkedHashMap&lt;String,ArrayList&lt;String&gt;&gt; cellsWithPassedTripletsDates=new LinkedHashMap&lt;String, ArrayList&lt;String&gt;&gt;(); for (String cellName : sitesToBeTestedList.get(siteName)) { System.out.println("\n*****************Processing for Cell---&gt;"+cellName+" ***********************"); boolean failed=false; ArrayList&lt;String&gt; passedDatesTriplets=new ArrayList&lt;String&gt;(); int consecutiveDays=0; String tripletDate=""; String prevDate_day=""; String today_Date=""; for (String date : cellDateKpiMetOrNotMap.get(cellName).keySet()) { System.out.println("\nprocessing for Date--&gt;"+date); if(!(prevDate_day.trim().equals(""))) today_Date=getNextDay(prevDate_day.substring(0, prevDate_day.lastIndexOf('_'))); if(Connection.props.getProperty("INCLUDE_WEEKENDS").equalsIgnoreCase("FALSE")) { if(date.endsWith("SAT") || date.endsWith("SUN") || (!(date.substring(0, date.lastIndexOf('_')).equalsIgnoreCase(today_Date)))) { if(consecutiveDays &gt;= Reader.days) { passedDatesTriplets.add(tripletDate); } tripletDate=""; consecutiveDays=0; prevDate_day=date; continue; } } if(cellDateKpiMetOrNotMap.get(cellName).get(date).equalsIgnoreCase("TRUE")) { if(tripletDate.equals("")) tripletDate=date; else tripletDate+="#"+date; consecutiveDays++; } else { failed=true; if(consecutiveDays &gt;= Reader.days)//kd { System.out.println("Triplet to be added--&gt;"+tripletDate); passedDatesTriplets.add(tripletDate); } tripletDate=""; consecutiveDays=0; } prevDate_day=date; } if(!failed) passedDatesTriplets.add(tripletDate); else { if(tripletDate.trim().split("#").length &gt;= Reader.days) { passedDatesTriplets.add(tripletDate); } } cellsWithPassedTripletsDates.put(cellName, passedDatesTriplets); } siteItsCellsWithPassedDates.put(siteName, cellsWithPassedTripletsDates); } System.out.println("\n************************************************SITES***************************************"); for (String site : siteItsCellsWithPassedDates.keySet()) { System.out.println("\n********************Site="+site+" ***********************"); for (String cellName : siteItsCellsWithPassedDates.get(site).keySet()) { System.out.println("\nCellName="+cellName); System.out.println(siteItsCellsWithPassedDates.get(site).get(cellName)); } System.out.println("***********************************************************"); } System.out.println("********************************************************************************************"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload