anchor.diff:                                                !  |  14  |  87  |
                                                 !  |  18  |  85  |
                                                 !  |  42  |  78  |
  -  CALL HASH_SORT(H,ASC)                       !  |  44  |  72  |        
  -  CALL HASH_SORT(H,DESC,.FALSE.)              !  |  60  |  64  |
  +  CALL BTREE_SORT(BT,ASC)                     !  |  44  |  72  |        
  +  CALL BTREE_SORT(BT,DESC,.FALSE.)            !  |  60  |  64  |
     DO I = 1, 10                                !  |  64  |  60  |
       WRITE(6,'(2I8)') ASC(I),DESC(I)           !  |  72  |  44  |
     END DO                                      !  |  78  |  42  |
  
positive.code:   END IF
    I = 1
    C = 0
    CALL HASH_SORTED(H,ARRAY,I,C,ASC)
  END SUBROUTINE HASH_SORT
  ! ---------------------------------------------------------------------------------------------------------------------------------+
  RECURSIVE SUBROUTINE HASH_SORTED(H,ARRAY,I,C,ASCENDING)
  TYPE(HASH), INTENT(IN)    :: H
  INTEGER(KIND=4),INTENT(INOUT) :: ARRAY(:)
  INTEGER(KIND=4),INTENT(IN)    :: I
  INTEGER(KIND=4),INTENT(INOUT) :: C
  LOGICAL(KIND=4),INTENT(IN)    :: ASCENDING
  IF (ASCENDING) THEN
    IF (H%HASH(2,I).NE.0) CALL HASH_SORTED(H,ARRAY,H%HASH(2,I),C,ASCENDING)
    IF (C.GT.SIZE(ARRAY)) RETURN
    C = C + 1
    ARRAY(C) = H%HASH(1,I)
    IF (H%HASH(3,I).NE.0) CALL HASH_SORTED(H,ARRAY,H%HASH(3,I),C,ASCENDING)
  ELSE
    IF (H%HASH(3,I).NE.0) CALL HASH_SORTED(H,ARRAY,H%HASH(3,I),C,ASCENDING)
    IF (C.GT.SIZE(ARRAY)) RETURN
    C = C + 1
    ARRAY(C) = H%HASH(1,I)
    IF (H%HASH(2,I).NE.0) CALL HASH_SORTED(H,ARRAY,H%HASH(2,I),C,ASCENDING)
  END IF
  END SUBROUTINE HASH_SORTED
  ! ---------------------------------------------------------------------------------------------------------------------------------+
  END MODULE MODHASH
  ! ---------------------------------------------------------------------------------------------------------------------------------+
  PROGRAM HASHTEST
  USE MODHASHCODE
  USE MODHASH
  IMPLICIT NONE
  INTEGER(KIND=4)           :: RES,I,J
  INTEGER(KIND=1),PARAMETER :: IDIV = 11
  
negative.code: CHARACTER(LEN=16)         :: STR16 = '   Some String  '
  CHARACTER(LEN=20)         :: STR20 = '1 34 tmp xyz  t '
  CHARACTER(LEN=24)         :: STR24 = '  ABCDEFGHIJKLMNO       '
  TYPE(BTREE)               :: BT
  INTEGER(KIND=4)           :: ASC(10),DESC(10)
    WRITE(6,'("0*** HASHTEST - INTEGER ********")')
    WRITE(6,'("       HASHCODE OF INT1  ",I20,    " = ",I11)')  INT1, HASHCODE( INT1)
    WRITE(6,'("       HASHCODE OF INT2  ",I20,    " = ",I11)')  INT2, HASHCODE( INT2)
    WRITE(6,'("       HASHCODE OF INT4  ",I20,    " = ",I11)')  INT4, HASHCODE( INT4)
    WRITE(6,'("       HASHCODE OF INT8  ",I20,    " = ",I11)')  INT8, HASHCODE( INT8)
    WRITE(6,'("0*** HASHTEST - REAL    ********")')
    WRITE(6,'("       HASHCODE OF REAL4 ",G20.10, " = ",I11)') REAL4, HASHCODE(REAL4)
    WRITE(6,'("       HASHCODE OF REAL8 ",G20.10, " = ",I11)') REAL8, HASHCODE(REAL8)
    WRITE(6,'("0*** HASHTEST - STRING  ********")')
    WRITE(6,'("       HASHCODE OF STR12 ",12X,A12," = ",I11)') STR12, HASHCODE(STR12)
    WRITE(6,'("       HASHCODE OF STR16 ", 8X,A16," = ",I11)') STR16, HASHCODE(STR16)
    WRITE(6,'("       HASHCODE OF STR20 ", 4X A20," = ",I11)') STR20, HASHCODE(STR20)
    WRITE(6,'("       HASHCODE OF STR24 ",    A24," = ",I11)') STR24, HASHCODE(STR24)
  
    CALL BTREE_INIT(BT)
    WRITE(6,'("CAPACITY = ",I4,", COUNT = ",I4)') SIZE(BT%TREE,2), BT%COUNT
  
                                                !            +------+       +------+------+
                                                !  IND       |VALUES|       |BEFORE|AFTER |              44
                                                !            +------+       +------+------+             /  \
    RES = BTREE_ADD(BT,44)                      !   1        |  44  |       |  4   |   2  |           42    64
    RES = BTREE_ADD(BT,64)                      !   2        |  64  |       |  7   |   3  |          /     /   \
    RES = BTREE_ADD(BT,87)                      !   3        |  87  |       |  5   |   0  |        14    60    87
    RES = BTREE_ADD(BT,42)                      !   4        |  42  |       |  6   |   0  |          \        /
    RES = BTREE_ADD(BT,85)                      !   5        |  85  |       |  8   |   0  |           18    85
    RES = BTREE_ADD(BT,14)                      !   6        |  14  |       |  0   |  10  |                /
    RES = BTREE_ADD(BT,60)                      !   7        |  60  |       |  0   |   0  |              78
    RES = BTREE_ADD(BT,78)                      !   8        |  78  |       |  9   |   0  |             /
    RES = BTREE_ADD(BT,72)                      !   9        |  72  |       |  0   |   0  |           72
    RES = BTREE_ADD(BT,18)                      !  10        |  18  |       |  0   |   0  |
                                                !            +------+       +------+------+
  
    WRITE(6,'("CAPACITY = ",I4,", COUNT = ",I4)') SIZE(BT%TREE,2), BT%COUNT
  
    DO I = 1, BT%COUNT
      WRITE(6,'(3I8)') (BT%TREE(J,I),J=1,3)
    END DO
  
                                                !  +------+------+
                                                !  | ASC  | DESC |
  