Files
harbour-core/harbour/contrib/btree/test/ttest.prg
April White 5fe776f5a2 2002-07-14 14:14 UTC+0500 April White <awhite@mail.rosecom.ca>
* contrib/btree/hb_btree.api
    + extern "C"
    * rename nFlags to ulFlags
    + declaration for hb_BTreeDataItem()
    * declaration for hb_BTreeInsert() to use a PHB_ITEM vs LONG

  * contrib/btree/hb_btree.ch
    - comments from around 'inmemory' definition

  * contrib/btree/test/test.prg
    + code to test in-memory tree, including passing floats vs longs

  * contrib/btree/test/ctest.c
    ! a SEEK call that was incorrectly failing because the
      DATA param passed as 0
    * hb_BTreeInsert() calls to use new form (PHB_ITEM vs long)

  * contrib/btree/hb_btree.c
    ; the following warnings are reported by BCC (thanks Alexander):
        Suspicious pointer conversion in function hb_BTreeNew & hb_BTreeOpen
          pBTree->pStrCompare = strncmp;
        Parameter 'ulFlags' is never used in function hb_BTreeOpen
    - defintion and use of DBG() macro
    + extern "C" ifdef'd
    - comments from around 'inmemory' definition
    * renamed nFlags to ulFlags, lFlags to ulFlags, position to iPosition
    * hb_btreenew [hi level] - when flag contains HB_BTREE_INMEMORY,
first
      parameter is ignored
    * hb_btreenew [lo level] - when flag contains HB_BTREE_INMEMORY,
dont
      try to open the file, etc, and clear necessary fields
    * hb_btreeclose [lo level] - close file and release file name only when
      necessary
    * only call HeaderWrite() when not in-memory tree
    + ioOneBufferAlloc() - allocate one ioBuffer_T block, called by
      ioBufferAlloc(), and Grow() when in-memory
    * Grow() in-memory - add a page to the link list
    + Prune() in-memory - added code to remove a page from the link list
    * (assorted) IsDirty flag is assigned the tree property IsDirtyFlagAssignment,
      so that in-memory trees never fire the write methods (ie. always false)
    * hb_BTreeGoTop(), hb_BTreeGoBottom() [lo-level]
      + bug fix: preserve last node found
      + if tree is empty, clear key/data, else retrieve selected key/data
    * ioBufferRead() - moved IsDirty reset within "if ( IsDirty )" block
    * ioBufferScan() - call ioBufferRead() when not in-memory tree
    - SearchNode() redundant BufferRelease() and return statement
    - enum ExceptionTypes (not used)
    - Buffer_T typedef struct, incorporating into the ioBuffer_T typedef struct
    * hb_KeyData_T: replaced lData with a union lData/pData
    + definition for hb_BTreeDataItem()
    * definition for hb_BTreeInsert() to use a PHB_ITEM vs LONG
    * hb_btreeinsert() [hi-level] accepts only number for file i/o and
      any data type for in-memory
    - macro SETKEYDATA(), placing equivalent code into hb_BTreeInsert()
    + Prune() - release individial items and then the page itself
    ! CountAdj() last param should have been SHORT not USHORT
    ; RecDelete() moved the inline assignment & comparision around to remove
      the b32 warning

    TODO: find a solution to the 'Suspicious pointer conversion in function
          hb_BTreeNew & hb_BTreeOpen' [strncmp() & hb_strncmp()]

    TODO: impliment ulFlags within hb_btreeopen() - see warning above
          - clear im-memory flag
          - get unique flag from file header

  * contrib/btree/doc/hb_btree.txt
    * spelling corrections
    * clarified use of HB_BTREE_INMEMORY flag with hb_BTreeNew() API
    ! corrected type of pBTree params, from 'hb_BTree *' to 'struct hb_BTree *'
    + definition for hb_BTreeDataItem()
    * clarified use of data param and data return value
2002-07-14 13:55:16 +00:00

200 lines
5.1 KiB
Plaintext

