home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 400-499 / ff473.lzh / CNewsSrc / cnews_src.lzh / man / dbz3z.man < prev    next >
Text File  |  1991-01-05  |  18KB  |  397 lines

  1.  
  2.  
  3.  
  4. DBZ(3Z)           MISC. REFERENCE MANUAL PAGES            DBZ(3Z)
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      dbminit, fetch, store, dbmclose  -  somewhat  dbm-compatible
  10.      database routines
  11.      dbzfresh, dbzagain, dbzfetch, dbzstore - database routines
  12.      dbzsize, dbzincore, dbzdebug - database routines
  13.  
  14. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  15.      ####iiiinnnncccclllluuuuddddeeee <<<<ddddbbbbzzzz....hhhh>>>>
  16.  
  17.      ddddbbbbmmmmiiiinnnniiiitttt((((bbbbaaaasssseeee))))
  18.      cccchhhhaaaarrrr ****bbbbaaaasssseeee;;;;
  19.  
  20.      ddddaaaattttuuuummmm
  21.      ffffeeeettttcccchhhh((((kkkkeeeeyyyy))))
  22.      ddddaaaattttuuuummmm kkkkeeeeyyyy;;;;
  23.  
  24.      ssssttttoooorrrreeee((((kkkkeeeeyyyy,,,, vvvvaaaalllluuuueeee))))
  25.      ddddaaaattttuuuummmm kkkkeeeeyyyy;;;;
  26.      ddddaaaattttuuuummmm vvvvaaaalllluuuueeee;;;;
  27.  
  28.      ddddbbbbmmmmcccclllloooosssseeee(((())))
  29.  
  30.      ddddbbbbzzzzffffrrrreeeesssshhhh((((bbbbaaaasssseeee,,,, ssssiiiizzzzeeee,,,, ffffiiiieeeellllddddsssseeeepppp,,,, ccccmmmmaaaapppp,,,, ttttaaaaggggmmmmaaaasssskkkk))))
  31.      cccchhhhaaaarrrr ****bbbbaaaasssseeee;;;;
  32.      lllloooonnnngggg ssssiiiizzzzeeee;;;;
  33.      iiiinnnntttt ffffiiiieeeellllddddsssseeeepppp;;;;
  34.      iiiinnnntttt ccccmmmmaaaapppp;;;;
  35.      lllloooonnnngggg ttttaaaaggggmmmmaaaasssskkkk;;;;
  36.  
  37.      ddddbbbbzzzzaaaaggggaaaaiiiinnnn((((bbbbaaaasssseeee,,,, oooollllddddbbbbaaaasssseeee))))
  38.      cccchhhhaaaarrrr ****bbbbaaaasssseeee;;;;
  39.      cccchhhhaaaarrrr ****oooollllddddbbbbaaaasssseeee;;;;
  40.  
  41.      ddddaaaattttuuuummmm
  42.      ddddbbbbzzzzffffeeeettttcccchhhh((((kkkkeeeeyyyy))))
  43.      ddddaaaattttuuuummmm kkkkeeeeyyyy;;;;
  44.  
  45.      ddddbbbbzzzzssssttttoooorrrreeee((((kkkkeeeeyyyy,,,, vvvvaaaalllluuuueeee))))
  46.      ddddaaaattttuuuummmm kkkkeeeeyyyy;;;;
  47.      ddddaaaattttuuuummmm vvvvaaaalllluuuueeee;;;;
  48.  
  49.      ddddbbbbzzzzssssyyyynnnncccc(((())))
  50.  
  51.      lllloooonnnngggg
  52.      ddddbbbbzzzzssssiiiizzzzeeee((((nnnneeeennnnttttrrrriiiieeeessss))))
  53.      lllloooonnnngggg nnnneeeennnnttttrrrriiiieeeessss;;;;
  54.  
  55.      ddddbbbbzzzziiiinnnnccccoooorrrreeee((((nnnneeeewwwwvvvvaaaalllluuuueeee))))
  56.  
  57.      ddddbbbbzzzzddddeeeebbbbuuuugggg((((nnnneeeewwwwvvvvaaaalllluuuueeee))))
  58.  
  59.  
  60.  
  61.  
  62.  
  63. Sun Microsystems    Last change: 13 Oct 1990                    1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. DBZ(3Z)           MISC. REFERENCE MANUAL PAGES            DBZ(3Z)
  71.  
  72.  
  73.  
  74. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  75.      These functions provide an indexing system for rapid  random
  76.      access  to  a text file (the _b_a_s_e _f_i_l_e).  Subject to certain
  77.      constraints, they are call-compatible with _d_b_m(3),  although
  78.      they  also provide some extensions.  (Note that they are _n_o_t
  79.      file-compatible with _d_b_m or any variant thereof.)
  80.  
  81.      In principle, _d_b_z stores key-value pairs, where both key and
  82.      value  are  arbitrary  sequences  of bytes, specified to the
  83.      functions by values of type _d_a_t_u_m, typedefed in  the  header
  84.      file  to  be  a structure with members _d_p_t_r (a value of type
  85.      _c_h_a_r * pointing to the bytes) and _d_s_i_z_e (a value of type _i_n_t
  86.      indicating how long the byte sequence is).
  87.  
  88.      In practice, _d_b_z is more restricted than _d_b_m.  A  _d_b_z  data-
  89.      base  must  be  an index into a base file, with the database
  90.      _v_a_l_u_es being _f_s_e_e_k(3) offsets into the base file.  Each such
  91.      _v_a_l_u_e  must  ``point to'' a place in the base file where the
  92.      corresponding _k_e_y sequence is found.  A key can be no longer
  93.      than  DBZMAXKEY  (a  constant  defined  in  the header file)
  94.      bytes.  No key can be an  initial  subsequence  of  another,
  95.      which  in  most  applications  requires  that keys be either
  96.      bracketed or terminated in some way (see the  discussion  of
  97.      the  _f_i_e_l_d_s_e_p parameter of _d_b_z_f_r_e_s_h, below, for a fine point
  98.      on terminators).
  99.  
  100.      _D_b_m_i_n_i_t opens a database, an index into the base file  _b_a_s_e,
  101.      consisting of files _b_a_s_e....ddddiiiirrrr and _b_a_s_e....ppppaaaagggg which must already
  102.      exist.  (If the database is new, they should be  zero-length
  103.      files.)   Subsequent  accesses  go  to  that  database until
  104.      _d_b_m_c_l_o_s_e is called to close the  database.   The  base  file
  105.      need not exist at the time of the _d_b_m_i_n_i_t, but it must exist
  106.      before accesses are attempted.
  107.  
  108.      _F_e_t_c_h searches the database for the specified _k_e_y, returning
  109.      the  corresponding _v_a_l_u_e if any.  _S_t_o_r_e stores the _k_e_y-_v_a_l_u_e
  110.      pair in the database.  _S_t_o_r_e will fail unless  the  database
  111.      files  are  writeable.  See below for a complication arising
  112.      from case mapping.
  113.  
  114.      _D_b_z_f_r_e_s_h is a variant of _d_b_m_i_n_i_t for creating a new database
  115.      with  more  control  over  details.  Unlike for _d_b_m_i_n_i_t, the
  116.      database files need not exist:   they  will  be  created  if
  117.      necessary, and truncated in any case.
  118.  
  119.      _D_b_z_f_r_e_s_h's _s_i_z_e parameter specifies the size  of  the  first
  120.      hash table within the database, in key-value pairs.  Perfor-
  121.      mance will be best if _s_i_z_e is a prime number and the  number
  122.      of  key-value  pairs  stored in the database does not exceed
  123.      about  75%  of  _s_i_z_e.   (The  _d_b_z_s_i_z_e  function,  given  the
  124.      expected  number of key-value pairs, will suggest a database
  125.      size that meets these criteria.)   Assuming  that  an  _f_s_e_e_k
  126.  
  127.  
  128.  
  129. Sun Microsystems    Last change: 13 Oct 1990                    2
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. DBZ(3Z)           MISC. REFERENCE MANUAL PAGES            DBZ(3Z)
  137.  
  138.  
  139.  
  140.      offset  is  4 bytes, the ....ppppaaaagggg file will be 4*_s_i_z_e bytes (the
  141.      ....ddddiiiirrrr file is tiny and roughly constant in  size)  until  the
  142.      number of key-value pairs exceeds about 80% of _s_i_z_e.  (Noth-
  143.      ing awful will happen if the database grows beyond  100%  of
  144.      _s_i_z_e, but accesses will slow down somewhat and the ....ppppaaaagggg file
  145.      will grow somewhat.)
  146.  
  147.      _D_b_z_f_r_e_s_h's _f_i_e_l_d_s_e_p parameter specifies the field  separator
  148.      in  the  base  file.   If  this is not NUL (0), and the last
  149.      character of a _k_e_y argument is NUL, that NUL compares  equal
  150.      to  either  a NUL or a _f_i_e_l_d_s_e_p in the base file.  This per-
  151.      mits use of NUL to terminate key strings  without  requiring
  152.      that  NULs appear in the base file.  The _f_i_e_l_d_s_e_p of a data-
  153.      base created with _d_b_m_i_n_i_t is the horizontal-tab character.
  154.  
  155.      For use in news systems, various forms of case mapping (e.g.
  156.      uppercase  to  lowercase)  in  keys are available.  The _c_m_a_p
  157.      parameter to _d_b_z_f_r_e_s_h is a single character specifying which
  158.      of  several mapping algorithms to use.  Available algorithms
  159.      are:
  160.  
  161.           0000    case-sensitive:  no case mapping
  162.  
  163.           BBBB    same as 0000
  164.  
  165.           NNNNUUUULLLL  same as 0000
  166.  
  167.           ====    case-insensitive:    uppercase    and    lowercase
  168.                equivalent
  169.  
  170.           bbbb    same as ====
  171.  
  172.           CCCC    RFC822 message-ID rules, case-sensitive before `@'
  173.                (with  certain  exceptions)  and  case-insensitive
  174.                after
  175.  
  176.           ????    whatever the local default is, normally CCCC
  177.  
  178.      Mapping algorithm 0000 (no mapping) is faster than  the  others
  179.      and  is  overwhelmingly the correct choice for most applica-
  180.      tions.  Unless compatibility constraints  interfere,  it  is
  181.      more  efficient  to pre-map the keys, storing mapped keys in
  182.      the base file, than to have _d_b_z  do  the  mapping  on  every
  183.      search.
  184.  
  185.      For historical reasons, _f_e_t_c_h and  _s_t_o_r_e  expect  their  _k_e_y
  186.      arguments  to be pre-mapped, but expect unmapped keys in the
  187.      base file.  _D_b_z_f_e_t_c_h and _d_b_z_s_t_o_r_e do the same jobs but  han-
  188.      dle  all  case  mapping internally, so the customer need not
  189.      worry about it.
  190.  
  191.  
  192.  
  193.  
  194.  
  195. Sun Microsystems    Last change: 13 Oct 1990                    3
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. DBZ(3Z)           MISC. REFERENCE MANUAL PAGES            DBZ(3Z)
  203.  
  204.  
  205.  
  206.      _D_b_z stores only the database _v_a_l_u_es in its files, relying on
  207.      reference  to  the  base  file  to  confirm  a hit on a key.
  208.      References to the base file can be minimized, greatly speed-
  209.      ing  up  searches,  if a little bit of information about the
  210.      keys can be stored in the _d_b_z files.  This  is  ``free''  if
  211.      there  are  some unused bits in an _f_s_e_e_k offset, so that the
  212.      offset can be _t_a_g_g_e_d with some information  about  the  key.
  213.      The  _t_a_g_m_a_s_k  parameter  of  _d_b_z_f_r_e_s_h  allows specifying the
  214.      location of unused bits.  _T_a_g_m_a_s_k should be a mask with  one
  215.      group  of contiguous 1111 bits.  The bits in the mask should be
  216.      unused (0) in _m_o_s_t offsets.  The bit immediately  above  the
  217.      mask  (the  _f_l_a_g  bit)  should be unused (0) in _a_l_l offsets;
  218.      (_d_b_z)_s_t_o_r_e will reject attempts to store a key-value pair in
  219.      which  the  _v_a_l_u_e has the flag bit on.  Apart from this res-
  220.      triction, tagging is invisible to the user.   As  a  special
  221.      case,  a  _t_a_g_m_a_s_k  of  1  means ``no tagging'', for use with
  222.      enormous base  files  or  on  systems  with  unusual  offset
  223.      representations.
  224.  
  225.      A _s_i_z_e of 0 given to _d_b_z_f_r_e_s_h is synonymous with  the  local
  226.      default;  the  normal  default is suitable for tables of 90-
  227.      100,000 key-value pairs.  A _c_m_a_p of 0  (NUL)  is  synonymous
  228.      with  the character 0000, signifying no case mapping (note that
  229.      the character ???? specifies the local  default  mapping,  nor-
  230.      mally  CCCC).   A  _t_a_g_m_a_s_k  of  0  is synonymous with the local
  231.      default tag mask, normally 0x7f000000  (specifying  the  top
  232.      bit  in a 32-bit offset as the flag bit, and the next 7 bits
  233.      as the mask, which is suitable for base files  up  to  circa
  234.      24MB).   Calling _d_b_m_i_n_i_t(_n_a_m_e) with the database files empty
  235.      is equivalent to calling _d_b_z_f_r_e_s_h(_n_a_m_e,_0,'\_t','?',_0).
  236.  
  237.      When databases are regenerated periodically, as in news,  it
  238.      is  simplest to pick the parameters for a new database based
  239.      on the old one.  This also permits some memory of past sizes
  240.      of  the  old  database,  so  that a new database size can be
  241.      chosen to cover expected fluctuations.  _D_b_z_a_g_a_i_n is a  vari-
  242.      ant  of _d_b_m_i_n_i_t for creating a new database as a new genera-
  243.      tion of an old database.  The  database  files  for  _o_l_d_b_a_s_e
  244.      must exist.  _D_b_z_a_g_a_i_n is equivalent to calling _d_b_z_f_r_e_s_h with
  245.      the same field separator, case mapping, and tag mask as  the
  246.      old  database,  and  a  _s_i_z_e equal to the result of applying
  247.      _d_b_z_s_i_z_e to the largest number  of  entries  in  the  _o_l_d_b_a_s_e
  248.      database and its previous 10 generations.
  249.  
  250.      When many accesses are being done by the same  program,  _d_b_z
  251.      is  massively  faster  if its first hash table is in memory.
  252.      If an internal flag is 1, an attempt is  made  to  read  the
  253.      table in when the database is opened, and _d_b_m_c_l_o_s_e writes it
  254.      out to disk again (if it was read successfully and has  been
  255.      modified).   _D_b_z_i_n_c_o_r_e  sets  the  flag  to  _n_e_w_v_a_l_u_e (which
  256.      should be 0 or 1) and returns the previous value; this  does
  257.      not  affect  the  status of a database that has already been
  258.  
  259.  
  260.  
  261. Sun Microsystems    Last change: 13 Oct 1990                    4
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. DBZ(3Z)           MISC. REFERENCE MANUAL PAGES            DBZ(3Z)
  269.  
  270.  
  271.  
  272.      opened.  The default is 0.  The attempt to read the table in
  273.      may  fail  due  to memory shortage; in this case _d_b_z quietly
  274.      falls back on its default behavior.  _S_t_o_r_es to an  in-memory
  275.      database  are not (in general) written out to the file until
  276.      _d_b_m_c_l_o_s_e or _d_b_z_s_y_n_c, so if robustness  in  the  presence  of
  277.      crashes  or  concurrent accesses is crucial, in-memory data-
  278.      bases should probably be avoided.
  279.  
  280.      _D_b_z_s_y_n_c causes all buffers etc. to be  flushed  out  to  the
  281.      files.  It is typically used as a precaution against crashes
  282.      or concurrent accesses when a _d_b_z-using process will be run-
  283.      ning for a long time.  It is a somewhat expensive operation,
  284.      especially for an in-memory database.
  285.  
  286.      If _d_b_z has been compiled with debugging facilities available
  287.      (which  makes  it  bigger and a bit slower), _d_b_z_d_e_b_u_g alters
  288.      the value (and returns the previous value)  of  an  internal
  289.      flag which (when 1; default is 0) causes verbose and cryptic
  290.      debugging output on standard output.
  291.  
  292.      Concurrent reading of databases is fairly safe, but there is
  293.      no (inter)locking, so concurrent updating is not.
  294.  
  295.      The database files include a record of the byte order of the
  296.      processor  creating the database, and accesses by processors
  297.      with different byte order will work, although they  will  be
  298.      slightly slower.  Byte order is preserved by _d_b_z_a_g_a_i_n.  How-
  299.      ever, agreement on the size and  internal  structure  of  an
  300.      _f_s_e_e_k  offset is necessary, as is consensus on the character
  301.      set.
  302.  
  303.      An open database occupies  three  _s_t_d_i_o  streams  and  their
  304.      corresponding  file  descriptors;  a fourth is needed for an
  305.      in-memory  database.   Memory  consumption   is   negligible
  306.      (except for _s_t_d_i_o buffers) except for in-memory databases.
  307.  
  308. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  309.      dbz(1), dbm(3)
  310.  
  311. DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
  312.      Functions returning _i_n_t values return 0 for success, -1  for
  313.      failure.   Functions  returning  _d_a_t_u_m values return a value
  314.      with _d_p_t_r set to NULL for failure.  _D_b_m_i_n_i_t attempts to have
  315.      _e_r_r_n_o  set  plausibly  on  return, but otherwise this is not
  316.      guaranteed.  An _e_r_r_n_o of EEEEDDDDOOOOMMMM from  _d_b_m_i_n_i_t  indicates  that
  317.      the database did not appear to be in _d_b_z format.
  318.  
  319. HHHHIIIISSSSTTTTOOOORRRRYYYY
  320.      The  original  _d_b_z  was  written  by  Jon  Zeeff   (zeeff@b-
  321.      tech.ann-arbor.mi.us).   Later contributions by David Butler
  322.      and Mark Moraes.  Extensive reworking, including this  docu-
  323.      mentation,  by Henry Spencer (henry@zoo.toronto.edu) as part
  324.  
  325.  
  326.  
  327. Sun Microsystems    Last change: 13 Oct 1990                    5
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. DBZ(3Z)           MISC. REFERENCE MANUAL PAGES            DBZ(3Z)
  335.  
  336.  
  337.  
  338.      of the C News project.  Hashing function by Peter Honeyman.
  339.  
  340. BBBBUUUUGGGGSSSS
  341.      The _d_p_t_r members of returned _d_a_t_u_m values  point  to  static
  342.      storage which is overwritten by later calls.
  343.  
  344.      Unlike _d_b_m, _d_b_z will misbehave if an existing key-value pair
  345.      is `overwritten' by a new (_d_b_z)_s_t_o_r_e with the same key.  The
  346.      user is responsible for avoiding this  by  using  (_d_b_z)_f_e_t_c_h
  347.      first  to  check  for  duplicates;  an internal optimization
  348.      remembers the result of the first search so there is minimal
  349.      overhead in this.
  350.  
  351.      Waiting until after _d_b_m_i_n_i_t to  bring  the  base  file  into
  352.      existence will fail if _c_h_d_i_r(2) has been used meanwhile.
  353.  
  354.      The RFC822 case mapper implements only a first approximation
  355.      to the hideously-complex RFC822 case rules.
  356.  
  357.      The prime finder in _d_b_z_s_i_z_e is not particularly quick.
  358.  
  359.      Should implement the _d_b_m  functions  _d_e_l_e_t_e,  _f_i_r_s_t_k_e_y,  and
  360.      _n_e_x_t_k_e_y.
  361.  
  362.      On C implementations which trap integer overflow,  _d_b_z  will
  363.      refuse  to  (_d_b_z)_s_t_o_r_e an _f_s_e_e_k offset equal to the greatest
  364.      representable positive number, as this would cause  overflow
  365.      in the biased representation used.
  366.  
  367.      _D_b_z_a_g_a_i_n perhaps ought to notice when many  offsets  in  the
  368.      old  database  were  too big for tagging, and shrink the tag
  369.      mask to match.
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393. Sun Microsystems    Last change: 13 Oct 1990                    6
  394.  
  395.  
  396.  
  397.