~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/sql_list.h

  • Committer: Stewart Smith
  • Date: 2008-07-13 08:00:16 UTC
  • mto: (210.1.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 211.
  • Revision ID: stewart@flamingspork.com-20080713080016-8qtjv9ypt42azzr6
CRC32() as UDF

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
 
#ifndef DRIZZLED_SQL_LIST_H
21
 
#define DRIZZLED_SQL_LIST_H
22
 
 
23
 
 
24
 
#include <utility>
25
 
#include <algorithm>
26
 
#include <stdlib.h>
27
 
#include <drizzled/sql_alloc.h>
28
 
 
29
 
/** Struct to handle simple linked lists. */
30
 
typedef struct st_sql_list {
31
 
  uint32_t elements;
32
 
  unsigned char *first;
33
 
  unsigned char **next;
34
 
 
35
 
  st_sql_list() {}                              /* Remove gcc warning */
36
 
  inline void empty()
37
 
  {
38
 
    elements=0;
39
 
    first=0;
40
 
    next= &first;
41
 
  }
42
 
  inline void link_in_list(unsigned char *element,unsigned char **next_ptr)
43
 
  {
44
 
    elements++;
45
 
    (*next)=element;
46
 
    next= next_ptr;
47
 
    *next=0;
48
 
  }
49
 
  inline void save_and_clear(struct st_sql_list *save)
50
 
  {
51
 
    *save= *this;
52
 
    empty();
53
 
  }
54
 
  inline void push_front(struct st_sql_list *save)
55
 
  {
56
 
    *save->next= first;                         /* link current list last */
57
 
    first= save->first;
58
 
    elements+= save->elements;
59
 
  }
60
 
  inline void push_back(struct st_sql_list *save)
61
 
  {
62
 
    if (save->first)
63
 
    {
64
 
      *next= save->first;
65
 
      next= save->next;
66
 
      elements+= save->elements;
67
 
    }
68
 
  }
69
 
} SQL_LIST;
 
1
#ifndef INCLUDES_MYSQL_SQL_LIST_H
 
2
#define INCLUDES_MYSQL_SQL_LIST_H
 
3
/* Copyright (C) 2000-2003 MySQL AB
 
4
 
 
5
   This program is free software; you can redistribute it and/or modify
 
6
   it under the terms of the GNU General Public License as published by
 
7
   the Free Software Foundation; version 2 of the License.
 
8
 
 
9
   This program is distributed in the hope that it will be useful,
 
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
   GNU General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU General Public License
 
15
   along with this program; if not, write to the Free Software
 
16
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
17
 
 
18
 
 
19
#ifdef USE_PRAGMA_INTERFACE
 
20
#pragma interface                       /* gcc class implementation */
 
21
#endif
 
22
 
 
23
/* mysql standard class memory allocator */
 
24
 
 
25
class Sql_alloc
 
26
{
 
27
public:
 
28
  static void *operator new(size_t size) throw ()
 
29
  {
 
30
    return sql_alloc(size);
 
31
  }
 
32
  static void *operator new[](size_t size)
 
33
  {
 
34
    return sql_alloc(size);
 
35
  }
 
36
  static void *operator new[](size_t size, MEM_ROOT *mem_root) throw ()
 
37
  { return alloc_root(mem_root, size); }
 
38
  static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
 
39
  { return alloc_root(mem_root, size); }
 
40
  static void operator delete(void *ptr __attribute__((__unused__)),
 
41
                              size_t size __attribute__((__unused__)))
 
42
  { TRASH(ptr, size); }
 
43
  static void operator delete(void *ptr __attribute__((__unused__)),
 
44
                              MEM_ROOT *mem_root __attribute__((__unused__)))
 
45
  { /* never called */ }
 
46
  static void operator delete[](void *ptr __attribute__((__unused__)),
 
47
                                MEM_ROOT *mem_root __attribute__((__unused__)))
 
48
  { /* never called */ }
 
49
  static void operator delete[](void *ptr __attribute__((__unused__)),
 
50
                                size_t size __attribute__((__unused__)))
 
51
  { TRASH(ptr, size); }
 
52
#ifdef HAVE_purify
 
53
  bool dummy;
 
54
  inline Sql_alloc() :dummy(0) {}
 
55
  inline ~Sql_alloc() {}
 
56
#else
 
57
  inline Sql_alloc() {}
 
58
  inline ~Sql_alloc() {}
 
59
#endif
 
60
 
 
61
};
 
62
 
70
63
 
71
64
/*
72
65
  Basic single linked list
107
100
  list_node *first,**last;
108
101
 
109
102
public:
110
 
  uint32_t elements;
 
103
  uint elements;
111
104
 
112
105
  inline void empty() { elements=0; first= &end_of_list; last=&first;}
113
106
  inline base_list() { empty(); }
133
126
    list_copy_and_replace_each_value after creating a copy.
134
127
  */
135
128
  base_list(const base_list &rhs, MEM_ROOT *mem_root);
136
 
  inline base_list(bool) { }
 
129
  inline base_list(bool error __attribute__((__unused__))) { }
137
130
  inline bool push_back(void *info)
138
131
  {
139
132
    if (((*last)=new list_node(info, &end_of_list)))
224
217
  */
225
218
  inline void swap(base_list &rhs)
226
219
  {
227
 
    std::swap(first, rhs.first);
228
 
    std::swap(last, rhs.last);
229
 
    std::swap(elements, rhs.elements);
 
220
    swap_variables(list_node *, first, rhs.first);
 
221
    swap_variables(list_node **, last, rhs.last);
 
222
    swap_variables(uint, elements, rhs.elements);
230
223
  }
231
224
  inline list_node* last_node() { return *last; }
232
225
  inline list_node* first_node() { return first;}
249
242
      check_list()
250
243
        name  Name to print to trace file
251
244
 
252
 
    RETURN
 
245
    RETURN 
253
246
      1  The list is Ok.
254
247
      0  List invariants are not met.
255
248
  */
258
251
  {
259
252
    base_list *list= this;
260
253
    list_node *node= first;
261
 
    uint32_t cnt= 0;
 
254
    uint cnt= 0;
262
255
 
263
256
    while (node->next != &end_of_list)
264
257
    {
298
291
protected:
299
292
  base_list *list;
300
293
  list_node **el,**prev,*current;
301
 
  void sublist(base_list &ls, uint32_t elm)
 
294
  void sublist(base_list &ls, uint elm)
302
295
  {
303
296
    ls.first= *el;
304
297
    ls.last= list->last;
305
298
    ls.elements= elm;
306
299
  }
307
300
public:
308
 
  base_list_iterator()
 
301
  base_list_iterator() 
309
302
    :list(0), el(0), prev(0), current(0)
310
303
  {}
311
304
 
312
 
  base_list_iterator(base_list &list_par)
 
305
  base_list_iterator(base_list &list_par) 
313
306
  { init(list_par); }
314
307
 
315
308
  inline void init(base_list &list_par)
431
424
template <class T> class List_iterator_fast :public base_list_iterator
432
425
{
433
426
protected:
434
 
  inline T *replace(T *)   { return (T*) 0; }
435
 
  inline T *replace(List<T> &) { return (T*) 0; }
 
427
  inline T *replace(T *a __attribute__((__unused__)))   { return (T*) 0; }
 
428
  inline T *replace(List<T> &a __attribute__((__unused__))) { return (T*) 0; }
436
429
  inline void remove(void)  { }
437
 
  inline void after(T *a)   { }
 
430
  inline void after(T *a __attribute__((__unused__)))   { }
438
431
  inline T** ref(void)      { return (T**) 0; }
439
432
 
440
433
public:
443
436
  inline void init(List<T> &a) { base_list_iterator::init(a); }
444
437
  inline T* operator++(int) { return (T*) base_list_iterator::next_fast(); }
445
438
  inline void rewind(void)  { base_list_iterator::rewind(); }
446
 
  void sublist(List<T> &list_arg, uint32_t el_arg)
 
439
  void sublist(List<T> &list_arg, uint el_arg)
447
440
  {
448
441
    base_list_iterator::sublist(list_arg, el_arg);
449
442
  }
452
445
 
453
446
/*
454
447
  A simple intrusive list which automaticly removes element from list
455
 
  on delete (for Session element)
 
448
  on delete (for THD element)
456
449
*/
457
450
 
458
451
struct ilink
460
453
  struct ilink **prev,*next;
461
454
  static void *operator new(size_t size)
462
455
  {
463
 
    return (void*)malloc((uint32_t)size);
 
456
    return (void*)my_malloc((uint)size, MYF(MY_WME | MY_FAE | ME_FATALERROR));
464
457
  }
465
 
  static void operator delete(void* ptr_arg, size_t)
 
458
  static void operator delete(void* ptr_arg,
 
459
                              size_t size __attribute__((__unused__)))
466
460
  {
467
 
     free((unsigned char*)ptr_arg);
 
461
     my_free((uchar*)ptr_arg, MYF(MY_WME|MY_ALLOW_ZERO_PTR));
468
462
  }
469
463
 
470
464
  inline ilink()
499
493
  const char* key;
500
494
  const char* val;
501
495
  i_string_pair():key(0),val(0) { }
502
 
  i_string_pair(const char* key_arg, const char* val_arg) :
 
496
  i_string_pair(const char* key_arg, const char* val_arg) : 
503
497
    key(key_arg),val(val_arg) {}
504
498
};
505
499
 
570
564
public:
571
565
  I_List() :base_ilist()        {}
572
566
  inline void empty()           { base_ilist::empty(); }
573
 
  inline bool is_empty()        { return base_ilist::is_empty(); }
 
567
  inline bool is_empty()        { return base_ilist::is_empty(); } 
574
568
  inline void append(T* a)      { base_ilist::append(a); }
575
569
  inline void push_back(T* a)   { base_ilist::push_back(a); }
576
570
  inline T* get()               { return (T*) base_ilist::get(); }
599
593
  Evidently not all template arguments have clone() method with
600
594
  the right signature.
601
595
 
602
 
  @return You must query the error state in Session for out-of-memory
 
596
  @return You must query the error state in THD for out-of-memory
603
597
  situation after calling this function.
604
598
*/
605
599
 
615
609
    it.replace(el->clone(mem_root));
616
610
}
617
611
 
618
 
/* sql_list.cc */
619
 
void free_list(I_List <i_string_pair> *list);
620
 
void free_list(I_List <i_string> *list);
621
 
 
622
 
 
623
 
#endif // DRIZZLED_SQL_LIST_H
 
612
#endif // INCLUDES_MYSQL_SQL_LIST_H