*
* $Id$
*/
#include "simpleio.ch"
#include "hb_btree.ch"
Procedure TTest()
local n, a
? "Harbour TBTree API test"
n := TBTreeNew( "test_2.out", 2048, 90 )
if n != NIL
? valtype( a := n:info() )
? "File", a[ HB_BTREEINFO_FILENAME ]
? "Page", a[ HB_BTREEINFO_PAGESIZE ]
? "Key ", a[ HB_BTREEINFO_KEYSIZE ]
? "Max ", a[ HB_BTREEINFO_MAXKEYS ]
? "Min ", a[ HB_BTREEINFO_MINKEYS ]
? "Flag", a[ HB_BTREEINFO_FLAGS ]
? "Keys", a[ HB_BTREEINFO_KEYCOUNT ]
?
insertdata( n )
? "Keys", n:info( HB_BTREEINFO_KEYCOUNT )
?
? "Forward traversal"
n:gotop()
while .t.
? n:key(), n:data()
if 1 <> n:skip( 1 )
exit
endif
end
?
? "Reverse traversal"
n:gobottom()
while .t.
? n:key(), n:data()
if -1 <> n:skip( -1 )
exit
endif
end
?
? "Test SEEK"
? n:seek( "cdntyzrf" )
? n:key(), n:data()
n:skip( 1 )
? n:key(), n:data(), "dmfmivqb ?"
?
? "Test soft SEEK of a short key"
? n:seek( "cd", ,.t. )
? n:key(), n:data()
n:skip( 1 )
? n:key(), n:data(), "dmfmivqb ?"
?
? "Test soft SEEK of an existing key"
? n:seek( "cdntyzrf", , .t. )
? n:key(), n:data()
n:skip( 1 )
? n:key(), n:data(), "dmfmivqb ?"
?
? "Test soft SEEK of a missing key, that should force EOF"
? n:seek( "zzzzzz" )
? n:key(), n:data()
n:skip( 1 )
? n:key(), n:data(), "dmfmivqb ?"
?
n:close()
else
? "error"
endif
return
static procedure insertdata( n )
n:insert( "fuweqgsz", 1 )
n:insert( "sjruexrd", 2 )
n:insert( "fvveitnz", 3 )
n:insert( "aqgksjxe", 4 )
n:insert( "oonrehvj", 5 )
n:insert( "gvowjwtr", 6 )
n:insert( "xxidwtvn", 7 )
n:insert( "rwjbxesd", 8 )
n:insert( "yaznsaek", 9 )
n:insert( "wbdhfkfy", 10 )
n:insert( "lryaezia", 11 )
n:insert( "tspmnrvk", 12 )
n:insert( "hpxryhdj", 13 )
n:insert( "sztcqaby", 14 )
n:insert( "fcyzsqja", 15 )
n:insert( "uccxumvg", 16 )
n:insert( "amwuoout", 17 )
n:insert( "yaytseln", 18 )
n:insert( "sfiiozej", 19 )
n:insert( "xuvsoljy", 20 )
n:insert( "qmqjbedm", 21 )
n:insert( "cctzzrkz", 22 )
n:insert( "ikytgdon", 23 )
n:insert( "pksobcwu", 24 )
n:insert( "vmurindj", 25 )
n:insert( "elvybqwg", 26 )
n:insert( "ixchaztx", 27 )
n:insert( "nzpztlhd", 28 )
n:insert( "aucrchiw", 29 )
n:insert( "munrytse", 30 )
n:insert( "kqkhcmls", 31 )
n:insert( "abqhurbi", 32 )
n:insert( "ymrldckr", 33 )
n:insert( "rhsmfflc", 34 )
n:insert( "apyfkvee", 35 )
n:insert( "cdntyzrf", 36 )
n:insert( "iacblqrh", 37 )
n:insert( "xvewqana", 38 )
n:insert( "xmybqytj", 39 )
n:insert( "dnowympf", 40 )
n:insert( "smloihft", 41 )
n:insert( "zumppmis", 42 )
n:insert( "jirucnxu", 43 )
n:insert( "ecdzikcv", 44 )
n:insert( "slbwvnpg", 45 )
n:insert( "yaftlkmz", 46 )
n:insert( "blcepksd", 47 )
n:insert( "xufowlpl", 48 )
n:insert( "xegtjtqc", 49 )
n:insert( "yplcqumq", 50 )
n:insert( "vdoycauz", 51 )
n:insert( "uhqkjuph", 52 )
n:insert( "prllaeyi", 53 )
n:insert( "ybzgmwzm", 54 )
n:insert( "kkvyllnp", 55 )
n:insert( "nberwsrb", 56 )
n:insert( "wgetahua", 57 )
n:insert( "yxcyehcv", 58 )
n:insert( "oacormks", 59 )
n:insert( "mcadkdxo", 60 )
n:insert( "ycsalwqw", 61 )
n:insert( "qmpysvjl", 62 )
n:insert( "iqikamew", 63 )
n:insert( "iaparrva", 64 )
n:insert( "casbvtay", 65 )
n:insert( "blaksexr", 66 )
n:insert( "tbosrbql", 67 )
n:insert( "ifkywsyt", 68 )
n:insert( "gvklwevy", 69 )
n:insert( "krpmpbud", 70 )
n:insert( "rdvlwbwm", 71 )
n:insert( "apnvdkww", 72 )
n:insert( "euqdocvm", 73 )
n:insert( "ksmkjcwp", 74 )
n:insert( "bztgclzc", 75 )
n:insert( "awkdnuxa", 76 )
n:insert( "abavnpod", 77 )
n:insert( "dvwvhjmh", 78 )
n:insert( "dmfmivqb", 79 )
n:insert( "ewsxanon", 80 )
return
/*
* Harbour Project source code:
* hb_btree api test
*
* Copyright 2000 April White <awhite@mail.rosecom.ca>
* www - http://www.harbour-project.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version, with one exception:
*
* The exception is that if you link the Harbour Runtime Library (HRL)
* and/or the Harbour Virtual Machine (HVM) with other files to produce
* an executable, this does not by itself cause the resulting executable
* to be covered by the GNU General Public License. Your use of that
* executable is in no way restricted on account of linking the HRL
* and/or HVM code into it.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit
* their web site at http://www.gnu.org/).
*
*/