hash.h
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:5k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /*-
  2.  * See the file LICENSE for redistribution information.
  3.  *
  4.  * Copyright (c) 1996, 1997, 1998, 1999, 2000
  5.  * Sleepycat Software.  All rights reserved.
  6.  */
  7. /*
  8.  * Copyright (c) 1990, 1993, 1994
  9.  * Margo Seltzer.  All rights reserved.
  10.  */
  11. /*
  12.  * Copyright (c) 1990, 1993, 1994
  13.  * The Regents of the University of California.  All rights reserved.
  14.  *
  15.  * This code is derived from software contributed to Berkeley by
  16.  * Margo Seltzer.
  17.  *
  18.  * Redistribution and use in source and binary forms, with or without
  19.  * modification, are permitted provided that the following conditions
  20.  * are met:
  21.  * 1. Redistributions of source code must retain the above copyright
  22.  *    notice, this list of conditions and the following disclaimer.
  23.  * 2. Redistributions in binary form must reproduce the above copyright
  24.  *    notice, this list of conditions and the following disclaimer in the
  25.  *    documentation and/or other materials provided with the distribution.
  26.  * 3. Neither the name of the University nor the names of its contributors
  27.  *    may be used to endorse or promote products derived from this software
  28.  *    without specific prior written permission.
  29.  *
  30.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  31.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  32.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  34.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  38.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  39.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  40.  * SUCH DAMAGE.
  41.  *
  42.  * $Id: hash.h,v 11.19 2000/12/21 23:05:16 krinsky Exp $
  43.  */
  44. /* Hash internal structure. */
  45. typedef struct hash_t {
  46. db_pgno_t meta_pgno; /* Page number of the meta data page. */
  47. u_int32_t h_ffactor; /* Fill factor. */
  48. u_int32_t h_nelem; /* Number of elements. */
  49. /* Hash function. */
  50. u_int32_t (*h_hash) __P((DB *, const void *, u_int32_t));
  51. } HASH;
  52. /* Cursor structure definitions. */
  53. typedef struct cursor_t {
  54. /* struct __dbc_internal */
  55. __DBC_INTERNAL
  56. /* Hash private part */
  57. /* Per-thread information */
  58. DB_LOCK hlock; /* Metadata page lock. */
  59. HMETA *hdr; /* Pointer to meta-data page. */
  60. PAGE *split_buf; /* Temporary buffer for splits. */
  61. /* Hash cursor information */
  62. db_pgno_t bucket; /* Bucket we are traversing. */
  63. db_pgno_t lbucket; /* Bucket for which we are locked. */
  64. db_indx_t dup_off; /* Offset within a duplicate set. */
  65. db_indx_t dup_len; /* Length of current duplicate. */
  66. db_indx_t dup_tlen; /* Total length of duplicate entry. */
  67. u_int32_t seek_size; /* Number of bytes we need for add. */
  68. db_pgno_t seek_found_page;/* Page on which we can insert. */
  69. u_int32_t order; /* Relative order among deleted curs. */
  70. #define H_CONTINUE 0x0001 /* Join--search strictly fwd for data */
  71. #define H_DELETED 0x0002 /* Cursor item is deleted. */
  72. #define H_DIRTY 0x0004 /* Meta-data page needs to be written */
  73. #define H_DUPONLY 0x0008 /* Dups only; do not change key. */
  74. #define H_EXPAND 0x0010 /* Table expanded. */
  75. #define H_ISDUP 0x0020 /* Cursor is within duplicate set. */
  76. #define H_NEXT_NODUP 0x0040 /* Get next non-dup entry. */
  77. #define H_NOMORE 0x0080 /* No more entries in bucket. */
  78. #define H_OK 0x0100 /* Request succeeded. */
  79. u_int32_t flags;
  80. } HASH_CURSOR;
  81. /* Test string. */
  82. #define CHARKEY "%$sniglet^&"
  83. /* Overflow management */
  84. /*
  85.  * The spares table indicates the page number at which each doubling begins.
  86.  * From this page number we subtract the number of buckets already allocated
  87.  * so that we can do a simple addition to calculate the page number here.
  88.  */
  89. #define BS_TO_PAGE(bucket, spares)
  90. ((bucket) + (spares)[__db_log2((bucket) + 1)])
  91. #define BUCKET_TO_PAGE(I, B) (BS_TO_PAGE((B), (I)->hdr->spares))
  92. /* Constraints about much data goes on a page. */
  93. #define MINFILL 4
  94. #define ISBIG(I, N) (((N) > ((I)->hdr->dbmeta.pagesize / MINFILL)) ? 1 : 0)
  95. /* Shorthands for accessing structure */
  96. #define NDX_INVALID 0xFFFF
  97. #define BUCKET_INVALID 0xFFFFFFFF
  98. /* On page duplicates are stored as a string of size-data-size triples. */
  99. #define DUP_SIZE(len) ((len) + 2 * sizeof(db_indx_t))
  100. /* Log messages types (these are subtypes within a record type) */
  101. #define PAIR_KEYMASK 0x1
  102. #define PAIR_DATAMASK 0x2
  103. #define PAIR_DUPMASK 0x4
  104. #define PAIR_MASK 0xf
  105. #define PAIR_ISKEYBIG(N) (N & PAIR_KEYMASK)
  106. #define PAIR_ISDATABIG(N) (N & PAIR_DATAMASK)
  107. #define PAIR_ISDATADUP(N) (N & PAIR_DUPMASK)
  108. #define OPCODE_OF(N) (N & ~PAIR_MASK)
  109. #define PUTPAIR 0x20
  110. #define DELPAIR 0x30
  111. #define PUTOVFL 0x40
  112. #define DELOVFL 0x50
  113. #define HASH_UNUSED1 0x60
  114. #define HASH_UNUSED2 0x70
  115. #define SPLITOLD 0x80
  116. #define SPLITNEW 0x90
  117. typedef enum {
  118. DB_HAM_CHGPG = 1,
  119. DB_HAM_SPLIT = 2,
  120. DB_HAM_DUP   = 3
  121. } db_ham_mode;
  122. #include "hash_auto.h"
  123. #include "hash_ext.h"
  124. #include "db_am.h"