home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 4 / AACD04.ISO / AACD / Programming / lsEstuff / old_lists / collectionX.e < prev    next >
Encoding:
Text File  |  1999-10-14  |  10.3 KB  |  439 lines

  1. OPT MODULE
  2.  
  3. MODULE '*xli'
  4.  
  5. EXPORT OBJECT collectionX OF xli
  6. ENDOBJECT
  7.  
  8. EXPORT OBJECT xniv OF xni
  9.    value
  10. ENDOBJECT
  11.  
  12. EXPORT OBJECT collectionX_CPObj OF xli_CPObj
  13. ENDOBJECT
  14.  
  15. PROC private_Methods_From_Here() OF collectionX IS EMPTY
  16.  
  17. PROC collectionX() OF collectionX IS TRUE
  18.  
  19. PROC countX() OF collectionX
  20.    DEF n:REG PTR TO xniv
  21.    DEF count:REG
  22.    count := NIL
  23.    n := self.first()
  24.    WHILE n
  25.       IF n.value <> NIL THEN INC count
  26.       n := n.next
  27.    ENDWHILE
  28. ENDPROC count
  29.  
  30. PROC absVals() OF collectionX
  31.    DEF n:PTR TO xniv
  32.    DEF useful=NIL
  33.    n := self.first()
  34.    WHILE n
  35.       IF n.value < 0
  36.          n.value := Abs(n.value)
  37.          INC useful
  38.       ENDIF
  39.       n := n.next
  40.    ENDWHILE
  41. ENDPROC useful
  42.  
  43. PROC getSumVals() OF collectionX
  44.    DEF n:REG PTR TO xniv
  45.    DEF sum:REG
  46.    sum := NIL
  47.    n := self.first()
  48.    WHILE n
  49.       sum := sum + n.value
  50.       n := n.next
  51.    ENDWHILE
  52. ENDPROC sum
  53.  
  54. PROC getAveVals() OF collectionX
  55.    DEF sum:REG
  56.    DEF count:REG
  57.    DEF n:REG PTR TO xniv
  58.    sum := NIL
  59.    count := NIL
  60.    n := self.first()
  61.    WHILE n
  62.       INC count
  63.       sum := sum + n.value
  64.       n := n.next
  65.    ENDWHILE
  66.    IF count = NIL THEN RETURN NIL
  67. ENDPROC sum / count
  68.  
  69. PROC getMaxVal() OF collectionX
  70.    DEF n:REG PTR TO xniv
  71.    DEF val:REG
  72.    val:=$80000000
  73.    n := self.first()
  74.    WHILE n
  75.       val := IF val < n.id THEN n.id ELSE val
  76.       n := n.next
  77.    ENDWHILE
  78. ENDPROC val
  79.  
  80. PROC getMinVal() OF collectionX
  81.    DEF n:REG PTR TO xniv
  82.    DEF val:REG
  83.    val:=$40000000
  84.    n := self.first()
  85.    WHILE n
  86.       val := IF val > n.id THEN n.id ELSE val
  87.       n := n.next
  88.    ENDWHILE
  89. ENDPROC val
  90.  
  91. EXPORT PROC createIVN(id, value)
  92.    DEF n:PTR TO xniv
  93.    n := FastNew(SIZEOF xniv)
  94.    n.id := id
  95.    n.value := value
  96. ENDPROC n
  97.  
  98. EXPORT PROC deleteIVN(n:PTR TO xniv)
  99.    FastDispose(n, SIZEOF xniv)
  100. ENDPROC
  101.  
  102. /* needs sorted lists ! */
  103. PROC applyExistsFrom(collectionX:PTR TO collectionX) OF collectionX
  104.    DEF thisnode:REG PTR TO xniv
  105.    DEF thatnode:REG PTR TO xniv
  106.    DEF useful:REG
  107.    useful := NIL
  108.    thisnode := self.first()
  109.    thatnode := collectionX.first()
  110.    WHILE (thisnode AND thatnode)
  111.       IF thisnode.id = thatnode.id
  112.          thisnode.value := thatnode.value
  113.          thisnode := thisnode.next
  114.          thatnode := thatnode.next
  115.          INC useful
  116.       ELSEIF thisnode.id > thatnode.id
  117.          thatnode := thatnode.next
  118.       ELSE
  119.          thisnode := thisnode.next
  120.       ENDIF
  121.    ENDWHILE
  122. ENDPROC useful
  123.  
  124. PROC applyANDFrom(collectionX:PTR TO collectionX) OF collectionX
  125.    DEF thisnode:REG PTR TO xniv
  126.    DEF thatnode:REG PTR TO xniv
  127.    DEF useful:REG
  128.    useful := NIL
  129.    thisnode := self.first()
  130.    thatnode := collectionX.first()
  131.    WHILE (thisnode AND thatnode)
  132.       IF thisnode.id = thatnode.id
  133.          thisnode.value := thatnode.value AND thisnode.value
  134.          thisnode := thisnode.next
  135.          thatnode := thatnode.next
  136.          INC useful
  137.       ELSEIF thisnode.id > thatnode.id
  138.          thatnode := thatnode.next
  139.       ELSE
  140.          thisnode := thisnode.next
  141.       ENDIF
  142.    ENDWHILE
  143. ENDPROC useful
  144.  
  145. PROC applyNewFrom(collectionX:PTR TO collectionX) OF collectionX
  146.    DEF thisnode:PTR TO xniv
  147.    DEF thatnode:PTR TO xniv
  148.    DEF newnode:PTR TO xniv
  149.    DEF hits=NIL
  150.    thisnode := self.first()
  151.    thatnode := collectionX.first()
  152.    WHILE thatnode
  153.       IF thisnode.id > thatnode.id
  154.          newnode := FastNew(SIZEOF xniv)
  155.          newnode.id := thatnode.id
  156.          newnode.value := thatnode.value
  157.          self.ordInsert(newnode)
  158.          thatnode := thatnode.next
  159.          INC hits
  160.       ELSEIF thisnode.id < thatnode.id
  161.          thisnode := thisnode.next
  162.       ELSE
  163.          thisnode := thisnode.next
  164.          thatnode := thatnode.next
  165.       ENDIF
  166.    ENDWHILE
  167. ENDPROC hits
  168.  
  169. PROC applyAllFrom(collectionX:PTR TO collectionX) OF collectionX
  170.    DEF thisnode:PTR TO xniv
  171.    DEF thatnode:PTR TO xniv
  172.    DEF newnode:PTR TO xniv
  173.    thisnode := self.first()
  174.    thatnode := collectionX.first()
  175.    WHILE thatnode
  176.       IF thisnode.id > thatnode.id
  177.          newnode := FastNew(SIZEOF xniv)
  178.          newnode.id := thatnode.id
  179.          newnode.value := thatnode.value
  180.          self.ordInsert(newnode)
  181.          thatnode := thatnode.next
  182.       ELSEIF thisnode.id < thatnode.id
  183.          thisnode := thisnode.next
  184.       ELSE
  185.          thisnode.value := thatnode.value
  186.          thisnode := thisnode.next
  187.          thatnode := thatnode.next
  188.       ENDIF
  189.    ENDWHILE
  190. ENDPROC
  191.  
  192. PROC applyAveFrom(collectionX:PTR TO collectionX) OF collectionX
  193.    DEF thisnode:PTR TO xniv
  194.    DEF thatnode:PTR TO xniv
  195.    DEF newnode:PTR TO xniv
  196.    thisnode := self.first()
  197.    thatnode := collectionX.first()
  198.    WHILE thatnode
  199.       IF thisnode.id > thatnode.id
  200.          newnode := FastNew(SIZEOF xniv)
  201.          newnode.id := thatnode.id
  202.          newnode.value := (thatnode.value) / 2
  203.          self.ordInsert(newnode)
  204.          thatnode := thatnode.next
  205.       ELSEIF thisnode.id < thatnode.id
  206.          thisnode := thisnode.next
  207.       ELSE
  208.          thisnode.value := ((thatnode.value) + (thisnode.value)) / 2
  209.          thisnode := thisnode.next
  210.          thatnode := thatnode.next
  211.       ENDIF
  212.    ENDWHILE
  213. ENDPROC
  214.  
  215. PROC applyORFrom(collectionX:PTR TO collectionX) OF collectionX
  216.    DEF thisnode:PTR TO xniv
  217.    DEF thatnode:PTR TO xniv
  218.    DEF newnode:PTR TO xniv
  219.    thisnode := self.first()
  220.    thatnode := collectionX.first()
  221.    WHILE thatnode
  222.       IF thisnode.id > thatnode.id
  223.          newnode := FastNew(SIZEOF xniv)
  224.          newnode.id := thatnode.id
  225.          newnode.value := thatnode.value
  226.          self.ordInsert(newnode)
  227.          thatnode := thatnode.next
  228.       ELSEIF thisnode.id < thatnode.id
  229.          thisnode := thisnode.next
  230.       ELSE
  231.          thisnode.value := thatnode.value OR thisnode.value
  232.          thisnode := thisnode.next
  233.          thatnode := thatnode.next
  234.       ENDIF
  235.    ENDWHILE
  236. ENDPROC
  237.  
  238. PROC set(id, value) OF collectionX
  239.    DEF n:PTR TO xniv
  240.    n := self.ordFind(id)
  241.    IF n = NIL
  242.       ->IF value = NIL THEN RETURN NIL
  243.       n := FastNew(SIZEOF xniv)
  244.       n.id := id
  245.       n := self.ordInsert(n)
  246.    ENDIF
  247.    n.value := value
  248. ENDPROC n
  249.  
  250. PROC get(id) OF collectionX
  251.    DEF n:PTR TO xniv
  252.    n := self.ordFind(id)
  253.    IF n = NIL THEN RETURN NIL
  254. ENDPROC n.value
  255.  
  256. PROC unSet(id) OF collectionX
  257.    DEF n:PTR TO xniv
  258.    n := self.ordFind(id)
  259.    IF n = NIL THEN RETURN NIL
  260.    self.removeFastDispose(n, SIZEOF xniv)
  261. ENDPROC
  262.  
  263. PROC clear() OF collectionX
  264.    self.removeFastDisposeAll(SIZEOF xniv)
  265. ENDPROC
  266.  
  267. PROC cleanUp() OF collectionX
  268.    DEF n:PTR TO xniv
  269.    n := self.first()
  270.    WHILE n
  271.       IF n.value = NIL THEN n := self.removeFastDispose(n, SIZEOF xniv)
  272.       n := n.next
  273.    ENDWHILE
  274. ENDPROC
  275.  
  276. OBJECT blahaj OF collectionX_CPObj
  277.    arrayptr
  278. ENDOBJECT
  279.  
  280. PROC wblahaL(blahaj:PTR TO blahaj)
  281.    DEF l:PTR TO LONG
  282.    DEF n:PTR TO xniv
  283.    l := blahaj.arrayptr
  284.    n := blahaj.node
  285.    l[] := n.value
  286.    blahaj.arrayptr := (blahaj.arrayptr) + 4
  287. ENDPROC
  288.  
  289. PROC wblahaI(blahaj:PTR TO blahaj)
  290.    DEF l:PTR TO INT
  291.    DEF n:PTR TO xniv
  292.    l := blahaj.arrayptr
  293.    n := blahaj.node
  294.    l[] := n.value
  295.    blahaj.arrayptr := (blahaj.arrayptr) + 2
  296. ENDPROC
  297.  
  298. PROC wblahaC(blahaj:PTR TO blahaj)
  299.    DEF l:PTR TO CHAR
  300.    DEF n:PTR TO xniv
  301.    l := blahaj.arrayptr
  302.    n := blahaj.node
  303.    l[] := n.value
  304.    blahaj.arrayptr := (blahaj.arrayptr) + 1
  305. ENDPROC
  306.  
  307. PROC cBSet(array:PTR TO CHAR, startid, stopid) OF collectionX
  308.    WHILE startid <> (stopid + 1) DO self.set(startid++, array[]++)
  309. ENDPROC
  310.  
  311. PROC iBSet(array:PTR TO INT, startid, stopid) OF collectionX
  312.    WHILE startid <> (stopid + 1) DO self.set(startid++, array[]++)
  313. ENDPROC
  314.  
  315. PROC lBSet(array:PTR TO LONG, startid, stopid) OF collectionX
  316.    WHILE startid <> (stopid + 1) DO self.set(startid++, array[]++)
  317. ENDPROC
  318.  
  319. PROC cBGet(array:PTR TO CHAR, startid, stopid) OF collectionX
  320.    DEF b:PTR TO blahaj
  321.    b.arrayptr := array
  322.    self.travArray({wblahaC}, b, startid, stopid)
  323. ENDPROC
  324.  
  325. PROC iBGet(array:PTR TO CHAR, startid, stopid) OF collectionX
  326.    DEF b:PTR TO blahaj
  327.    b.arrayptr := array
  328.    self.travArray({wblahaI}, b, startid, stopid)
  329. ENDPROC
  330.  
  331. PROC lBGet(array:PTR TO CHAR, startid, stopid) OF collectionX
  332.    DEF b:PTR TO blahaj
  333.    b.arrayptr := array
  334.    self.travArray({wblahaL}, b, startid, stopid)
  335. ENDPROC
  336.  
  337. PROC swapV(id1, id2) OF collectionX
  338.    DEF n1:REG PTR TO xniv
  339.    DEF n2:REG PTR TO xniv
  340.    DEF n:REG PTR TO xniv
  341.    DEF temp
  342.    n1 := NIL
  343.    n2 := NIL
  344.    n := self.first()
  345.    WHILE n
  346.       IF n.id = id1 THEN n1 := n
  347.       IF n.id = id2 THEN n2 := n
  348.       n := IF (n1 AND n2) THEN NIL ELSE n.next
  349.    ENDWHILE
  350.    IF (n1 = NIL) AND (n2 = NIL) THEN RETURN NIL
  351.    IF n1 = NIL
  352.       n1 := createIVN(id1, 0)
  353.       self.ordInsert(n1)
  354.    ENDIF
  355.    IF n2 = NIL
  356.       n2 := createIVN(id2, 0)
  357.       self.ordInsert(n2)
  358.    ENDIF
  359.    temp := n1.value
  360.    n1.value := n2.value
  361.    n2.value := temp
  362. ENDPROC
  363.  
  364. PROC sortV() OF collectionX
  365.    DEF n:REG PTR TO xniv
  366.    DEF nnext:REG PTR TO xniv
  367.    DEF useful:REG
  368.    DEF temp:REG
  369.    REPEAT
  370.       n := self.first()
  371.       useful := FALSE
  372.       WHILE n
  373.          nnext := n.next
  374.          IF nnext
  375.             IF n.value > nnext.value
  376.                temp := n.value
  377.                n.value := nnext.value
  378.                nnext.value := temp
  379.                useful := TRUE
  380.             ENDIF
  381.             n := n.next
  382.          ELSE
  383.             n := NIL
  384.          ENDIF
  385.       ENDWHILE
  386.    UNTIL useful = FALSE
  387. ENDPROC
  388.  
  389. /* this one is clever! :) */
  390. /* fakes nodes that doesnt exist */
  391. PROC indexTraverse(proc, cpobj:PTR TO xli_CPObj, startid, endid) OF collectionX
  392.    DEF n:PTR TO xni
  393.    DEF id
  394.    DEF defnode:xniv
  395.    defnode.next := NIL
  396.    defnode.prev := NIL
  397.    defnode.value := NIL
  398.    cpobj.list := self
  399.    id := startid
  400.    INC endid
  401.    n := self.first()
  402.    WHILE id < endid
  403.       IF (n = NIL) OR (n.id > id)
  404.          defnode.id := id
  405.          cpobj.node := defnode
  406.          proc(cpobj)
  407.          INC id
  408.       ELSE
  409.          IF n.id < id
  410.             n := n.next
  411.          ELSE -> n.id = id
  412.             cpobj.node := n
  413.             proc(cpobj)
  414.             INC id
  415.          ENDIF
  416.       ENDIF
  417.    ENDWHILE
  418. ENDPROC
  419.  
  420. PROC cloneContentsTo(nax:PTR TO collectionX) OF collectionX
  421.    nax.clear()
  422.    self.cloneFastNew(nax, SIZEOF xniv)
  423. ENDPROC self.first()
  424.  
  425. PROC scrollX(amount) OF collectionX IS self.scroll(amount)
  426.  
  427. PROC cmpMapX(nax:PTR TO collectionX) OF collectionX IS self.cmpMap(nax)
  428.  
  429. PROC getMaxX() OF collectionX IS self.getMaxID()
  430.  
  431. PROC getMinX() OF collectionX IS self.getMinID()
  432.  
  433. PROC end() OF collectionX IS self.clear()
  434.  
  435. /*EE folds
  436. -1
  437. 5 1 7 2 9 1 15 8 18 10 21 8 24 12 27 8 30 8 33 4 36 1 40 18 43 18 46 21 49 20 52 20 55 20 58 9 61 3 64 4 67 1 70 6 73 2 75 6 78 6 81 6 84 1 87 1 90 1 93 3 96 3 99 3 102 24 105 22 110 26 113 2 
  438. EE folds*/
  439.