home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / alt / amateur / 418 < prev    next >
Encoding:
Internet Message Format  |  1992-12-26  |  4.8 KB

  1. Xref: sparky alt.amateur-comp:418 comp.lang.c:19036 comp.lang.c++:18553 comp.misc:4728
  2. Path: sparky!uunet!mcsun!uknet!warwick!doc.ic.ac.uk!agate!spool.mu.edu!uwm.edu!zaphod.mps.ohio-state.edu!swrinde!network.ucsd.edu!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  3. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  4. Newsgroups: alt.amateur-comp,comp.lang.c,comp.lang.c++,comp.misc
  5. Subject: Re: What is Object Oriented Programming? Is C doomed?
  6. Message-ID: <1992Dec30.191012.28786@ucc.su.OZ.AU>
  7. Date: 30 Dec 92 19:10:12 GMT
  8. References: <1992Dec28.015333.5242@ucc.su.OZ.AU> <1992Dec29.211256.188@fcom.cc.utah.edu>
  9. Sender: news@ucc.su.OZ.AU
  10. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  11. Lines: 108
  12. Nntp-Posting-Host: extro.ucc.su.oz.au
  13.  
  14. In article <1992Dec29.211256.188@fcom.cc.utah.edu> swillden@news.ccutah.edu (Shawn Willden) writes:
  15. >maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
  16. >:     You dont understand, see my attempt at explaining above.
  17. >: A suitable cache which is 1% the size of the list guarrantees
  18. >: random read and write. End of story.
  19. >
  20. >A more intuitive explanation is this:  If your cache has n/100
  21. >elements, you can break the list up into n/100 + 1 pieces and know
  22. >easily which piece a given element is in.  Then, to find the element
  23. >you want you need only traverse the appropriate piece.  Since there is
  24. >1 element of the cache for every 100 elements of the list, the longest
  25. >any piece need be is 100 elements.  If you have 1 cache entry for
  26. >every m elements of the list, the longest a piece need be is m.
  27.  
  28.     Yes. For arbitrary list size, read/write is O(1) but
  29. of course insert and delete is not.
  30.  
  31.     You can do better than this if you also want fast 
  32. sequential access (in the forward direction). Have another
  33. cache of size m.
  34.  
  35.     When you ask for element i, after you find
  36. it cache the pointer into slot i%m.
  37.  
  38.     Setting m=2 is great for insertions in a singly
  39. linked list at the current position. m>2 allows some
  40. backtracking.
  41.  
  42.     I allow 'indexed' access to the list: the user
  43. thinks its an array with insert and delete operations.
  44. I have implemented cache version 2, but not the one
  45. I originally described.
  46.  
  47.     That because although it looks like an array,
  48. I know its a list, and also because none of my lists
  49. have been big enough (yet) to worry.
  50.  
  51.  
  52.     The main point is that I can access it as a singly
  53. linked list like this:
  54.  
  55.     for(int i=1; i<+l; ++i) l[i]=X;
  56.  
  57. and its fast, but if I *really* want to get the n'th element,
  58. I can just say
  59.  
  60.     X=l[n];
  61.  
  62. and am not constrained by the implementation. Note this
  63. is NOT a 'list' in the sense that lists can be linked
  64. together to form trees, my lists cannot share common
  65. parts.
  66.  
  67. >This technique allows random access (read/write) in known time and
  68. >also allows easy insertions and deletions.  Insertions and deletions
  69. >can require major changes to the cache (which could require traversal
  70. >of a large part of the list) but a reasonable algorithm could minimize
  71. >these, only adjusting the cache when, for example, some access
  72. >required 150 nodes to be traversed.  This would, of course, require
  73. >the cache to contain indices as well as pointers.
  74.  
  75.     Yes. But cache type2 is easily adjusted on insertion
  76. or deletion. On insertion, just add 1 to all indices after
  77. the insertion point (which is still O(n), however).
  78. On deletion you might have to remove one pointer from the cache.
  79.  
  80. >
  81. >In addition, other optimizations could allow for even faster access
  82. >when the elements are accessed in common ways, such as sequentially.
  83.  
  84.     Yes, cache type2 does this reasonably well,
  85. and there are no problems with iterators getting out of whack
  86. on insertion and deletion. The iterators are also easy
  87. to use, cause they are just integers.
  88. >
  89. >John:
  90. >
  91. >    Is this scheme similar to the one you had in mind?  If yours
  92. >is better, please share it (or provide references, I suppose I ought
  93. >to check Knuth to see if he has anything like this).
  94.  
  95.     What you described is exactly what I was thinking of,
  96. (but haven't implemented) and I can see you already thought
  97. of what I *have* impemented (cache type 2).
  98.  
  99.     Probably, for each type of access you could
  100. have a different caching scheme. So you could make the cache
  101. abstract perhaps?? And 'mixin' the optimal cache design
  102. on a list by list basis according to your requirements.
  103.  
  104. >
  105. >In any case, I like the idea well enough that I think I'm going to
  106. >start using it.
  107. >
  108.  
  109.     I havent even tried doubly linked lists yet.
  110. After all, that 'back link' is just a 'distributed cache'.
  111.  
  112.     There are lots of permutations one could try.
  113. No one would be optimal for all cases of course.
  114.  
  115.     Sometimes even a preallocated array would be best :-)
  116.  
  117. -- 
  118. ;----------------------------------------------------------------------
  119.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  120.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  121. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  122.