home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / reviewed / volume03 / chipset2 / 07 < prev    next >
Encoding:
Text File  |  1993-03-13  |  25.3 KB  |  1,013 lines

  1. From decwrl!athertn!sander.cupertino.ca.us!paul@cs.purdue.edu Wed Jan  6 13:53:34 EST 1993
  2. Submit chipset-2 07/10 
  3. #! /bin/sh
  4. # This is a shell archive.  Remove anything before this line, then unpack
  5. # it by saving it into a file and typing "sh file".  To overwrite existing
  6. # files, type "sh file -c".  You can also feed this as standard input via
  7. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  8. # will see the following message at the end:
  9. #        "End of archive 7 (of 10)."
  10. # Contents:  Makefile src/btree/btree.man
  11. # Wrapped by paul@sander on Sun Nov 22 15:41:53 1992
  12. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  13. if test -f Makefile -a "${1}" != "-c" ; then 
  14.   echo shar: Will not over-write existing file \"Makefile\"
  15. else
  16. echo shar: Extracting \"Makefile\" \(12140 characters\)
  17. sed "s/^X//" >Makefile <<'END_OF_Makefile'
  18. X# This is the Makefile for the Software ChipSet.  Edit this as needed
  19. X# for your system.  This makefile works properly with brain-dead SVR2
  20. X# make, so it should work with your tool, too.
  21. X#
  22. X# The "all" target installs all of the components in a single library
  23. X# rooted in this directory.  The "install" target installs that library
  24. X# and the include files and documents in an appropriate place.
  25. X#
  26. X# This file is part of a suite of programs called Software Chipset.
  27. X# The source code for Software Chipset has been released into the
  28. X# public domain by its author, Paul Sander.
  29. X
  30. Xinclude common.mk
  31. X
  32. X# This rule verifies that all of the Software ChipSet's files have unpacked
  33. X# correctly.
  34. X
  35. Xverify:
  36. X    ok=1;                                \
  37. X    if [ ! -f MANIFEST ];                        \
  38. X    then                                \
  39. X        echo MANIFEST file missing from top-level directory;    \
  40. X        ok=0;                            \
  41. X    elif [ ! -d src ];                        \
  42. X    then                                \
  43. X        echo There is no source code for the components;    \
  44. X        echo Source code belongs in directories contained in;    \
  45. X        echo the directory '"./src"';                \
  46. X        ok=0;                            \
  47. X    else                                \
  48. X        cd src;                            \
  49. X        for x in `/bin/ls`;                    \
  50. X        do                            \
  51. X            if [ "$$x" = "CVS" ];                \
  52. X            then                        \
  53. X                continue;                \
  54. X            fi;                        \
  55. X            echo Checking ./src/$$x;            \
  56. X            if [ -d $$x ];                    \
  57. X            then                        \
  58. X                cd $$x;                    \
  59. X                if [ ! -f MANIFEST ];            \
  60. X                then                    \
  61. X                    echo MANIFEST missing from ./src/$$x;\
  62. X                    ok=0;                \
  63. X                else                    \
  64. X                    thisOk=1;            \
  65. X                    for y in `cat MANIFEST`;    \
  66. X                    do                \
  67. X                        if [ ! -f $$y ];    \
  68. X                        then            \
  69. X                            echo $$y missing from ./src/$$x;\
  70. X                            thisOk=0;    \
  71. X                        fi;            \
  72. X                    done;                \
  73. X                    if [ $$thisOk = 0 ];        \
  74. X                    then                \
  75. X                        ok=0;            \
  76. X                    fi;                \
  77. X                fi;                    \
  78. X                cd ..;                    \
  79. X            fi;                        \
  80. X        done;                            \
  81. X    fi;                                \
  82. X    if [ "$$ok" = 0 ];                        \
  83. X    then                                \
  84. X        echo Failed to verify installation;            \
  85. X        false;                            \
  86. X    else                                \
  87. X        echo Installation is okay;                \
  88. X    fi;                                \
  89. X
  90. X# This rule builds the staging area rooted in the present working directory.
  91. X
  92. Xprep:
  93. X    echo '*** Prepping ***'
  94. X    if [ ! -d $(STAGE) ];                        \
  95. X    then                                \
  96. X        echo The $(STAGE) directory does not exist.  Please;    \
  97. X        echo create it.;                    \
  98. X        /bin/false;                        \
  99. X    else                                \
  100. X        for x in $(STAGEINC) $(STAGELIB) $(STAGEMAN)         \
  101. X                 $(STAGEMAN)/man3 $(STAGETMP);            \
  102. X        do                            \
  103. X            if [ ! -d "$$x" ];                \
  104. X            then                        \
  105. X                mkdir $$x;                \
  106. X            fi;                        \
  107. X        done;                            \
  108. X    fi
  109. X
  110. X# This rule makes the "installInclude," "installLib," and "installDocs"
  111. X# targets in each of the source directories, forcing their ROOT macros
  112. X# to point to here.  Thus, installed under this directory are the
  113. X# include files first (since some components may depend on others),
  114. X# then the libraries and documentation.  Finally, the libchipset.a
  115. X# library is built.
  116. X
  117. Xall: prep
  118. X    root=$(STAGE);                            \
  119. X    incdir=$(STAGEINC);                        \
  120. X    libdir=$(STAGELIB);                        \
  121. X    mandir=$(STAGEMAN)/man3;                    \
  122. X    for t in installInclude installLib installDocs;            \
  123. X    do                                \
  124. X        for x in $(COMPONENTS);                    \
  125. X        do                            \
  126. X            if [ -f "src/$$x/Makefile" ];            \
  127. X            then                        \
  128. X                echo '***' Building $$x $$t '***';    \
  129. X                ( cd src/$$x && make $$t ROOT=$$root    \
  130. X                    INCDIR=$$incdir            \
  131. X                    LIBDIR=$$libdir            \
  132. X                    MANDIR=$$mandir            \
  133. X                );                    \
  134. X                echo;                    \
  135. X            else                        \
  136. X                echo '***' No Makefile in $$x '***';    \
  137. X            fi;                        \
  138. X        done;                            \
  139. X    done
  140. X    echo '***' Building libchipset.a library '***'
  141. X    rm -rf $(STAGETMP)/*
  142. X    stagelib=$(STAGELIB);                        \
  143. X    cd $(STAGETMP);                            \
  144. X    for x in $$stagelib/*.a;                    \
  145. X    do                                \
  146. X        if [ "$$x" != "$$stagelib/libchipset.a" ];        \
  147. X        then                            \
  148. X            echo '***' Processing $$x '***';        \
  149. X            ar x $$x;                    \
  150. X            ar r $$stagelib/libchipset.a *.o;        \
  151. X            rm *.o;                        \
  152. X        fi;                            \
  153. X    done
  154. X    if [ -x $(RANLIB) ]; then $(RANLIB) $(STAGELIB)/libchipset.a; fi
  155. X
  156. X# This rule installs the manpages.  It scans the man directory, and
  157. X# makes sure a corresponding one exists in the install tree.  Then
  158. X# it copies all of the manpages it finds into the install tree, one
  159. X# directory at a time.
  160. X
  161. XinstallDocs:
  162. X    if [ ! -d $(DESTMAN) ];                        \
  163. X    then                                \
  164. X        echo $(DESTMAN) does not exist.  Please create it.;    \
  165. X        false;                            \
  166. X    fi
  167. X    echo '***' Installing manpages '***'
  168. X    cd $(STAGEMAN);                            \
  169. X    for sec in *;                            \
  170. X    do                                \
  171. X        if [ -d $$sec -a -d $(DESTMAN)/$$sec ];            \
  172. X        then                            \
  173. X        (                            \
  174. X            cd $$sec;                    \
  175. X            for f in *;                    \
  176. X            do                        \
  177. X                if [ -f $$f ];                \
  178. X                then                    \
  179. X                    cp $$f $(DESTMAN)/$$sec/$$f;    \
  180. X                    chmod 644 $(DESTMAN)/$$sec/$$f;    \
  181. X                fi;                    \
  182. X            done;                        \
  183. X        );                            \
  184. X        else                            \
  185. X            echo $(DESTMAN)/$$sec does not exist.;        \
  186. X            echo Please create it.;                \
  187. X            false;                        \
  188. X            break;                        \
  189. X        fi;                            \
  190. X    done;
  191. X
  192. X# This rule copies all of the include files into the install tree.
  193. X
  194. XinstallInclude:
  195. X    if [ ! -d $(DESTINC) ];                        \
  196. X    then                                \
  197. X        echo $(DESTINC) does not exist.  Please create it.;    \
  198. X        false;                            \
  199. X    fi
  200. X    echo '***' Installing include files '***'
  201. X    cd $(STAGEINC);                            \
  202. X    for x in *;                            \
  203. X    do                                \
  204. X        if [ -f $$x ];                        \
  205. X        then                            \
  206. X            cp $$x $(DESTINC);                \
  207. X            chmod 644 $(DESTINC)/$$x;            \
  208. X        fi;                            \
  209. X    done
  210. X
  211. X# This rule copies the libchipset.a file to the install tree, and
  212. X# ranlibs it if necessary.
  213. X
  214. XinstallLib:
  215. X    if [ ! -d $(DESTLIB) ];                        \
  216. X    then                                \
  217. X        echo $(DESTLIB) does not exist.  Please create it.;    \
  218. X        false;                            \
  219. X    fi
  220. X    echo '***' Installing library '***'
  221. X    cp $(STAGELIB)/libchipset.a $(DESTLIB)
  222. X    if [ -x $(RANLIB) ]; then $(RANLIB) $(DESTLIB)/libchipset.a; fi
  223. X    chmod 644 $(DESTLIB)/libchipset.a
  224. X
  225. X# This rule installs public header files, libchipset.a, and the manpages.
  226. X
  227. Xinstall: all installDocs installInclude installLib
  228. X    echo '***' Installation complete '***'
  229. X
  230. X# This rule builds and runs the self-tests for each component.
  231. X
  232. Xtest: all
  233. X    if [ ! -d $(STAGETMP) ];                    \
  234. X    then                                \
  235. X        mkdir $(STAGETMP);                    \
  236. X    fi;                                \
  237. X    rm -f $(STAGETMP)/test.out;                    \
  238. X    touch $(STAGETMP)/test.out;                    \
  239. X    for x in $(COMPONENTS);                        \
  240. X    do                                \
  241. X    (                                \
  242. X        if [ ! -f src/$$x/Makefile ];                \
  243. X        then                            \
  244. X            continue;                    \
  245. X        fi;                            \
  246. X        echo "Testing $$x:";                    \
  247. X        echo "Testing $$x:" >> $(STAGETMP)/test.out;        \
  248. X        cd src/$$x;                        \
  249. X        make test ROOT=$(STAGE) INCDIR=$(STAGEINC)        \
  250. X            LIBDIR=$(STAGELIB) MANDIR=$(STAGEMAN);        \
  251. X        if [ "$$?" -ne 0 ];                    \
  252. X        then                            \
  253. X            echo "FAILED to build test" >> $(STAGETMP)/test.out;\
  254. X            echo "FAILED to build test";            \
  255. X            false;                        \
  256. X            break;                        \
  257. X        else                            \
  258. X            ./test >> $(STAGETMP)/test.out;            \
  259. X            if [ "$$?" -ne 0 ];                \
  260. X            then                        \
  261. X                echo "FAILED test";            \
  262. X                false;                    \
  263. X                break;                    \
  264. X            else                        \
  265. X                echo "PASSED test";            \
  266. X            fi;                        \
  267. X        fi;                            \
  268. X    );                                \
  269. X    done;                                \
  270. X    if [ "$$?" -ne 0 ];                        \
  271. X    then                                \
  272. X        echo "---- FAILED ----";                \
  273. X    else                                \
  274. X        echo "---- PASSED ----";                \
  275. X    fi
  276. X
  277. X# This rule cleans intermediate files by cleaning the staging area
  278. X# and doing a "make clean" in all of the component source directories.
  279. X
  280. Xclean:
  281. X    if [ -d $(STAGELIB) ];                        \
  282. X    then                                \
  283. X        cd $(STAGELIB);                        \
  284. X        > /dev/null 2>&1 files=* /bin/true;            \
  285. X        if [ "$$files" != "" ];                    \
  286. X        then                            \
  287. X            for x in $$files;                \
  288. X            do                        \
  289. X                if [ "$$x" != "libchipset.a" ];        \
  290. X                then                    \
  291. X                    rm $$x;                \
  292. X                fi;                    \
  293. X            done;                        \
  294. X        fi;                            \
  295. X    fi
  296. X    for x in $(COMPONENTS);                        \
  297. X    do                                \
  298. X        if [ -d src/$$x -a -f src/$$x/Makefile ];        \
  299. X        then                            \
  300. X            echo '***' Cleaning $$x '***';            \
  301. X            ( cd src/$$x && make clean );            \
  302. X        fi;                            \
  303. X    done
  304. X    rm -rf $(STAGETMP)
  305. X
  306. X# This rule attempts to return to pristine sources by removing all
  307. X# installed files from the staging area, and doing a "make spotless"
  308. X# in each of the component source directories.
  309. X
  310. Xspotless clobber realclean veryclean:
  311. X    rm -rf $(STAGEINC) $(STAGELIB) $(STAGETMP) $(STAGEMAN) $(STAGEINST)
  312. X    rm -rf $(STAGE)
  313. X    rm temp
  314. X    for x in $(COMPONENTS);                        \
  315. X    do                                \
  316. X        if [ -d src/$$x -a -f src/$$x/Makefile ];        \
  317. X        then                            \
  318. X            echo '***' Scrubbing $$x '***';            \
  319. X            ( cd src/$$x && make spotless );        \
  320. X        fi;                            \
  321. X    done
  322. X
  323. XMANIFEST: clobber
  324. X    find . -type f -print |                        \
  325. X        sed -e 's/^\.\///' -e /CVS/d -e /header/d |        \
  326. X        sort > MANIFEST
  327. X    for x in $(COMPONENTS);                        \
  328. X    do                                \
  329. X        echo Processing $$x;                    \
  330. X        ( cd src/$$x && make MANIFEST );            \
  331. X    done
  332. X
  333. X# This rule builds a shar file using Rich $alz's shar implementation.
  334. X
  335. Xshar:
  336. X    for x in $(STAGETMP) $(STAGEINST);                \
  337. X    do                                \
  338. X        if [ ! -d $$x ];                    \
  339. X        then                            \
  340. X            mkdir $$x;                    \
  341. X        fi;                            \
  342. X    done
  343. X    cp MANIFEST $(STAGETMP)/MANIFEST
  344. X    echo src >> $(STAGETMP)/MANIFEST
  345. X    for x in $(COMPONENTS);                        \
  346. X    do                                \
  347. X        if [ -f src/$$x/Makefile -a -f src/$$x/MANIFEST ];    \
  348. X        then                            \
  349. X            echo src/$$x >> $(STAGETMP)/MANIFEST;        \
  350. X        fi;                            \
  351. X    done
  352. X    for x in $(COMPONENTS);                        \
  353. X    do                                \
  354. X        if [ -f src/$$x/Makefile -a -f src/$$x/MANIFEST ];    \
  355. X        then                            \
  356. X            echo "Processing $$x";                \
  357. X            sed -e "s/^/src\/$$x\//g" src/$$x/MANIFEST    \
  358. X                >> $(STAGETMP)/MANIFEST;        \
  359. X        fi;                            \
  360. X    done
  361. X    makekit -n$(STAGEINST)/ChipSet.part -s30k             \
  362. X        "-tNow edit common.mk and do a 'make all'"        \
  363. X        < $(STAGETMP)/MANIFEST
  364. X    rm $(STAGETMP)/MANIFEST
  365. X
  366. X# This rule builds a portable cpio archive.
  367. X
  368. Xcpio:
  369. X    for x in $(STAGETMP) $(STAGEINST);                \
  370. X    do                                \
  371. X        if [ ! -d $$x ];                    \
  372. X        then                            \
  373. X            mkdir $$x;                    \
  374. X        fi;                            \
  375. X    done
  376. X    cp MANIFEST $(STAGETMP)/MANIFEST
  377. X    for x in $(COMPONENTS);                        \
  378. X    do                                \
  379. X        if [ -f src/$$x/Makefile -a -f src/$$x/MANIFEST ];    \
  380. X        then                            \
  381. X            echo "Processing $$x";                \
  382. X            sed -e "s/^/src\/$$x\//g" src/$$x/MANIFEST    \
  383. X                >> $(STAGETMP)/MANIFEST;        \
  384. X        fi;                            \
  385. X    done
  386. X    cpio -ocv < $(STAGETMP)/MANIFEST | compress             \
  387. X        > $(STAGEINST)/ChipSet.cpio.Z
  388. X    rm $(STAGETMP)/MANIFEST
  389. X
  390. X# This rule builds a tar archive.
  391. X
  392. Xtar:
  393. X    for x in $(STAGETMP) $(STAGETMP)/ChipSet            \
  394. X         $(STAGETMP)/ChipSet/src $(STAGEINST);            \
  395. X    do                                \
  396. X        if [ ! -d $$x ];                    \
  397. X        then                            \
  398. X            mkdir $$x;                    \
  399. X        fi;                            \
  400. X    done
  401. X    cp MANIFEST $(STAGETMP)/MANIFEST
  402. X    for x in $(COMPONENTS);                        \
  403. X    do                                \
  404. X        if [ -f src/$$x/Makefile -a -f src/$$x/MANIFEST ];    \
  405. X        then                            \
  406. X            echo "Processing $$x";                \
  407. X            sed -e "s/^/src\/$$x\//g" src/$$x/MANIFEST    \
  408. X                >> $(STAGETMP)/MANIFEST;        \
  409. X            mkdir $(STAGETMP)/ChipSet/src/$$x;        \
  410. X        fi;                            \
  411. X    done
  412. X    (                                \
  413. X        read x;                            \
  414. X        while [ "$$x" != "" ];                    \
  415. X        do                            \
  416. X            echo Linking $$x;                \
  417. X            ln $$x $(STAGETMP)/ChipSet/$$x;            \
  418. X            read x;                        \
  419. X        done;                            \
  420. X        /bin/true;                        \
  421. X    ) < $(STAGETMP)/MANIFEST
  422. X    ( cd $(STAGETMP)/ChipSet; tar cf - . ) | compress         \
  423. X        > $(STAGEINST)/ChipSet.tar.Z
  424. X    rm -rf $(STAGETMP)/MANIFEST $(STAGETMP)/ChipSet
  425. X
  426. X# This rule builds a zip archive.
  427. X
  428. Xzip:
  429. X    for x in $(STAGETMP) $(STAGETMP)/ChipSet             \
  430. X         $(STAGETMP)/ChipSet/src $(STAGEINST);            \
  431. X    do                                \
  432. X        if [ ! -d $$x ];                    \
  433. X        then                            \
  434. X            mkdir $$x;                    \
  435. X        fi;                            \
  436. X    done
  437. X    cp MANIFEST $(STAGETMP)/MANIFEST
  438. X    for x in $(COMPONENTS);                        \
  439. X    do                                \
  440. X        if [ -f src/$$x/Makefile -a -f src/$$x/MANIFEST ];    \
  441. X        then                            \
  442. X            echo "Processing $$x";                \
  443. X            sed -e "s/^/src\/$$x\//g" src/$$x/MANIFEST    \
  444. X                >> $(STAGETMP)/MANIFEST;        \
  445. X            mkdir $(STAGETMP)/ChipSet/src/$$x;        \
  446. X        fi;                            \
  447. X    done
  448. X    (                                \
  449. X        read x;                            \
  450. X        while [ "$$x" != "" ];                    \
  451. X        do                            \
  452. X            echo Linking $$x;                \
  453. X            ln $$x $(STAGETMP)/ChipSet/$$x;            \
  454. X            read x;                        \
  455. X        done;                            \
  456. X        /bin/true;                        \
  457. X    ) < $(STAGETMP)/MANIFEST
  458. X    rm -f $(STAGEINST)/ChipSet.zip
  459. X    echo Software ChipSet |                        \
  460. X        ( cd $(STAGETMP)/ChipSet;                \
  461. X          NOZIP=":" zip -rnsz $(STAGEINST)/ChipSet.zip . )
  462. X    rm -rf $(STAGETMP)/MANIFEST $(STAGETMP)/ChipSet
  463. X
  464. X# This rule builds arc archives for each component plus the scaffolding.
  465. X# This remains undocumented because the archive files are cumbersome to
  466. X# unpack, and because the unpacked source files are not suitable for
  467. X# compilation on Unix systems.
  468. X
  469. Xarc:
  470. X    if [ ! -d $(STAGEINST) ]; then mkdir $(STAGEINST); fi
  471. X    rm -f $(STAGEINST)/*.arc
  472. X    arc ais $(STAGEINST)/ChipSet.arc `cat MANIFEST`
  473. X    for x in $(COMPONENTS);                        \
  474. X    do                                \
  475. X        if [ -f src/$$x/Makefile -a -f src/$$x/MANIFEST ];    \
  476. X        then                            \
  477. X        (                            \
  478. X            cd src/$$x;                    \
  479. X            arc ais $(STAGEINST)/$$x.arc `cat MANIFEST`;    \
  480. X        );                            \
  481. X        fi;                            \
  482. X    done
  483. X
  484. X### End of file ###
  485. X
  486. END_OF_Makefile
  487. if test 12140 -ne `wc -c <Makefile`; then
  488.     echo shar: \"Makefile\" unpacked with wrong size!
  489. fi
  490. # end of overwriting check
  491. fi
  492. if test -f src/btree/btree.man -a "${1}" != "-c" ; then 
  493.   echo shar: Will not over-write existing file \"src/btree/btree.man\"
  494. else
  495. echo shar: Extracting \"src/btree/btree.man\" \(10900 characters\)
  496. sed "s/^X//" >src/btree/btree.man <<'END_OF_src/btree/btree.man'
  497. X.TH BTREE
  498. X.SH NAME
  499. Xbt_dump, bt_search, bt_setup, bt_freeSetup, bt_new, bt_destroy, bt_insert,
  500. Xbt_traverse, bt_delete, bt_rank, bt_delRank, bt_data, bt_setData -
  501. XIn-memory B-tree manipulation
  502. X.SH SYNOPSIS
  503. X#include <btree.h>
  504. X.sp
  505. X#ifdef __STDC__
  506. X.sp
  507. XBT_SETUP bt_setup(int order, int (*comp)(void*,void*), void *data)
  508. X.sp
  509. Xvoid bt_freeSetup(BT_SETUP setup)
  510. X.sp
  511. XBTREE bt_new(BT_SETUP setup)
  512. X.sp
  513. Xvoid bt_destroy(BTREE tree, void (*free_key)(void*,void*),
  514. Xvoid (*free_data)(void*,void*), void *info)
  515. X.sp
  516. Xint bt_insert(BTREE tree, void *key, void *data)
  517. X.sp
  518. Xvoid    *bt_delete(BTREE tree, void *key, void **data)
  519. X.sp
  520. Xvoid *bt_search(BTREE tree, void *target, void **data)
  521. X.sp
  522. Xvoid bt_traverse(BTREE tree, void (*fn)(void*,void*,void*), void *parms)
  523. X.sp
  524. Xvoid bt_dump(BTREE tree, void (*key_dump)(void*,void*,void*), void *info)
  525. X.sp
  526. Xvoid *bt_first(BTREE tree, void **data)
  527. X.sp
  528. Xvoid *bt_last(BTREE tree, void **data)
  529. X.sp
  530. Xvoid *bt_next(BTREE tree, void **data)
  531. X.sp
  532. Xvoid *bt_prev(BTREE tree, void **data)
  533. X.sp
  534. Xvoid *bt_rank(BTREE tree, int rank, void **data)
  535. X.sp
  536. Xvoid *bt_delRank(BTREE tree, int rank, void **data)
  537. X.sp
  538. Xvoid *bt_data(BTREE tree)
  539. X.sp
  540. Xvoid bt_setData(BTREE tree, void *data)
  541. X.sp
  542. X#else
  543. X.sp
  544. XBT_SETUP bt_setup(order,comp,data)
  545. X.br
  546. Xint    order;
  547. X.br
  548. Xint    (*comp)();
  549. X.br
  550. Xvoid    *data;
  551. X.sp
  552. Xvoid bt_freeSetup(setup)
  553. X.br
  554. XBT_SETUP    setup;
  555. X.sp
  556. XBTREE bt_new(setup)
  557. X.br
  558. XBT_SETUP    setup;
  559. X.sp
  560. Xvoid bt_destroy(tree,free_key,free_data,info)
  561. X.br
  562. XBTREE    tree;
  563. X.br
  564. Xvoid    (*free_key)();
  565. X.br
  566. Xvoid    (*free_data)();
  567. X.br
  568. Xvoid    *info;
  569. X.sp
  570. Xint bt_insert(tree,key,data)
  571. X.br
  572. XBTREE    tree;
  573. X.br
  574. Xvoid    *key;
  575. X.br
  576. Xvoid    *data;
  577. X.sp
  578. Xvoid    *bt_delete(tree,key,data)
  579. X.br
  580. XBTREE    tree;
  581. X.br
  582. Xvoid    *key;
  583. X.br
  584. Xvoid    **data;
  585. X.sp
  586. Xvoid *bt_search(tree,target,data)
  587. X.br
  588. XBTREE    tree;
  589. X.br
  590. Xvoid    *target;
  591. X.br
  592. Xvoid    **data;
  593. X.sp
  594. Xvoid bt_traverse(tree,fn,parms)
  595. X.br
  596. XBTREE    tree;
  597. X.br
  598. Xvoid    (*fn)();
  599. X.br
  600. Xvoid    *parms;
  601. X.sp
  602. Xvoid bt_dump(tree,key_dump,info)
  603. X.br
  604. XBTREE    tree;
  605. X.br
  606. Xvoid    (*key_dump)();
  607. X.br
  608. Xvoid    *info;
  609. X.sp
  610. Xvoid *bt_first(tree,data)
  611. X.br
  612. XBTREE    tree;
  613. X.br
  614. Xvoid    **data;
  615. X.sp
  616. Xvoid *bt_last(tree,data)
  617. X.br
  618. XBTREE    tree;
  619. X.br
  620. Xvoid    **data;
  621. X.sp
  622. Xvoid *bt_next(tree,data)
  623. X.br
  624. XBTREE    tree;
  625. X.br
  626. Xvoid    **data;
  627. X.sp
  628. Xvoid *bt_prev(tree,data)
  629. X.br
  630. XBTREE    tree;
  631. X.br
  632. Xvoid    **data;
  633. X.sp
  634. Xvoid *bt_rank(tree,rank,data)
  635. X.br
  636. XBTREE    tree;
  637. X.br
  638. Xint    rank;
  639. X.br
  640. Xvoid    **data;
  641. X.sp
  642. Xvoid *bt_delRank(tree,rank,data)
  643. X.br
  644. XBTREE    tree;
  645. X.br
  646. Xint    rank;
  647. X.br
  648. Xvoid    **data;
  649. X.sp
  650. Xvoid *bt_data(tree)
  651. X.br
  652. XBTREE    tree;
  653. X.sp
  654. Xvoid bt_setData(tree,data)
  655. X.br
  656. XBTREE    tree;
  657. X.br
  658. Xvoid    *data;
  659. X.sp
  660. X#endif
  661. X.SH DESCRIPTION
  662. XThese functions implement an in-memory B-tree data structure.  The tree
  663. Xitself stores only pointers to the client's data, and relies on
  664. Xclient-provided functions for any comparisons and storage deallocation.
  665. X.sp
  666. X.B bt_setup
  667. Xbuilds a setup structure before a B-tree can be created, or NULL if an
  668. Xerror occurs.  The setup structure is a magic
  669. Xcookie that can be used to set up many B-trees.  It must be freed by calling
  670. X.BR bt_freeSetup .
  671. XThe client specifies the desired order (the maximum
  672. Xnumber of children allowed each node) of the tree to be set up
  673. X(for performance trade-offs based on the efficiency of comparisons of
  674. Xclient-provided data), an optional pointer to a user-defined structure that
  675. Xis stored once with the tree, and a pointer to a function that compares two
  676. Xclient-provided data structures.  The comparison function, 
  677. X.BR comp ,
  678. Xhas the following interface:
  679. X.RS
  680. X.B
  681. Xint comp(k1,k2)
  682. X.br
  683. X.B
  684. Xvoid *k1,*k2;
  685. X.RE
  686. XThe result of this function is -1 if the object pointed to by k1 is "less than"
  687. Xthe object pointed to by k2, 0 if they are "equal", and 1 otherwise.
  688. XClient-provided data structures that
  689. Xcompare greater by this function will appear later in the lexical order
  690. Xof the data stored in the tree.
  691. XThe client may also specify the initial value of the data returned by
  692. X.B bt_getData
  693. Xafter a tree is instantiated.
  694. X.sp
  695. X.B bt_freeSetup
  696. Xfrees the setup structure created by
  697. X.BR bt_setup .
  698. XIt can be called any time after
  699. X.B bt_new
  700. Xis called.  B-trees do not require their setup structures to exist after they
  701. Xare created.  The user-defined structure (pointed to by
  702. X.B data
  703. Xwhen
  704. X.B bt_setup
  705. Xis called) is not affected in any way.
  706. X.sp
  707. X.B bt_new
  708. Xcreates a new B-tree.  Given a BT_SETUP setup structure,
  709. X.B bt_new
  710. Xreturns a pointer to a handle for the B-tree, or NULL if an error occurs.
  711. X.sp
  712. X.B bt_destroy
  713. Xdeallocates all storage allocated to a B-tree.  The client provides a pointer
  714. Xto two visitation functions that are each called once for each item stored in
  715. Xthe tree.  The items are visited in arbitrary order.  If
  716. XNULL is passed instead of a pointer to a function, no action is taken for
  717. Xthe client-provided data or key, but the tree structure itself is freed.
  718. XThe
  719. X.B free_key
  720. Xand
  721. X.B free_data
  722. Xparameters specify functions that free the keys and data stored in the tree.
  723. XThe
  724. X.B free_data
  725. Xfunction is always called before the
  726. X.B free_key
  727. Xfunction.  The
  728. X.B info
  729. Xparameter is always passed to both functions without modification.
  730. XThe interfaces for these functions follow:
  731. X.sp
  732. X    void freeThis(keyOrData,info)
  733. X.br
  734. X    void    *keyOrData;
  735. X.br
  736. X    void    *info;
  737. X.sp
  738. X.B bt_insert
  739. Xinserts a new item into the tree.  1 is returned if the insertion was
  740. Xsuccessful, -1 is returned if the new item matches another item that has
  741. Xalready been inserted into the tree, and 0 is returned in the event of an
  742. Xerror.  The
  743. X.B data
  744. Xparameter is a pointer to a user-defined data structure that is stored with
  745. Xthe key, and can be retrieved by any access or deletion function.
  746. X.sp
  747. X.B bt_delete
  748. Xdeletes an item from a tree.  The value returned is the same as that passed
  749. Xto
  750. X.B bt_insert
  751. Xwhen the item was inserted, or NULL if the item is not found.  The
  752. X.B data
  753. Xparameter returns the pointer stored with the key when
  754. X.B bt_insert
  755. Xwas called, or is undefined when the key is not found.
  756. X.sp
  757. X.B bt_search
  758. Xsearches for an item in a tree.  The value returned is the same as that passed
  759. Xto
  760. X.B bt_insert
  761. Xwhen the item was inserted, or NULL if the item is not found.  The
  762. X.B data
  763. Xparameter returns the pointer stored with the key when
  764. X.B bt_insert
  765. Xwas called, or is undefined if the key is not found.
  766. X.sp
  767. X.B bt_traverse
  768. Xtraverses the tree, calling a client-provided visitation function
  769. X.B fn
  770. Xonce for each item stored there.
  771. X.B fn
  772. Xhas the following interface:
  773. X.RS
  774. X.B
  775. Xvoid fn(item,parms,data)
  776. X.br
  777. X.B
  778. Xvoid *item;
  779. X.B
  780. X.br
  781. X.B
  782. Xvoid *parms;
  783. X.br
  784. X.B
  785. Xvoid *data;
  786. X.RE
  787. X.B item
  788. Xis the pointer stored when the item was inserted into the tree.
  789. X.B parms
  790. Xis an arbitrary pointer that the client wishes to pass to the visitation
  791. Xfunction, but is otherwise unused by the B-tree implementation.
  792. X.B data
  793. Xis a pointer to a user-defined structure that is stored with the key when
  794. X.B bt_insert
  795. Xis called.
  796. XItems are visited in their lexical order.
  797. X.sp
  798. X.B bt_dump
  799. Xdisplays the contents of the tree to stdout, along with some diagnostic and
  800. Xstatistical information.  The
  801. X.B key_dump
  802. Xfunction is called once for each item in the tree, in arbitrary order.  It
  803. Xmay be NULL if no action is desired.  Its interface follows:
  804. X.RS
  805. X.B
  806. Xvoid key_dump(key,data,info)
  807. X.br
  808. X.B
  809. Xvoid *key;
  810. X.br
  811. X.B
  812. Xvoid *data;
  813. X.br
  814. X.B
  815. Xvoid *info;
  816. X.RE
  817. XWhere
  818. X.B key
  819. Xis a key stored in the B-tree,
  820. X.B data
  821. Xis the user-defined pointer stored with the key at the time
  822. X.B bt_insert
  823. Xwas called, and
  824. X.B info
  825. Xis arbitrary data passed to the bt_dump function as the
  826. X.B info
  827. Xparameter.
  828. X.sp
  829. X.B bt_first
  830. Xreturns the item that falls earliest in the lexical order of the items
  831. Xstored in the tree, or NULL if the tree is empty.  The user-defined pointer
  832. Xstored with the key is also returned in the
  833. X.B data
  834. Xparameter.
  835. X.sp
  836. X.B bt_last
  837. Xreturns the item that falls latest in the lexical order of the items
  838. Xstored in the tree, or NULL if the tree is empty.  The user-defined pointer
  839. Xstored with the key is also returned in the
  840. X.B data
  841. Xparameter.
  842. X.sp
  843. X.B bt_next
  844. Xreturns the next item higher in the lexical order after the last key
  845. Xreturned by
  846. X.BR bt_first ,
  847. X.BR bt_next ,
  848. X.BR bt_prev ,
  849. X.BR bt_rank ,
  850. Xor
  851. X.BR bt_search .
  852. XIf
  853. X.B bt_search
  854. Xfailed to find an item,
  855. X.B bt_next
  856. Xreturns the next item higher in the
  857. Xlexical order that was stored in the tree.  NULL is returned if
  858. Xthe last call to
  859. X.B bt_next
  860. Xreturned the item falling highest in the
  861. Xlexical order of the items stored in the tree, or if the tree was
  862. Xmodified since the last call to
  863. X.B bt_next
  864. Xor
  865. X.BR bt_prev .
  866. XIf a key is found, the user-defined pointer stored with the key is also returned
  867. Xin the
  868. X.B data
  869. Xparameter.
  870. X.sp
  871. X.B bt_prev
  872. Xreturns the next item lower in the lexical order after the last key
  873. Xreturned by
  874. X.BR bt_last ,
  875. X.BR bt_next ,
  876. X.b bt_prev ,
  877. X.b bt_rank ,
  878. Xor
  879. X.BR bt_search .
  880. XIf
  881. X.B bt_search
  882. Xfailed to find an item,
  883. X.B bt_prev
  884. Xreturns the next item lower in the
  885. Xlexical order that was stored in the tree.  NULL is returned if
  886. Xthe last call to
  887. X.B bt_prev
  888. Xreturned the item falling lowest in the
  889. Xlexical order of the items stored in the tree, or if the tree was
  890. Xmodified since the last call to
  891. X.B bt_next
  892. Xor
  893. X.BR bt_prev .
  894. XIf a key is found, the user-defined pointer stored with the key is also returned
  895. Xin the
  896. X.B data
  897. Xparameter.
  898. X.sp
  899. X.B bt_rank
  900. Xreturns the key in the B-tree that falls in the
  901. X.BR rank th
  902. Xposition in the lexical order of all keys stored in the tree.
  903. XThe
  904. X.B rank
  905. Xparameter is zero-based.
  906. XNULL is returned if the specified rank is less than 0 or greater or equal to
  907. Xthe number of keys stored in the tree.
  908. XIf the call succeeds, the tree is left in a state such that
  909. X.B bt_next
  910. Xand
  911. X.B bt_prev
  912. Xbehave as expected.  The user-defined pointer stored with the key is also
  913. Xreturned in the
  914. X.B data
  915. Xparameter.
  916. X.sp
  917. X.B bt_delRank
  918. Xdeletes the key stored in the specified lexical position in the B-tree.
  919. XThe value returned is the same as that passed to
  920. X.B bt_insert
  921. Xwhen the item was inserted, or NULL if the specified
  922. X.B rank
  923. Xis invalid.
  924. X.B rank
  925. Xis zero-based, and must be less than the number of keys stored in the tree.
  926. XThe user-defined pointer stored with the key is also returned in the
  927. X.B data
  928. Xparameter.
  929. X.sp
  930. X.B NOTE:
  931. XNULL can safely be passed as the
  932. X.B data
  933. Xparameter in any of the access functions (
  934. X.BR bt_search ,
  935. X.BR bt_first ,
  936. X.BR bt_next ,
  937. X.BR bt_last ,
  938. X.BR bt_prev ,
  939. Xor
  940. X.BR bt_rank )
  941. Xor deletion functions (
  942. X.B bt_delete
  943. Xor
  944. X.BR bt_delRank ).
  945. X.sp
  946. XWorst case performance characteristics are listed below.  Here, "m" is number
  947. Xpassed as the "order" parameter to bt_setup, and "n" is the number of items
  948. Xstored in the tree.
  949. X.RS
  950. Xbt_search:    O(m * log n)
  951. X.br
  952. Xbt_new:        O(1)
  953. X.br
  954. Xbt_destroy:    O(log n) + O(n) when free_key is not NULL
  955. X.br
  956. X        O(log n) otherwise
  957. X.br
  958. Xbt_insert:    O(m * log n)
  959. X.br
  960. Xbt_delete:    O(m * log n)
  961. X.br
  962. Xbt_traverse:    O(n)
  963. X.br
  964. Xbt_next:        O(log n)
  965. X.br
  966. Xbt_prev:        O(log n)
  967. X.br
  968. Xbt_first:        O(log n)
  969. X.br
  970. Xbt_last:        O(log n)
  971. X.br
  972. Xbt_rank:    O(m * log n)
  973. X.br
  974. Xbt_delRank:    O(m * log n)
  975. X.br
  976. Xbt_data:    O(1)
  977. X.br
  978. Xbt_setData:    O(1)
  979. X.RE
  980. X.sp
  981. XThe B-tree implementation is reentrant.
  982. X.SH BUGS
  983. XThis implementation has not been tested on nearly enough platforms.
  984. X.sp
  985. X.B bt_dump
  986. Xassumes that pointers are the same size as integers, and that they can be
  987. Xdisplayed in total in eight hexidecimal digits.
  988. END_OF_src/btree/btree.man
  989. if test 10900 -ne `wc -c <src/btree/btree.man`; then
  990.     echo shar: \"src/btree/btree.man\" unpacked with wrong size!
  991. fi
  992. # end of overwriting check
  993. fi
  994. echo shar: End of archive 7 \(of 10\).
  995. cp /dev/null ark7isdone
  996. MISSING=""
  997. for I in 1 2 3 4 5 6 7 8 9 10 ; do
  998.     if test ! -f ark${I}isdone ; then
  999.     MISSING="${MISSING} ${I}"
  1000.     fi
  1001. done
  1002. if test "${MISSING}" = "" ; then
  1003.     echo You have unpacked all 10 archives.
  1004.     echo "Now edit common.mk and do a 'make all'"
  1005.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1006. else
  1007.     echo You still need to unpack the following archives:
  1008.     echo "        " ${MISSING}
  1009. fi
  1010. ##  End of shell archive.
  1011. exit 0
  1012.  
  1013.