~drizzle-trunk/drizzle/development

520.7.1 by Monty Taylor
Moved hash.c to drizzled.
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
520.7.1 by Monty Taylor
Moved hash.c to drizzled.
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
 */
1 by brian
clean slate
19
20
/* Dynamic hashing of record with different key-length */
21
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
22
#pragma once
520.7.1 by Monty Taylor
Moved hash.c to drizzled.
23
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
24
#include <drizzled/dynamic_array.h>
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
25
2221.7.5 by Olaf van der Spek
Refactor
26
namespace drizzled {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
27
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
28
typedef struct charset_info_st CHARSET_INFO;
29
1 by brian
clean slate
30
/*
31
  Overhead to store an element in hash
32
  Can be used to approximate memory consumption for a hash
33
 */
34
#define HASH_OVERHEAD (sizeof(char*)*2)
35
36
/* flags for hash_init */
37
#define HASH_UNIQUE     1       /* hash_insert fails on duplicate key */
38
481 by Brian Aker
Remove all of uchar.
39
typedef unsigned char *(*hash_get_key)(const unsigned char *,size_t*,bool);
1 by brian
clean slate
40
typedef void (*hash_free_key)(void *);
41
2221.7.5 by Olaf van der Spek
Refactor
42
struct HASH_LINK 
43
{
44
  /* index to next key */
45
  uint32_t next;
46
  /* data for current entry */
47
  unsigned char *data;
48
} ;
49
50
struct HASH
51
{
52
  // typedef std::vector<HASH_LINK> array_t;
53
  typedef DYNAMIC_ARRAY array_t;
520.7.1 by Monty Taylor
Moved hash.c to drizzled.
54
  /* Length of key if const length */
55
  size_t key_offset,key_length;
1138 by Brian Aker
Merge of Joe Daly's work
56
  uint32_t blength;
298 by Brian Aker
ulong conversion.
57
  uint32_t records;
482 by Brian Aker
Remove uint.
58
  uint32_t flags;
520.7.1 by Monty Taylor
Moved hash.c to drizzled.
59
  /* Place for hash_keys */
2221.7.5 by Olaf van der Spek
Refactor
60
  array_t array;
1 by brian
clean slate
61
  hash_get_key get_key;
598.1.1 by Super-User
Fixed solaris build crap.
62
  hash_free_key free;
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
63
  const CHARSET_INFO *charset;
2221.7.5 by Olaf van der Spek
Refactor
64
};
1 by brian
clean slate
65
66
/* A search iterator state */
482 by Brian Aker
Remove uint.
67
typedef uint32_t HASH_SEARCH_STATE;
1 by brian
clean slate
68
598.1.1 by Super-User
Fixed solaris build crap.
69
bool
70
_hash_init(HASH *hash,uint32_t growth_size, const CHARSET_INFO * const charset,
71
           uint32_t size, size_t key_offset, size_t key_length,
72
           hash_get_key get_key,
73
           hash_free_key free_element, uint32_t flags);
595 by Brian Aker
Fix, partial, for Sun Studio.
74
#define hash_init(A,B,C,D,E,F,G,H) _hash_init(A,0,B,C,D,E,F,G,H)
1 by brian
clean slate
75
void hash_free(HASH *tree);
481 by Brian Aker
Remove all of uchar.
76
unsigned char *hash_element(HASH *hash,uint32_t idx);
520.7.1 by Monty Taylor
Moved hash.c to drizzled.
77
unsigned char *hash_search(const HASH *info, const unsigned char *key,
78
                           size_t length);
79
unsigned char *hash_first(const HASH *info, const unsigned char *key,
80
                          size_t length, HASH_SEARCH_STATE *state);
81
unsigned char *hash_next(const HASH *info, const unsigned char *key,
82
                         size_t length, HASH_SEARCH_STATE *state);
481 by Brian Aker
Remove all of uchar.
83
bool my_hash_insert(HASH *info,const unsigned char *data);
84
bool hash_delete(HASH *hash,unsigned char *record);
1 by brian
clean slate
85
86
#define hash_inited(H) ((H)->array.buffer != 0)
87
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
88
} /* namespace drizzled */
89