home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 568a.lha / RexxRMF_v1.1 / test.rexx < prev    next >
OS/2 REXX Batch file  |  1991-09-11  |  3KB  |  87 lines

  1.  
  2. /* This example illustrates how to use 'low level' AVL-tree functions */
  3. /* for simple indexing, nothing meaningful is done here.              */
  4.  
  5.  
  6. x = addlib("RexxRMF.library",0,-30,0)
  7.  
  8.  
  9. ix = open_rmf()  /* no data file or index file will be created                */
  10.                  /* simply using search/sort capabilities of AVL              */
  11.                  /* cannot save the index, cuz we did not open it with a name */
  12.  
  13. if ix = '0000 0000'x then exit
  14.  
  15. p = showlist('P')          /* build list of names */
  16.  
  17. do forever                 /* insert names from showlist() into tree */
  18.                            /* insertion occurs such that the names  */
  19.                            /* are sorted in alphabetical order       */
  20.    if p = '' then leave
  21.    parse var p port p      /* parse out a name */
  22.    
  23.    z = add_key(ix,0,port,0) /* add name to the tree */
  24.    
  25. end
  26.  
  27.  
  28. do i = 1 to 100
  29.    treenode = find_pos(ix,0,i)  /* find by position (ie. in sorted order) */
  30.    
  31.    if treenode = '0000 0000'x then leave
  32.    say " Node " i '=' key_value(treenode)  /* print value of key */
  33.    
  34. end
  35.  
  36. do i = 1 to 8
  37.    z = add_key(ix,0,"Ron_nie",0)  /* add a key into the tree */
  38. end
  39.  
  40.    z = add_key(ix,0,"RHONDA",0)  /* add some more keys into the tree */
  41.    z = add_key(ix,0,"RHONDA",0)
  42.    z = add_key(ix,0,"RHONDA",0)
  43.    z = add_key(ix,0,"RONNIE",0)
  44.    z = add_key(ix,0,"RONNIE",0)
  45.    z = add_key(ix,0,"RONNIE",0)
  46.  
  47.  
  48. akey = find_key(ix,0,"IDCMP",1)   /* find key IDCMP in our tree */
  49.  
  50. do until akey = '0000 0000'x
  51.    if akey ~= '0000 0000'x then
  52.       say "FOUND KEY" key_value(akey) "occurence" key_occur(akey) "position" node_pos(akey)
  53.    akey = find_next(ix,0)
  54. end
  55.  
  56.  
  57. string = "R"
  58.  
  59. akey = locate_key(ix,0,string,1)  /* will locate any key beginning with "R" */
  60.  
  61. do until akey = '0000 0000'x
  62.    if akey ~= '0000 0000'x then
  63.       say "LOCATED KEY" key_value(akey) "occurence" key_occur(akey) "position" node_pos(akey)
  64.    akey = locate_next(ix,0)
  65. end
  66.  
  67.  
  68. z = delete_key(ix,0,"RHONDA",1)  /* delete first occurence of RHONDA  */
  69.                                  /* will cause mulitples occur number */
  70.                                  /* to be adjusted accordingly        */
  71.                                  
  72. z = delete_key(ix,0,"RHONDA",1)  /* what was occurence #2 is now occur */
  73.                                  /* occur #1                           */
  74.  
  75.  
  76. do i = 1 to 100
  77.    treenode = find_pos(ix,0,i)  /* find by position (ie. in sorted order) */
  78.    
  79.    if treenode = '0000 0000'x then leave
  80.    say " Node " i '=' key_value(treenode)  /* print value of key */
  81.    
  82. end
  83.  
  84. x = close_rmf(ix,0)      /* close index, releasing mem used       */
  85.  
  86. exit
  87.