User Tools

Site Tools


cdc:nos2.source:nam5871:ndlsst

NDLSST

Table Of Contents

  • [00002] PROC NDLSST(TABLE,FRST$WORD,BIT$POS,MASK,ENT$SZ,NUM$ENT)
  • [00006] SHELL SORT TABLE.

Source Code

NDLSST.txt
  1. *DECK NDLSST
  2. PROC NDLSST(TABLE,FRST$WORD,BIT$POS,MASK,ENT$SZ,NUM$ENT);
  3. BEGIN
  4. *IF,DEF,IMS
  5. #
  6. ** NDL$SST - SHELL SORT TABLE.
  7. *
  8. * D.K. ENDO 81/11/10
  9. *
  10. * THIS PROCEDURE USES SHELL-S METHOD FOR SORTING A TABLE. (SEE CACM
  11. * VOL. 6 NUMBER 5 MAY 1963, PAGE 209)
  12. *
  13. * PROC NDL$SST(TABLE,FRST$WORD,BIT$POS,MASK,ENT$SZ,NUM$ENT)
  14. *
  15. * ENTRY TABLE = TABLE TO BE SORTED.
  16. * FRST$WORD = FIRST WORD IN TABLE TO BEGIN SORT.
  17. * BIT$POS = BEGINNING BIT POSITION OF MASK.
  18. * MASK = LENGTH OF MASK IN NUMBER OF BITS.
  19. * ENT$SZ = ENTRY SIZE IN CP WORDS.
  20. * NUM$ENT = NUMBER OF ENTRIES TO BE SORTED.
  21. *
  22. * EXIT TABLE = TABLE SORTED IN ASCENDING ORDER.
  23. *
  24. * METHOD
  25. *
  26. * FOR I=1 STEP I UNTIL NUM$ENT,
  27. * GAP = 2 * I - 1
  28. * FOR GAP=GAP/2 WHILE M NQ ZERO,
  29. * K = NUM$ENT - GAP.
  30. * FOR J=1 STEP 1 UNTIL K,
  31. * FOR I=J STEP -GAP UNTIL ONE,
  32. * IF ENTRY[I+GAP] LESS THAN ENTRY[I],
  33. * EXCHANGE THE TWO ENTRIES.
  34. *
  35. * THE FIRST LOOP DETERMINES GAP AS THE CLOSEST POWER OF TWO TO THE
  36. * ENTRY COUNT, MINUS ONE. THE SECOND LOOP CONTROLS THE GAP BETWEEN
  37. * COMPARED ELEMENTS. INITIALLY GAP/2, IT SHRINKS BY A FACTOR OF TWO
  38. * EACH PASS UNTIL IT BECOMES ZERO. THE THIRD LOOP COMPARES ELEMENTS
  39. * SEPARATED BY GAP. THE FOURTH LOOP EXCHANGES ANY THAT ARE OUT OF
  40. * ORDER.
  41. *
  42. #
  43. *ENDIF
  44. ITEM FRST$WORD; # FIRST WORD TO BE SORTED #
  45. ITEM BIT$POS; # BEGINNING BIT POSITION OF MASK #
  46. ITEM MASK; # LENGTH OF MASK IN NUMBER OF BITS #
  47. ITEM ENT$SZ; # LENGTH OF EACH ENTRY IN CP WORDS #
  48. ITEM NUM$ENT; # NUMBER OF ENTRIES IN TABLE #
  49. ARRAY TABLE[0:0] S(1);# TABLE TO BE SORTED #
  50. BEGIN
  51. ITEM TBL$WORD (0,0,60);
  52. END
  53. # #
  54. ITEM GAP; # NUMBER OF ENTRIES BETWEEN THE TWO #
  55. # ELEMENTS BEING COMPARED #
  56. ITEM I; # POINTER TO THE 1ST OF THE 2 ELEMENTS TO #
  57. # BE COMPARED #
  58. ITEM J; # USED TO INITIALIZE -I- #
  59. ITEM K; # LAST VALUE FOR -I- BEFORE NEXT PASS #
  60. ITEM L; # USED FOR STEPPING THRU THE EXCHANGE OF #
  61. # EACH WORD IN THE ENTRY #
  62. CONTROL EJECT;
  63. # #
  64. # SHELL SORT CODE BEGINS HERE #
  65. # #
  66. GAP = 0; # INITIALIZE GAP VALUE #
  67. FOR I=1 STEP I WHILE I LQ NUM$ENT DO
  68. BEGIN # GAP = THE CLOSEST POWER OF TWO TO THE #
  69. GAP = (2 * I) - 1; # ENTRY COUNT, MINUS 1 #
  70. END
  71.  
  72. # DIVIDE THE GAP BY TWO FOR EACH PASS #
  73. FOR GAP = GAP/2 WHILE GAP NQ 0 DO
  74. BEGIN
  75.  
  76. #CALCULATE POSITION OF LAST ELMT MINUS GAP#
  77. K = FRST$WORD + (NUM$ENT -(GAP + 1)) * ENT$SZ;
  78.  
  79. # BEGINNING W/1ST ELMT INCR TO NEXT ONE #
  80. FOR J=FRST$WORD STEP ENT$SZ UNTIL K DO
  81. BEGIN
  82.  
  83. # BEGINNING W/-J- COMPARE ELEMENT ABOVE #
  84. FOR I=J STEP -(GAP * ENT$SZ) WHILE I GQ FRST$WORD DO
  85. BEGIN
  86.  
  87. # IF 2ND ELEMENT IS LESS THAN 1ST, #
  88. # THEN EXCHANGE THEM #
  89. IF B<BIT$POS,MASK>TBL$WORD[I + (GAP * ENT$SZ)] LS
  90. B<BIT$POS,MASK>TBL$WORD[I]
  91. THEN
  92. BEGIN
  93.  
  94. # EXCHANGE THE ENTRY WORD BY WORD #
  95. FOR L=0 STEP 1 UNTIL ENT$SZ-1 DO
  96. BEGIN
  97.  
  98. TBL$WORD[I + (GAP * ENT$SZ) + L] == TBL$WORD[I + L];
  99. END
  100. END
  101. END
  102. END
  103. GAP = GAP/2; # DIVIDE THE GAP BY TWO #
  104. END
  105. RETURN; # **** RETURN **** #
  106. END # NDLSST #
  107. TERM
cdc/nos2.source/nam5871/ndlsst.txt ยท Last modified: 2023/08/05 17:22 by Site Administrator