OOFILE  1.9
ooflist.cpp
Go to the documentation of this file.
1 // COPYRIGHT 1994 A.D. Software, All rights reserved
2 
3 #include "oofpch_c.h" // for precompilation of core files
4 
5 #ifndef H_OOFIOS
6  #include "oofios.h"
7 #endif
8 #ifndef H_OOF1
9  #include "oof1.h"
10 #endif
11 #ifndef H_OOFLIST
12  #include "ooflist.h"
13 #endif
14 
15 #ifdef OOF_MEM_DEBUG_LAST_INCLUDE
16  #include OOF_MEM_DEBUG_LAST_INCLUDE
17 #endif
18 
19 #ifndef OOF_NO_STDLIB
20  #ifndef std
21  using namespace std;
22  #endif
23 #endif
24 
25 // -------------------------------------------------------
26 // O O F _ L i s t
27 // -------------------------------------------------------
28 
29 //----------------------------------------------------------------------
30 // OOF_List::append
31 // append an "item" to the end of the list.
32 //
33 // Allocate a ListElement to keep track of the item.
34 // If the list is empty, then this will be the only element.
35 // Otherwise, put it at the end.
36 //
37 // "item" is the thing to put on the list, it can be a pointer to
38 // anything.
39 //----------------------------------------------------------------------
40 
41 void
42 OOF_List::append(unsigned long theItem)
43 {
44  OOF_ListElement *element = new OOF_ListElement(theItem);
45 
46  if (isEmpty()) { // list is empty
47  mFirst = element;
48  mLast = element;
49  } else { // else put it after last
50  mLast->mNext = element;
51  mLast = element;
52  }
53  mCount++;
54 }
55 
56 //----------------------------------------------------------------------
57 // OOF_List::prepend
58 // Put an "item" on the front of the list.
59 //
60 // Allocate a ListElement to keep track of the item.
61 // If the list is empty, then this will be the only element.
62 // Otherwise, put it at the beginning.
63 //
64 // "item" is the thing to put on the list, it can be a pointer to
65 // anything.
66 //----------------------------------------------------------------------
67 
68 void OOF_List::prepend(unsigned long theItem)
69 {
70  OOF_ListElement *element = new OOF_ListElement(theItem);
71 
72  if (isEmpty()) { // list is empty
73  mFirst = element;
74  mLast = element;
75  } else { // else put it before first
76  element->mNext = mFirst;
77  mFirst = element;
78  }
79  mCount++;
80 }
81 
82 //----------------------------------------------------------------------
83 // OOF_List::remove
84 // remove the first "item" from the front of the list.
85 //
86 // Returns:
87 // Removed item, 0 if nothing on the list.
88 //----------------------------------------------------------------------
89 
90 unsigned long OOF_List::remove()
91 {
92  OOF_ListElement *element = mFirst;
93  unsigned long thing;
94 
95  if (isEmpty())
96  return 0;
97 
98  thing = mFirst->mItem;
99  if (mFirst == mLast) { // list had one item, now has none
100  mFirst = 0;
101  mLast = 0;
102  } else {
103  mFirst = element->mNext;
104  }
105  mCount--;
106  delete element;
107  return thing;
108 }
109 
110 //----------------------------------------------------------------------
111 // OOF_List::member
112 // Returns true if the list contains theItem.
113 //----------------------------------------------------------------------
114 
115 bool OOF_List::member(unsigned long theItem) const
116 {
117  OOF_ListElement *ptr; // keep track
118 
119  for (ptr = mFirst; ptr != 0; ptr = ptr->mNext)
120  {
121  if(ptr->mItem == theItem)
122  return(true);
123  }
124 
125  return false;
126 }
127 
128 //----------------------------------------------------------------------
129 // OOF_List::sortedInsert
130 // Insert an "item" into a list, so that the list elements are
131 // sorted in increasing order.
132 //
133 // Allocate a ListElement to keep track of the item.
134 // If the list is empty, then this will be the only element.
135 // Otherwise, walk through the list, one element at a time,
136 // to find where the new item should be placed.
137 //----------------------------------------------------------------------
138 
139 void OOF_List::sortedInsert(unsigned long theItem)
140 {
141  OOF_ListElement *element = new OOF_ListElement(theItem);
142  OOF_ListElement *ptr; // keep track
143 
144  if (isEmpty()) { // if list is empty, put
145  mFirst = element;
146  mLast = element;
147  mCount = 1;
148  } else if (theItem < mFirst->mItem) {
149  // item goes on front of list
150  element->mNext = mFirst;
151  mFirst = element;
152  mCount++;
153  } else { // look for first one in list bigger than item
154  for (ptr = mFirst; ptr->mNext != 0; ptr = ptr->mNext) {
155  if (theItem < ptr->mNext->mItem) {
156  element->mNext = ptr->mNext;
157  ptr->mNext = element;
158  mCount++;
159  return;
160  }
161  }
162  mLast->mNext = element; // item goes at end of list
163  mLast = element;
164  mCount++;
165  }
166 }
167 
168 //----------------------------------------------------------------------
169 // List::sortedInsertNoDups
170 // Insert an "item" into a list, so that the list elements are
171 // sorted in increasing order and there are no duplicates.
172 //
173 // Allocate a ListElement to keep track of the item.
174 // If the list is empty, then this will be the only element.
175 // Otherwise, walk through the list, one element at a time,
176 // to find where the new item should be placed.
177 //----------------------------------------------------------------------
178 
179 void OOF_List::sortedInsertNoDups(unsigned long theItem)
180 {
181  OOF_ListElement *element = new OOF_ListElement(theItem);
182  OOF_ListElement *ptr; // keep track
183 
184  if (isEmpty()) { // if list is empty, bung it in
185  mFirst = element;
186  mLast = element;
187  mCount = 1;
188  } else if (theItem < mFirst->mItem) {
189  // item goes on front of list
190  element->mNext = mFirst;
191  mFirst = element;
192  mCount++;
193  } else { // look for first one in list bigger than item
194  for (ptr = mFirst; ptr->mNext != 0; ptr = ptr->mNext) {
195  if (theItem < ptr->mNext->mItem) {
196  if (theItem == ptr->mItem) {
197  delete element;
198  return;
199  } else {
200  element->mNext = ptr->mNext;
201  ptr->mNext = element;
202  mCount++;
203  return;
204  }
205  }
206  }
207  // We've tested everything except the last item, and
208  // we're either larger, or equal to the last item
209  if(theItem != mLast->mItem) {
210  mLast->mNext = element; // item goes at end of list
211  mLast = element;
212  mCount++;
213  }
214  }
215 }
216 
217 
218 
219 // -------------------------------------------------------
220 // O O F _ S o r t e r (various versions - no templates)
221 // -------------------------------------------------------
222 
223 //----------------------------------------------------------------------
224 // OOF_ULSorter::remove
225 // remove the first "item" from the front of the list.
226 //
227 // Returns:
228 // Removed item, 0 if nothing on the list.
229 //----------------------------------------------------------------------
230 
231 unsigned long OOF_ULSorter::remove()
232 {
233  OOF_ULSorterElement *element = mFirst;
234  unsigned long data;
235 
236  if (isEmpty())
237  return 0;
238 
239  data = mFirst->mData;
240  if (mFirst == mLast) { // list had one item, now has none
241  mFirst = 0;
242  mLast = 0;
243  } else {
244  mFirst = element->mNext;
245  }
246  mCount--;
247  delete element;
248  return data;
249 }
250 
251 //----------------------------------------------------------------------
252 // OOF_ULSorter::sortedInsert
253 // Insert an "item" into a list, so that the list elements are
254 // sorted in increasing order.
255 //
256 // Allocate a ListElement to keep track of the item.
257 // If the list is empty, then this will be the only element.
258 // Otherwise, walk through the list, one element at a time,
259 // to find where the new item should be placed.
260 //----------------------------------------------------------------------
261 
262 void
263 OOF_ULSorter::sortedInsert(unsigned long theItem, unsigned long theData)
264 {
265  OOF_ULSorterElement *element = new OOF_ULSorterElement(theItem, theData);
266  OOF_ULSorterElement *ptr; // keep track
267 
268  if (isEmpty()) { // if list is empty, just bung it in !
269  mFirst = element;
270  mLast = element;
271  mLastInsertEqual=false;
272  mCount = 1;
273  } else if (theItem <= mFirst->mItem) {
274  // item goes on front of list
275  if (theItem == mFirst->mItem) {
276  mLastInsertEqual=true;
277  mEqualInserted=element;
278  } else
279  mLastInsertEqual=false;
280  element->mNext = mFirst;
281  mFirst = element;
282  mCount++;
283  } else { // look for first one in list bigger than item
284  for (ptr = mFirst; ptr->mNext != 0; ptr = ptr->mNext)
285  if (theItem == ptr->mNext->mItem) {
286  element->mNext = ptr->mNext;
287  ptr->mNext = element;
288  mLastInsertEqual=true;
289  mEqualInserted=element;
290  mCount++;
291  return;
292  } else if (theItem < ptr->mNext->mItem) {
293  element->mNext = ptr->mNext;
294  ptr->mNext = element;
295  mLastInsertEqual=false;
296  mCount++;
297  return;
298  }
299  mLast->mNext = element; // item goes at end of list
300  mLast = element;
301  mLastInsertEqual=false;
302  mCount++;
303  }
304 }
305 
306 //----------------------------------------------------------------------
307 // OOF_ULSorter::sortedInsertReverse
308 // Insert an "item" into a list, so that the list elements are
309 // sorted in increasing order.
310 //
311 // Allocate a ListElement to keep track of the item.
312 // If the list is empty, then this will be the only element.
313 // Otherwise, walk through the list, one element at a time,
314 // to find where the new item should be placed.
315 //----------------------------------------------------------------------
316 
317 void
318 OOF_ULSorter::sortedInsertReverse(unsigned long theItem, unsigned long theData)
319 {
320  OOF_ULSorterElement *element = new OOF_ULSorterElement(theItem, theData);
321  OOF_ULSorterElement *ptr; // keep track
322 
323  if (isEmpty()) { // if list is empty, just bung it in !
324  mFirst = element;
325  mLast = element;
326  mLastInsertEqual=false;
327  mCount = 1;
328  } else if (theItem >= mFirst->mItem) {
329  // item goes on front of list
330  if (theItem == mFirst->mItem) {
331  mLastInsertEqual=true;
332  mEqualInserted=element;
333  } else
334  mLastInsertEqual=false;
335  element->mNext = mFirst;
336  mFirst = element;
337  mCount++;
338  } else { // look for first one in list smaller than item
339  for (ptr = mFirst; ptr->mNext != 0; ptr = ptr->mNext)
340  if (theItem > ptr->mNext->mItem) {
341  element->mNext = ptr->mNext;
342  ptr->mNext = element;
343  mLastInsertEqual=false;
344  mCount++;
345  return;
346  } else if (theItem == ptr->mNext->mItem) {
347  element->mNext = ptr->mNext;
348  ptr->mNext = element;
349  mLastInsertEqual=true;
350  mEqualInserted=element;
351  mCount++;
352  return;
353  }
354  mLast->mNext = element; // item goes at end of list
355  mLast = element;
356  mLastInsertEqual=false;
357  mCount++;
358  }
359 }
360 
361 void
363 {
364 #ifdef OOF_DEBUG
365  if(theItem->mNext==0)
366  dbConnect::raise("Hmm, sorter::exchange got called, and there's no following record");
367 #endif
368 
369  // Swap the data
370  unsigned long temp;
371  temp=theItem->mData;
372  theItem->mData=theItem->mNext->mData;
373  theItem->mNext->mData=temp;
374 
375  // Reset the Equality stuff
376  if((theItem->mNext->mNext!=0)&&(theItem->mNext->mItem==theItem->mNext->mNext->mItem)) {
377  mLastInsertEqual=true;
378  mEqualInserted=theItem->mNext;
379  } else {
380  mLastInsertEqual=false;
381  }
382 }
383 
384 //--------//
385 
386 //----------------------------------------------------------------------
387 // OOF_LSorter::remove
388 //----------------------------------------------------------------------
389 
390 unsigned long OOF_LSorter::remove()
391 {
392  OOF_LSorterElement *element = mFirst;
393  unsigned long data;
394 
395  if (isEmpty())
396  return 0;
397 
398  data = mFirst->mData;
399  if (mFirst == mLast) { // list had one item, now has none
400  mFirst = 0;
401  mLast = 0;
402  } else {
403  mFirst = element->mNext;
404  }
405  mCount--;
406  delete element;
407  return data;
408 }
409 
410 //----------------------------------------------------------------------
411 // OOF_LSorter::sortedInsert
412 //----------------------------------------------------------------------
413 
414 void
415 OOF_LSorter::sortedInsert(long theItem, unsigned long theData)
416 {
417  OOF_LSorterElement *element = new OOF_LSorterElement(theItem, theData);
418  OOF_LSorterElement *ptr; // keep track
419 
420  if (isEmpty()) { // if list is empty, just bung it in !
421  mFirst = element;
422  mLast = element;
423  mCount = 1;
424  } else if (theItem < mFirst->mItem) {
425  // item goes on front of list
426  element->mNext = mFirst;
427  mFirst = element;
428  mCount++;
429  } else { // look for first one in list bigger than item
430  for (ptr = mFirst; ptr->mNext != 0; ptr = ptr->mNext) {
431  if (theItem < ptr->mNext->mItem) {
432  element->mNext = ptr->mNext;
433  ptr->mNext = element;
434  mCount++;
435  return;
436  }
437  }
438  mLast->mNext = element; // item goes at end of list
439  mLast = element;
440  mCount++;
441  }
442 }
443 
444 //----------------------------------------------------------------------
445 // OOF_LSorter::sortedInsertReverse
446 //----------------------------------------------------------------------
447 
448 void
449 OOF_LSorter::sortedInsertReverse(long theItem, unsigned long theData)
450 {
451  OOF_LSorterElement *element = new OOF_LSorterElement(theItem, theData);
452  OOF_LSorterElement *ptr; // keep track
453 
454  if (isEmpty()) { // if list is empty, just bung it in !
455  mFirst = element;
456  mLast = element;
457  mCount = 1;
458  } else if (theItem > mFirst->mItem) {
459  // item goes on front of list
460  element->mNext = mFirst;
461  mFirst = element;
462  mCount++;
463  } else { // look for first one in list bigger than item
464  for (ptr = mFirst; ptr->mNext != 0; ptr = ptr->mNext) {
465  if (theItem > ptr->mNext->mItem) {
466  element->mNext = ptr->mNext;
467  ptr->mNext = element;
468  mCount++;
469  return;
470  }
471  }
472  mLast->mNext = element; // item goes at end of list
473  mLast = element;
474  mCount++;
475  }
476 }
477 
478 //--------//
479 
480 //----------------------------------------------------------------------
481 // OOF_DSorter::remove
482 //----------------------------------------------------------------------
483 
484 unsigned long OOF_DSorter::remove()
485 {
486  OOF_DSorterElement *element = mFirst;
487  unsigned long data;
488 
489  if (isEmpty())
490  return 0;
491 
492  data = mFirst->mData;
493  if (mFirst == mLast) { // list had one item, now has none
494  mFirst = 0;
495  mLast = 0;
496  } else {
497  mFirst = element->mNext;
498  }
499  mCount--;
500  delete element;
501  return data;
502 }
503 
504 //----------------------------------------------------------------------
505 // OOF_DSorter::sortedInsert
506 //----------------------------------------------------------------------
507 
508 void
509 OOF_DSorter::sortedInsert(double theItem, unsigned long theData)
510 {
511  OOF_DSorterElement *element = new OOF_DSorterElement(theItem, theData);
512  OOF_DSorterElement *ptr; // keep track
513 
514  if (isEmpty()) { // if list is empty, just bung it in !
515  mFirst = element;
516  mLast = element;
517  mCount = 1;
518  } else if (theItem < mFirst->mItem) {
519  // item goes on front of list
520  element->mNext = mFirst;
521  mFirst = element;
522  mCount++;
523  } else { // look for first one in list bigger than item
524  for (ptr = mFirst; ptr->mNext != 0; ptr = ptr->mNext) {
525  if (theItem < ptr->mNext->mItem) {
526  element->mNext = ptr->mNext;
527  ptr->mNext = element;
528  mCount++;
529  return;
530  }
531  }
532  mLast->mNext = element; // item goes at end of list
533  mLast = element;
534  mCount++;
535  }
536 }
537 
538 //----------------------------------------------------------------------
539 // OOF_DSorter::sortedInsertReverse
540 //----------------------------------------------------------------------
541 
542 void
543 OOF_DSorter::sortedInsertReverse(double theItem, unsigned long theData)
544 {
545  OOF_DSorterElement *element = new OOF_DSorterElement(theItem, theData);
546  OOF_DSorterElement *ptr; // keep track
547 
548  if (isEmpty()) { // if list is empty, just bung it in !
549  mFirst = element;
550  mLast = element;
551  mCount = 1;
552  } else if (theItem > mFirst->mItem) {
553  // item goes on front of list
554  element->mNext = mFirst;
555  mFirst = element;
556  mCount++;
557  } else { // look for first one in list bigger than item
558  for (ptr = mFirst; ptr->mNext != 0; ptr = ptr->mNext) {
559  if (theItem > ptr->mNext->mItem) {
560  element->mNext = ptr->mNext;
561  ptr->mNext = element;
562  mCount++;
563  return;
564  }
565  }
566  mLast->mNext = element; // item goes at end of list
567  mLast = element;
568  mCount++;
569  }
570 }
571 
572 
573 // -------------------------------------------------------
574 // O O F _ P S o r t e r (various versions - no templates)
575 // -------------------------------------------------------
576 
577 //----------------------------------------------------------------------
578 // OOF_ULPSorter::remove
579 // remove the first "item" from the front of the list.
580 //
581 // Returns:
582 // Removed item, 0 if nothing on the list.
583 //----------------------------------------------------------------------
584 
585 unsigned long OOF_ULPSorter::remove()
586 {
587  OOF_ULPSorterElement *element = mFirst;
588  unsigned long data;
589 
590  if (isEmpty())
591  return 0;
592 
593  data = mFirst->mData;
594  if (mFirst == mLast) { // list had one item, now has none
595  mFirst = 0;
596  mLast = 0;
597  } else {
598  mFirst = element->mNext;
599  }
600  mCount--;
601  delete element;
602  return data;
603 }
604 
605 //----------------------------------------------------------------------
606 // OOF_ULPSorter::sortedInsert
607 // Insert an "item" into a list, so that the list elements are
608 // sorted in increasing order.
609 //
610 // Allocate a ListElement to keep track of the item.
611 // If the list is empty, then this will be the only element.
612 // Otherwise, walk through the list, one element at a time,
613 // to find where the new item should be placed.
614 //----------------------------------------------------------------------
615 
616 void
617 OOF_ULPSorter::sortedInsert(unsigned long theItem, unsigned long theData)
618 {
619  OOF_ULPSorterElement *element = new OOF_ULPSorterElement(theItem, theData);
620  OOF_ULPSorterElement *ptr; // keep track
621 
622  if (isEmpty()) { // if list is empty, just bung it in !
623  mFirst = element;
624  mLast = element;
625  mLastInsertEqual=false;
626  mCount = 1;
627  } else if (theItem <= mFirst->mItem) {
628  // item goes on front of list
629  if (theItem == mFirst->mItem) {
630  mLastInsertEqual=true;
631  mEqualInserted=element;
632  element->mPart=mFirst->mPart+1;
633  } else
634  mLastInsertEqual=false;
635  element->mNext = mFirst;
636  mFirst = element;
637  mCount++;
638  } else { // look for first one in list bigger than item
639  for (ptr = mFirst; ptr->mNext != 0; ptr = ptr->mNext)
640  if (theItem == ptr->mNext->mItem) {
641  element->mNext = ptr->mNext;
642  element->mPart = ptr->mNext->mPart+1;
643  ptr->mNext = element;
644  mLastInsertEqual=true;
645  mEqualInserted=element;
646  mCount++;
647  return;
648  } else if (theItem < ptr->mNext->mItem) {
649  element->mNext = ptr->mNext;
650  ptr->mNext = element;
651  mLastInsertEqual=false;
652  mCount++;
653  return;
654  }
655  mLast->mNext = element; // item goes at end of list
656  mLast = element;
657  mLastInsertEqual=false;
658  mCount++;
659  }
660 }
661 
662 //----------------------------------------------------------------------
663 // OOF_ULPSorter::sortedInsertReverse
664 // Insert an "item" into a list, so that the list elements are
665 // sorted in increasing order.
666 //
667 // Allocate a ListElement to keep track of the item.
668 // If the list is empty, then this will be the only element.
669 // Otherwise, walk through the list, one element at a time,
670 // to find where the new item should be placed.
671 //----------------------------------------------------------------------
672 
673 void
674 OOF_ULPSorter::sortedInsertReverse(unsigned long theItem, unsigned long theData)
675 {
676  OOF_ULPSorterElement *element = new OOF_ULPSorterElement(theItem, theData);
677  OOF_ULPSorterElement *ptr; // keep track
678 
679  if (isEmpty()) { // if list is empty, just bung it in !
680  mFirst = element;
681  mLast = element;
682  mLastInsertEqual=false;
683  mCount = 1;
684  } else if (theItem >= mFirst->mItem) {
685  // item goes on front of list
686  if (theItem == mFirst->mItem) {
687  mLastInsertEqual=true;
688  mEqualInserted=element;
689  element->mPart = mFirst->mPart+1;
690  } else
691  mLastInsertEqual=false;
692  element->mNext = mFirst;
693  mFirst = element;
694  mCount++;
695  } else { // look for first one in list smaller than item
696  for (ptr = mFirst; ptr->mNext != 0; ptr = ptr->mNext)
697  if (theItem > ptr->mNext->mItem) {
698  element->mNext = ptr->mNext;
699  ptr->mNext = element;
700  mLastInsertEqual=false;
701  mCount++;
702  return;
703  } else if (theItem == ptr->mNext->mItem) {
704  element->mNext = ptr->mNext;
705  element->mPart = ptr->mNext->mPart+1;
706  ptr->mNext = element;
707  mLastInsertEqual=true;
708  mEqualInserted=element;
709  mCount++;
710  return;
711  }
712  mLast->mNext = element; // item goes at end of list
713  mLast = element;
714  mLastInsertEqual=false;
715  mCount++;
716  }
717 }
718 
719 void
721 {
722 #ifdef OOF_DEBUG
723  if(theItem->mNext==0)
724  dbConnect::raise("Hmm, PSorter::exchange got called, and there's no following record");
725 #endif
726 
727  // Swap the data
728  unsigned long temp, temp2;
729  temp=theItem->mData;
730  temp2=theItem->mPart;
731  theItem->mData=theItem->mNext->mData;
732  theItem->mPart=theItem->mNext->mPart;
733  theItem->mNext->mData=temp;
734  theItem->mNext->mPart=temp2;
735 
736  // Reset the Equality stuff
737  if((theItem->mNext->mNext!=0)&&(theItem->mNext->mItem==theItem->mNext->mNext->mItem)) {
738  mLastInsertEqual=true;
739  mEqualInserted=theItem->mNext;
740  } else {
741  mLastInsertEqual=false;
742  }
743 }
744 
745 //--------//
746 
747 //----------------------------------------------------------------------
748 // OOF_LPSorter::remove
749 //----------------------------------------------------------------------
750 
751 unsigned long OOF_LPSorter::remove()
752 {
753  OOF_LPSorterElement *element = mFirst;
754  unsigned long data;
755 
756  if (isEmpty())
757  return 0;
758 
759  data = mFirst->mData;
760  if (mFirst == mLast) { // list had one item, now has none
761  mFirst = 0;
762  mLast = 0;
763  } else {
764  mFirst = element->mNext;
765  }
766  mCount--;
767  delete element;
768  return data;
769 }
770 
771 //----------------------------------------------------------------------
772 // OOF_LPSorter::sortedInsert
773 //----------------------------------------------------------------------
774 
775 void
776 OOF_LPSorter::sortedInsert(long theItem, unsigned long theData)
777 {
778  OOF_LPSorterElement *element = new OOF_LPSorterElement(theItem, theData);
779  OOF_LPSorterElement *ptr; // keep track
780 
781  if (isEmpty()) { // if list is empty, just bung it in !
782  mFirst = element;
783  mLast = element;
784  mCount = 1;
785  } else if (theItem <= mFirst->mItem) {
786  // item goes on front of list
787  if (theItem == mFirst->mItem) {
788  element->mPart=mFirst->mPart+1;
789  }
790  element->mNext = mFirst;
791  mFirst = element;
792  mCount++;
793  } else { // look for first one in list bigger than item
794  for (ptr = mFirst; ptr->mNext != 0; ptr = ptr->mNext)
795  if (theItem == ptr->mNext->mItem) {
796  element->mNext = ptr->mNext;
797  element->mPart = ptr->mNext->mPart+1;
798  ptr->mNext = element;
799  mCount++;
800  return;
801  } else if (theItem < ptr->mNext->mItem) {
802  element->mNext = ptr->mNext;
803  ptr->mNext = element;
804  mCount++;
805  return;
806  }
807  mLast->mNext = element; // item goes at end of list
808  mLast = element;
809  mCount++;
810  }
811 }
812 
813 //----------------------------------------------------------------------
814 // OOF_LPSorter::sortedInsertReverse
815 //----------------------------------------------------------------------
816 
817 void
818 OOF_LPSorter::sortedInsertReverse(long theItem, unsigned long theData)
819 {
820  OOF_LPSorterElement *element = new OOF_LPSorterElement(theItem, theData);
821  OOF_LPSorterElement *ptr; // keep track
822 
823  if (isEmpty()) { // if list is empty, just bung it in !
824  mFirst = element;
825  mLast = element;
826  mCount = 1;
827  } else if (theItem >= mFirst->mItem) {
828  // item goes on front of list
829  if (theItem == mFirst->mItem) {
830  element->mPart = mFirst->mPart+1;
831  }
832  element->mNext = mFirst;
833  mFirst = element;
834  mCount++;
835  } else { // look for first one in list smaller than item
836  for (ptr = mFirst; ptr->mNext != 0; ptr = ptr->mNext)
837  if (theItem > ptr->mNext->mItem) {
838  element->mNext = ptr->mNext;
839  ptr->mNext = element;
840  mCount++;
841  return;
842  } else if (theItem == ptr->mNext->mItem) {
843  element->mNext = ptr->mNext;
844  element->mPart = ptr->mNext->mPart+1;
845  ptr->mNext = element;
846  mCount++;
847  return;
848  }
849  mLast->mNext = element; // item goes at end of list
850  mLast = element;
851  mCount++;
852  }
853 }
854 
855 //--------//
856 
857 //----------------------------------------------------------------------
858 // OOF_DPSorter::remove
859 //----------------------------------------------------------------------
860 
861 unsigned long OOF_DPSorter::remove()
862 {
863  OOF_DPSorterElement *element = mFirst;
864  unsigned long data;
865 
866  if (isEmpty())
867  return 0;
868 
869  data = mFirst->mData;
870  if (mFirst == mLast) { // list had one item, now has none
871  mFirst = 0;
872  mLast = 0;
873  } else {
874  mFirst = element->mNext;
875  }
876  mCount--;
877  delete element;
878  return data;
879 }
880 
881 //----------------------------------------------------------------------
882 // OOF_DPSorter::sortedInsert
883 //----------------------------------------------------------------------
884 
885 void
886 OOF_DPSorter::sortedInsert(double theItem, unsigned long theData)
887 {
888  OOF_DPSorterElement *element = new OOF_DPSorterElement(theItem, theData);
889  OOF_DPSorterElement *ptr; // keep track
890 
891  if (isEmpty()) { // if list is empty, just bung it in !
892  mFirst = element;
893  mLast = element;
894  mCount = 1;
895  } else if (theItem <= mFirst->mItem) {
896  // item goes on front of list
897  if (theItem == mFirst->mItem) {
898  element->mPart=mFirst->mPart+1;
899  }
900  element->mNext = mFirst;
901  mFirst = element;
902  mCount++;
903  } else { // look for first one in list bigger than item
904  for (ptr = mFirst; ptr->mNext != 0; ptr = ptr->mNext)
905  if (theItem == ptr->mNext->mItem) {
906  element->mNext = ptr->mNext;
907  element->mPart = ptr->mNext->mPart+1;
908  ptr->mNext = element;
909  mCount++;
910  return;
911  } else if (theItem < ptr->mNext->mItem) {
912  element->mNext = ptr->mNext;
913  ptr->mNext = element;
914  mCount++;
915  return;
916  }
917  mLast->mNext = element; // item goes at end of list
918  mLast = element;
919  mCount++;
920  }
921 }
922 
923 //----------------------------------------------------------------------
924 // OOF_DPSorter::sortedInsertReverse
925 //----------------------------------------------------------------------
926 
927 void
928 OOF_DPSorter::sortedInsertReverse(double theItem, unsigned long theData)
929 {
930  OOF_DPSorterElement *element = new OOF_DPSorterElement(theItem, theData);
931  OOF_DPSorterElement *ptr; // keep track
932 
933  if (isEmpty()) { // if list is empty, just bung it in !
934  mFirst = element;
935  mLast = element;
936  mCount = 1;
937  } else if (theItem >= mFirst->mItem) {
938  // item goes on front of list
939  if (theItem == mFirst->mItem) {
940  element->mPart = mFirst->mPart+1;
941  }
942  element->mNext = mFirst;
943  mFirst = element;
944  mCount++;
945  } else { // look for first one in list smaller than item
946  for (ptr = mFirst; ptr->mNext != 0; ptr = ptr->mNext)
947  if (theItem > ptr->mNext->mItem) {
948  element->mNext = ptr->mNext;
949  ptr->mNext = element;
950  mCount++;
951  return;
952  } else if (theItem == ptr->mNext->mItem) {
953  element->mNext = ptr->mNext;
954  element->mPart = ptr->mNext->mPart+1;
955  ptr->mNext = element;
956  mCount++;
957  return;
958  }
959  mLast->mNext = element; // item goes at end of list
960  mLast = element;
961  mCount++;
962  }
963 }
unsigned long mData
Definition: ooflist.h:118
void sortedInsert(double theItem, unsigned long theData)
Definition: ooflist.cpp:509
virtual unsigned long remove()
Definition: ooflist.cpp:585
unsigned long mData
Definition: ooflist.h:332
static void raise(std::ostream &, bool terminateAfterMsg=true)
void sortedInsertReverse(unsigned long theItem, unsigned long theData)
Put item into list sorted.
Definition: ooflist.cpp:318
bool member(unsigned long theItem) const
Is theItem in the list.
Definition: ooflist.cpp:115
void sortedInsertReverse(long theItem, unsigned long theData)
Definition: ooflist.cpp:818
precompilation header.
virtual unsigned long remove()
Take item off the front of the list.
Definition: ooflist.cpp:231
Tries to hide the different platforms and version issues with standard IO.
void sortedInsert(unsigned long theItem, unsigned long theData)
Definition: ooflist.cpp:263
unsigned long mData
Definition: ooflist.h:384
void sortedInsertReverse(unsigned long theItem, unsigned long theData)
Definition: ooflist.cpp:674
unsigned long mData
Definition: ooflist.h:271
unsigned long mItem
Definition: ooflist.h:69
unsigned short mPart
Definition: ooflist.h:333
Sortable list element for one unsigned long.
Definition: ooflist.h:106
OOF_LPSorterElement * mNext
Definition: ooflist.h:327
void append(unsigned long theItem)
Put item at the end of the list.
Definition: ooflist.cpp:42
void sortedInsert(long theItem, unsigned long theData)
Definition: ooflist.cpp:415
void sortedInsert(unsigned long theItem, unsigned long theData)
Definition: ooflist.cpp:617
OOF_DPSorterElement * mNext
Definition: ooflist.h:379
unsigned long mData
Definition: ooflist.h:176
Element for partitionable, sortable list of longs.
Definition: ooflist.h:319
Element for sortable list of longs.
Definition: ooflist.h:164
OOF_ULSorterElement * mNext
Definition: ooflist.h:113
void exchange(OOF_ULPSorterElement *theItem)
Definition: ooflist.cpp:720
virtual unsigned long remove()
Definition: ooflist.cpp:861
unsigned short mPart
Definition: ooflist.h:385
OOF_DSorterElement * mNext
Definition: ooflist.h:217
void sortedInsert(long theItem, unsigned long theData)
Definition: ooflist.cpp:776
virtual unsigned long remove()
Definition: ooflist.cpp:751
unsigned short mPart
Definition: ooflist.h:272
Element for partitionable, sortable list of unsigned longs.
Definition: ooflist.h:258
unsigned long mItem
Definition: ooflist.h:117
void sortedInsertNoDups(unsigned long theItem)
Put item into list sorted only if not already there.
Definition: ooflist.cpp:179
Elements used in OOF_ListBase.
Definition: ooflist.h:59
unsigned long mItem
Definition: ooflist.h:270
unsigned long mData
Definition: ooflist.h:222
OOF_LSorterElement * mNext
Definition: ooflist.h:171
virtual unsigned long remove()
Take item off the front of the list.
Definition: ooflist.cpp:90
void prepend(unsigned long theItem)
Put item at the beginning of the list.
Definition: ooflist.cpp:68
void sortedInsert(unsigned long theItem)
Put item into list sorted.
Definition: ooflist.cpp:139
OOF_ULPSorterElement * mNext
Definition: ooflist.h:266
virtual unsigned long remove()
Definition: ooflist.cpp:390
Defines varying list types because we run on older compilers instead of templating lists...
OOF_ListElement * mNext
Definition: ooflist.h:65
void exchange(OOF_ULSorterElement *theItem)
Definition: ooflist.cpp:362
Element for sortable list of doubles.
Definition: ooflist.h:210
void sortedInsertReverse(double theItem, unsigned long theData)
Definition: ooflist.cpp:543
Sortable list of doubles with partitioning for nested sorts.
Definition: ooflist.h:371
void sortedInsertReverse(long theItem, unsigned long theData)
Definition: ooflist.cpp:449
void sortedInsert(double theItem, unsigned long theData)
Definition: ooflist.cpp:886
virtual unsigned long remove()
Definition: ooflist.cpp:484
void sortedInsertReverse(double theItem, unsigned long theData)
Definition: ooflist.cpp:928