~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to drizzled/my_hash.h

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
/* Dynamic hashing of record with different key-length */
 
21
 
 
22
#ifndef DRIZZLED_MY_HASH_H
 
23
#define DRIZZLED_MY_HASH_H
 
24
 
 
25
#include "drizzled/dynamic_array.h"
 
26
 
 
27
namespace drizzled
 
28
{
 
29
 
 
30
typedef struct charset_info_st CHARSET_INFO;
 
31
 
 
32
/*
 
33
  Overhead to store an element in hash
 
34
  Can be used to approximate memory consumption for a hash
 
35
 */
 
36
#define HASH_OVERHEAD (sizeof(char*)*2)
 
37
 
 
38
/* flags for hash_init */
 
39
#define HASH_UNIQUE     1       /* hash_insert fails on duplicate key */
 
40
 
 
41
typedef unsigned char *(*hash_get_key)(const unsigned char *,size_t*,bool);
 
42
typedef void (*hash_free_key)(void *);
 
43
 
 
44
typedef struct st_hash {
 
45
  /* Length of key if const length */
 
46
  size_t key_offset,key_length;
 
47
  uint32_t blength;
 
48
  uint32_t records;
 
49
  uint32_t flags;
 
50
  /* Place for hash_keys */
 
51
  DYNAMIC_ARRAY array;
 
52
  hash_get_key get_key;
 
53
  hash_free_key free;
 
54
  const CHARSET_INFO *charset;
 
55
} HASH;
 
56
 
 
57
/* A search iterator state */
 
58
typedef uint32_t HASH_SEARCH_STATE;
 
59
 
 
60
bool
 
61
_hash_init(HASH *hash,uint32_t growth_size, const CHARSET_INFO * const charset,
 
62
           uint32_t size, size_t key_offset, size_t key_length,
 
63
           hash_get_key get_key,
 
64
           hash_free_key free_element, uint32_t flags);
 
65
#define hash_init(A,B,C,D,E,F,G,H) _hash_init(A,0,B,C,D,E,F,G,H)
 
66
void hash_free(HASH *tree);
 
67
unsigned char *hash_element(HASH *hash,uint32_t idx);
 
68
unsigned char *hash_search(const HASH *info, const unsigned char *key,
 
69
                           size_t length);
 
70
unsigned char *hash_first(const HASH *info, const unsigned char *key,
 
71
                          size_t length, HASH_SEARCH_STATE *state);
 
72
unsigned char *hash_next(const HASH *info, const unsigned char *key,
 
73
                         size_t length, HASH_SEARCH_STATE *state);
 
74
bool my_hash_insert(HASH *info,const unsigned char *data);
 
75
bool hash_delete(HASH *hash,unsigned char *record);
 
76
 
 
77
#define hash_inited(H) ((H)->array.buffer != 0)
 
78
 
 
79
} /* namespace drizzled */
 
80
 
 
81
#endif /* DRIZZLED_MY_HASH_H */