IntList parentIdListPtr = netPtr.net_getParentIdListPtr(id);
IntListNode it = parentIdListPtr.head;
- parentIdListPtr.list_iter_reset(it);
- while (parentIdListPtr.list_iter_hasNext(it)) {
+ while (it.nextPtr!=null) {
it = it.nextPtr;
- int parentId = parentIdListPtr.list_iter_next(it);
+ int parentId = it.dataPtr;
if((status = workQueuePtr.queue_push(parentId)) == false) {
System.out.println("Assert failed: status= "+ status + "should be true");
System.exit(0);
IntList parentIdListPtr = netPtr.net_getParentIdListPtr(v);
int index = 0;
IntListNode it = parentIdListPtr.head;
- parentIdListPtr.list_iter_reset(it);
- while (parentIdListPtr.list_iter_hasNext(it)) {
+ while (it.nextPtr!=null) {
it = it.nextPtr;
- int parentId = parentIdListPtr.list_iter_next(it);
+ int parentId = it.dataPtr;
int value = records[startindex + parentId];
if(value == DATA_INIT) {
System.out.println("Assert failed value should be != DATA_INIT");
* =============================================================================
*/
public void
- list_iter_reset (IntListNode itPtr)
+ list_iter_reset (IntListIter itPtr)
{
- itPtr = head;
+ itPtr.ptr = head;
}
/* =============================================================================
* =============================================================================
*/
public boolean
- list_iter_hasNext (IntListNode itPtr)
+ list_iter_hasNext (IntListIter itPtr)
{
- return ((itPtr.nextPtr != null) ? true : false);
+ return (itPtr.ptr.nextPtr != null);
}
* =============================================================================
*/
public int
- list_iter_next (IntListNode itPtr)
+ list_iter_next (IntListIter itPtr)
{
- return itPtr.dataPtr;
+ int val=itPtr.ptr.dataPtr;
+ itPtr.ptr=itPtr.ptr.nextPtr;
+ return val;
}
/* =============================================================================
--- /dev/null
+public class IntListIter {
+ IntListNode ptr;
+}
\ No newline at end of file
#ifdef TEST_LEARNER
ListNode it = learnerPtr.taskListPtr.head;
- learnerPtr.taskListPtr.list_iter_reset(it);
- while (learnerPtr.taskListPtr.list_iter_hasNext(it)) {
+ while (it.nextPtr!=null) {
it = it.nextPtr;
- LearnerTask taskPtr = learnerPtr.taskListPtr.list_iter_next(it);
+ LearnerTask taskPtr = it.dataPtr;
System.out.println("[task] op= "+ taskPtr.op +" from= "+taskPtr.fromId+" to= " +taskPtr.toId+
" score= " + taskPtr.score);
}
LearnerTask taskPtr = null;
ListNode it = taskListPtr.head;
- taskListPtr.list_iter_reset(it);
- if (taskListPtr.list_iter_hasNext(it)) {
+ if (it.nextPtr!=null) {
it = it.nextPtr;
- taskPtr = taskListPtr.list_iter_next(it);
+ taskPtr = it.dataPtr;
boolean status = taskListPtr.list_remove(taskPtr);
if(status == false) {
System.out.println("Assert failed: when removing from a list in TMpopTask()");
IntList parentIdListPtr = netPtr.net_getParentIdListPtr(id);
IntListNode it = parentIdListPtr.head;
- parentIdListPtr.list_iter_reset(it);
- while (parentIdListPtr.list_iter_hasNext(it)) {
+ while (it.nextPtr!=null) {
it = it.nextPtr;
- int parentId = parentIdListPtr.list_iter_next(it);
+ int parentId = it.dataPtr;
boolean status = parentQueryVectorPtr.vector_pushBack(queries[parentId]);
if(status == false) {
System.out.println("Assert failed: unable to pushBack in queue");
IntList parentIdListPtr = netPtr.net_getParentIdListPtr(id);
IntListNode it = parentIdListPtr.head;
- parentIdListPtr.list_iter_reset(it);
- while (parentIdListPtr.list_iter_hasNext(it)) {
+ while (it.nextPtr!=null) {
it = it.nextPtr;
- int parentId = parentIdListPtr.list_iter_next(it);
+ int parentId = it.dataPtr;
boolean status = parentQueryVectorPtr.vector_pushBack(queries[parentId]);
if(status == false) {
System.out.println("Assert failed: unable to pushBack in queue in TMpopulateParentQueryVector()");
{
IntListNode it = parentIdListPtr.head;
- parentIdListPtr.list_iter_reset(it);
- while( parentIdListPtr.list_iter_hasNext(it)) {
+ while(it.nextPtr!=null) {
it = it.nextPtr;
- int parentId = parentIdListPtr.list_iter_next(it);
+ int parentId = it.dataPtr;
invalidBitmapPtr.bitmap_set(parentId); // invalid since already have edge
}
* =============================================================================
*/
public void
- list_iter_reset (ListNode itPtr)
+ list_iter_reset (ListIter itPtr)
{
- itPtr = head;
+ itPtr.ptr = head;
}
/* =============================================================================
* =============================================================================
*/
public boolean
- list_iter_hasNext (ListNode itPtr)
+ list_iter_hasNext (ListIter itPtr)
{
- return ((itPtr.nextPtr != null) ? true : false);
+ return itPtr.ptr.nextPtr != null;
}
/* =============================================================================
* =============================================================================
*/
public LearnerTask
- list_iter_next (ListNode itPtr)
+ list_iter_next (ListIter itPtr)
{
- //itPtr = itPtr.nextPtr;
- return itPtr.dataPtr;
+ LearnerTask lt=itPtr.ptr.dataPtr;
+ itPtr.ptr=itPtr.ptr.nextPtr;
+ return lt;
}
/* =============================================================================
--- /dev/null
+public class ListIter {
+ public ListNode ptr;
+}
\ No newline at end of file
IntList parentIdListPtr = childNodePtr.parentIdListPtr;
IntListNode it = parentIdListPtr.head; //intialize iterator
- parentIdListPtr.list_iter_reset(it);
- while (parentIdListPtr.list_iter_hasNext(it)) {
+ while (it.nextPtr!=null) {
it = it.nextPtr;
- int parentId = parentIdListPtr.list_iter_next(it);
+ int parentId = it.dataPtr;
if (parentId == fromId) {
return true;
}
IntList parentIdListPtr = childNodePtr.parentIdListPtr;
IntListNode it = parentIdListPtr.head;//initialize iterator
- parentIdListPtr.list_iter_reset(it);
- while (parentIdListPtr.list_iter_hasNext(it)) {
+ while (it.nextPtr!=null) {
it = it.nextPtr;
- int parentId = parentIdListPtr.list_iter_next(it);
+ int parentId = it.dataPtr;
if (parentId == fromId) {
return true;
}
NetNode nodePtr = (NetNode) (nodeVectorPtr.vector_at(id));
IntList childIdListPtr = nodePtr.childIdListPtr;
IntListNode it = childIdListPtr.head;
- childIdListPtr.list_iter_reset(it);
- while (childIdListPtr.list_iter_hasNext(it)) {
+ while (it.nextPtr!=null) {
it = it.nextPtr;
- int childId = childIdListPtr.list_iter_next(it);
+ int childId = it.dataPtr;
if (!visitedBitmapPtr.bitmap_isSet(childId)) {
status = workQueuePtr.queue_push(childId);
if(status == false) {
nodePtr.mark = NET_NODE_MARK_TEST;
IntList childIdListPtr = nodePtr.childIdListPtr;
IntListNode it = childIdListPtr.head;
- childIdListPtr.list_iter_reset(it);
- while (childIdListPtr.list_iter_hasNext(it)) {
+ while (it.nextPtr!=null) {
it = it.nextPtr;
- int childId = childIdListPtr.list_iter_next(it);
+ int childId = it.dataPtr;
NetNode childNodePtr = (NetNode)(nodeVectorPtr.vector_at(childId));
if (isCycle(nodeVectorPtr, childNodePtr)) {
return true;
NetNode nodePtr = (NetNode)(nodeVectorPtr.vector_at(id));
IntList parentIdListPtr = nodePtr.parentIdListPtr;
IntListNode it = parentIdListPtr.head;
- parentIdListPtr.list_iter_reset(it);
- while (parentIdListPtr.list_iter_hasNext(it)) {
+ while (it.nextPtr!=null) {
it = it.nextPtr;
- int parentId = parentIdListPtr.list_iter_next(it);
+ int parentId = it.dataPtr;
status = ancestorBitmapPtr.bitmap_set(parentId);
if(status == false) {
System.out.println("Assert failed: for bitmap_set in net_findAncestors()");
NetNode nodePtr = (NetNode)(nodeVectorPtr.vector_at(parentId));
IntList grandParentIdListPtr = nodePtr.parentIdListPtr;
IntListNode it = grandParentIdListPtr.head;
- grandParentIdListPtr.list_iter_reset(it);
- while (grandParentIdListPtr.list_iter_hasNext(it)) {
+ while (it.nextPtr!=null) {
it = it.nextPtr;
- int grandParentId = grandParentIdListPtr.list_iter_next(it);
+ int grandParentId = it.dataPtr;
if (!ancestorBitmapPtr.bitmap_isSet(grandParentId)) {
if((status = ancestorBitmapPtr.bitmap_set(grandParentId)) == false) {
System.out.println("Assert failed: for ancestorBitmapPtr bitmap_set in net_findAncestors()");
NetNode nodePtr = (NetNode)(nodeVectorPtr.vector_at(id));
IntList childIdListPtr = nodePtr.childIdListPtr;
IntListNode it = childIdListPtr.head;
- childIdListPtr.list_iter_reset(it);
- while (childIdListPtr.list_iter_hasNext(it)) {
+ while (it.nextPtr!=null) {
it = it.nextPtr;
- int childId = childIdListPtr.list_iter_next(it);
+ int childId = it.dataPtr;
if((status = descendantBitmapPtr.bitmap_set(childId)) == false) {
System.out.println("Assert failed: for descendantBitmapPtr.bitmap_set in net_findDescendants()");
System.exit(0);
NetNode nodePtr = (NetNode)(nodeVectorPtr.vector_at(childId));
IntList grandChildIdListPtr = nodePtr.childIdListPtr;
IntListNode it = grandChildIdListPtr.head;
- grandChildIdListPtr.list_iter_reset(it);
- while (grandChildIdListPtr.list_iter_hasNext(it)) {
+ while (it.nextPtr!=null) {
it = it.nextPtr;
- int grandChildId = grandChildIdListPtr.list_iter_next(it);
+ int grandChildId = it.dataPtr;
if (!descendantBitmapPtr.bitmap_isSet(grandChildId)) {
if((status = descendantBitmapPtr.bitmap_set(grandChildId)) == false) {
System.out.println("Assert failed: for descendantBitmapPtr.bitmap_set in net_findDescendants()");
--- /dev/null
+public class QuickSort {
+ public QuickSort() {
+
+ }
+
+ /**
+ * Sort an array of Objects into ascending order. The sort algorithm is an optimised
+ * quicksort, as described in Jon L. Bentley and M. Douglas McIlroy's
+ * "Engineering a Sort Function", Software-Practice and Experience, Vol.
+ * 23(11) P. 1249-1265 (November 1993). This algorithm gives nlog(n)
+ * performance on many arrays that would take quadratic time with a standard
+ * quicksort.
+ *
+ * @param a the array to sort
+ */
+ public void sort(Object[] a)
+ {
+ qsort(a, 0, a.length);
+ }
+
+ public void sort(Object[] a, int fromIndex, int toIndex)
+ {
+ qsort(a, fromIndex, toIndex);
+ }
+
+ private int med3(int a, int b, int c, Object[]d)
+ {
+ if(less(d[a], d[b])) {
+ if(less(d[b], d[c])) {
+ return b;
+ } else {
+ if(less(d[a], d[c]))
+ return c;
+ else
+ return a;
+ }
+ } else {
+ if(less(d[c], d[b])) {
+ return b;
+ } else {
+ if(less(d[c], d[a]))
+ return c;
+ else
+ return a;
+ }
+ }
+ }
+
+ private void swap(int i, int j, Object[] a)
+ {
+ Object c = a[i];
+ a[i] = a[j];
+ a[j] = c;
+ }
+
+ private void qsort(Object[] a, int start, int n)
+ {
+ // use an insertion sort on small arrays
+ if (n <= 7)
+ {
+ for (int i = start + 1; i < start + n; i++)
+ for (int j = i; j > 0 && less(a[j], a[j - 1]); j--)
+ swap(j, j - 1, a);
+ return;
+ }
+
+ int pm = n / 2; // small arrays, middle element
+ if (n > 7)
+ {
+ int pl = start;
+ int pn = start + n - 1;
+
+ if (n > 40)
+ { // big arrays, pseudomedian of 9
+ int s = n / 8;
+ pl = med3(pl, pl + s, pl + 2 * s, a);
+ pm = med3(pm - s, pm, pm + s, a);
+ pn = med3(pn - 2 * s, pn - s, pn, a);
+ }
+ pm = med3(pl, pm, pn, a); // mid-size, med of 3
+ }
+
+ int pa, pb, pc, pd, pv;
+ int r;
+
+ pv = start;
+ swap(pv, pm, a);
+ pa = pb = start;
+ pc = pd = start + n - 1;
+
+ while(true)
+ {
+ while (pb <= pc && (r = diff(a[pb],a[pv])) <= 0)
+ {
+ if (r == 0)
+ {
+ swap(pa, pb, a);
+ pa++;
+ }
+ pb++;
+ }
+ while (pc >= pb && (r = diff(a[pc],a[pv])) >= 0)
+ {
+ if (r == 0)
+ {
+ swap(pc, pd, a);
+ pd--;
+ }
+ pc--;
+ }
+ if (pb > pc)
+ break;
+ swap(pb, pc, a);
+ pb++;
+ pc--;
+ }
+ int pn = start + n;
+ int s;
+ s = Math.imin(pa - start, pb - pa);
+ vecswap(start, pb - s, s, a);
+ s = Math.imin(pd - pc, pn - pd - 1);
+ vecswap(pb, pn - s, s, a);
+ if ((s = pb - pa) > 1)
+ qsort(a, start, s);
+ if ((s = pd - pc) > 1)
+ qsort(a, pn - s, s);
+ }
+
+ private void vecswap(int i, int j, int n, Object[] a)
+ {
+ for (; n > 0; i++, j++, n--)
+ swap(i, j, a);
+ }
+
+ /* ===========================================
+ * compareQuery
+ * -- Want smallest ID first
+ * -- For vector_sort
+ * ===========================================
+ */
+ public boolean less(Object x, Object y) {
+ Query aQueryPtr = (Query) x;
+ Query bQueryPtr = (Query) y;
+ if(aQueryPtr.index < bQueryPtr.index)
+ return true;
+ return false;
+ }
+
+ public int diff(Object x, Object y) {
+ Query aQueryPtr = (Query) x;
+ Query bQueryPtr = (Query) y;
+ return (aQueryPtr.index - bQueryPtr.index);
+ }
+
+ /**
+ * main to test quick sort
+ **/
+ /*
+ public static void main(String[] args) {
+ QuickSort qs = new QuickSort();
+ Query[] queries = new Query[10];
+
+ Random r = new Random();
+ r.random_alloc();
+ r.random_seed(0);
+
+ for(int i = 0; i<10; i++) {
+ queries[i] = new Query();
+ queries[i].index = (int) (r.random_generate() % 100);
+ queries[i].value = -1;
+ }
+
+ System.out.println("Before sorting");
+ for(int i = 0; i<10; i++)
+ System.out.println("queries["+i+"]= "+ queries[i]);
+
+ qs.sort(queries);
+
+ System.out.println("After sorting");
+ for(int i = 0; i<10; i++)
+ System.out.println("queries["+i+"]= "+ queries[i]);
+ }
+ */
+}