Drizzled Public API Documentation

my_hash.h
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 /* Dynamic hashing of record with different key-length */
00021 
00022 #pragma once
00023 
00024 #include <drizzled/dynamic_array.h>
00025 
00026 namespace drizzled {
00027 
00028 /*
00029   Overhead to store an element in hash
00030   Can be used to approximate memory consumption for a hash
00031  */
00032 #define HASH_OVERHEAD (sizeof(char*)*2)
00033 
00034 /* flags for hash_init */
00035 #define HASH_UNIQUE     1       /* hash_insert fails on duplicate key */
00036 
00037 typedef unsigned char *(*hash_get_key)(const unsigned char *,size_t*,bool);
00038 typedef void (*hash_free_key)(void *);
00039 
00040 struct HASH_LINK 
00041 {
00042   /* index to next key */
00043   uint32_t next;
00044   /* data for current entry */
00045   unsigned char *data;
00046 } ;
00047 
00048 struct charset_info_st;
00049 
00050 struct HASH
00051 {
00052   // typedef std::vector<HASH_LINK> array_t;
00053   typedef DYNAMIC_ARRAY array_t;
00054   /* Length of key if const length */
00055   size_t key_offset,key_length;
00056   uint32_t blength;
00057   uint32_t records;
00058   uint32_t flags;
00059   /* Place for hash_keys */
00060   array_t array;
00061   hash_get_key get_key;
00062   hash_free_key free;
00063   const charset_info_st *charset;
00064 };
00065 
00066 /* A search iterator state */
00067 typedef uint32_t HASH_SEARCH_STATE;
00068 
00069 void
00070 _hash_init(HASH *hash,uint32_t growth_size, const charset_info_st* const,
00071            uint32_t size, size_t key_offset, size_t key_length,
00072            hash_get_key get_key,
00073            hash_free_key free_element, uint32_t flags);
00074 #define hash_init(A,B,C,D,E,F,G,H) _hash_init(A,0,B,C,D,E,F,G,H)
00075 void hash_free(HASH *tree);
00076 unsigned char *hash_search(const HASH *info, const unsigned char *key,
00077                            size_t length);
00078 unsigned char *hash_first(const HASH *info, const unsigned char *key, size_t length, HASH_SEARCH_STATE *state);
00079 bool my_hash_insert(HASH *info,const unsigned char *data);
00080 bool hash_delete(HASH *hash,unsigned char *record);
00081 
00082 } /* namespace drizzled */
00083