%@ page import="java.util.*" %> <%@ taglib uri="/WEB-INF/displaytag-12.tld" prefix="display" %> <%! public int[] allocHits(int[] hits, int maxReturned) { // sum the hits int tothits = 0; int totalloc = 0; int[] todo = new int[hits.length]; for (int i=0;i < hits.length; i++) { tothits += hits[i]; todo[i] = 0; } int tot = 0; //System.out.println("Starting.................."); while (totalloc < tothits && totalloc < maxReturned && tot < 20) { int div = (maxReturned - totalloc) / hits.length; if (div == 0 && totalloc < maxReturned) { div = maxReturned - totalloc; } //System.out.println("div-----:"+div+" tothits:"+tothits); for (int i=0;i < hits.length; i++) { int r = hits[i] - todo[i]; int n = div < r ? div : r; todo[i] += n; totalloc += n; //System.out.println("hits:"+i+" div:"+div+" r:"+r+" n:"+n+" todo[i]:"+todo[i]); if (totalloc == tothits) break; } //System.out.println("done set, totalloc:"+totalloc); tot++; } System.out.println("done set, tot:"+tot); return todo; } %><% int[] hits; int[] todo; int max; %>
<% max = 100; hits = new int[] {166,10,42}; todo = allocHits(hits, max); %>To Do:
<% for (int i=0; i
To Do:
<% for (int i=0; i
To Do:
<% for (int i=0; i
To Do:
<% for (int i=0; i