hotspot/src/share/vm/utilities/array.hpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 1551 b431de37a22c
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2000-2005 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// correct linkage required to compile w/o warnings
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
// (must be on file level - cannot be local)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
extern "C" { typedef int (*ftype)(const void*, const void*); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
class ResourceArray: public ResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  int   _length;                                 // the number of array elements
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  void* _data;                                   // the array memory
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  int   _nesting;                                // the resource area nesting level
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  // creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  ResourceArray() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
    _length  = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
    _data    = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    DEBUG_ONLY(init_nesting();)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  ResourceArray(size_t esize, int length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    assert(length >= 0, "illegal length");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    _length  = length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    _data    = resource_allocate_bytes(esize * length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    DEBUG_ONLY(init_nesting();)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  void init_nesting();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  // helper functions
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  void sort     (size_t esize, ftype f);         // sort the array
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  void expand   (size_t esize, int i, int& size);// expand the array to include slot i
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  void remove_at(size_t esize, int i);           // remove the element in slot i
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  // standard operations
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  int  length() const                            { return _length; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  bool is_empty() const                          { return length() == 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
class CHeapArray: public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  int   _length;                                 // the number of array elements
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  void* _data;                                   // the array memory
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  // creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  CHeapArray() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    _length  = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    _data    = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  CHeapArray(size_t esize, int length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    assert(length >= 0, "illegal length");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    _length  = length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    _data    = (void*) NEW_C_HEAP_ARRAY(char *, esize * length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  void init_nesting();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  // helper functions
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  void sort     (size_t esize, ftype f);         // sort the array
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  void expand   (size_t esize, int i, int& size);// expand the array to include slot i
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  void remove_at(size_t esize, int i);           // remove the element in slot i
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  // standard operations
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  int  length() const                            { return _length; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  bool is_empty() const                          { return length() == 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
#define define_generic_array(array_name,element_type, base_class)                        \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  class array_name: public base_class {                                                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
   protected:                                                                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    typedef element_type etype;                                                          \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    enum { esize = sizeof(etype) };                                                      \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
                                                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    void base_remove_at(size_t size, int i) { base_class::remove_at(size, i); }          \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
                                                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
   public:                                                                               \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    /* creation */                                                                       \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    array_name() : base_class()                       {}                                 \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    array_name(const int length) : base_class(esize, length) {}                          \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    array_name(const int length, const etype fx) : base_class(esize, length) {           \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
      for (int i = 0; i < length; i++) ((etype*)_data)[i] = fx;                          \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    }                                                                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
                                                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    /* standard operations */                                                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    etype& operator [] (const int i) const {                                             \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
      assert(0 <= i && i < length(), "index out of bounds");                             \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
      return ((etype*)_data)[i];                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    }                                                                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
                                                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    int index_of(const etype x) const {                                                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
      int i = length();                                                                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
      while (i-- > 0 && ((etype*)_data)[i] != x) ;                                       \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
      /* i < 0 || ((etype*)_data)_data[i] == x */                                        \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
      return i;                                                                          \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    }                                                                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
                                                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    void sort(int f(etype*, etype*))             { base_class::sort(esize, (ftype)f); }  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    bool contains(const etype x) const           { return index_of(x) >= 0; }            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
                                                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    /* deprecated operations - for compatibility with GrowableArray only */              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    etype  at(const int i) const                 { return (*this)[i]; }                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    void   at_put(const int i, const etype x)    { (*this)[i] = x; }                     \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    etype* adr_at(const int i)                   { return &(*this)[i]; }                 \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    int    find(const etype x)                   { return index_of(x); }                 \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  };                                                                                     \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
#define define_array(array_name,element_type)                                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  define_generic_array(array_name, element_type, ResourceArray)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
#define define_stack(stack_name,array_name)                                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  class stack_name: public array_name {                                                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
   protected:                                                                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    int _size;                                                                           \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
                                                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    void grow(const int i, const etype fx) {                                             \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      assert(i >= length(), "index too small");                                          \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
      if (i >= size()) expand(esize, i, _size);                                          \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
      for (int j = length(); j <= i; j++) ((etype*)_data)[j] = fx;                       \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
      _length = i+1;                                                                     \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    }                                                                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
                                                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
   public:                                                                               \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    /* creation */                                                                       \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    stack_name() : array_name()                  { _size = 0; }                          \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    stack_name(const int size) : array_name(size){ _length = 0; _size = size; }          \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    stack_name(const int size, const etype fx) : array_name(size, fx) { _size = size; }  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
                                                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    /* standard operations */                                                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    int size() const                             { return _size; }                       \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
                                                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    void push(const etype x) {                                                           \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
      if (length() >= size()) expand(esize, length(), _size);                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
      ((etype*)_data)[_length++] = x;                                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    }                                                                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
                                                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    etype pop() {                                                                        \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
      assert(!is_empty(), "stack is empty");                                             \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
      return ((etype*)_data)[--_length];                                                 \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    }                                                                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
                                                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    etype top() const {                                                                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
      assert(!is_empty(), "stack is empty");                                             \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
      return ((etype*)_data)[length() - 1];                                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    }                                                                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
                                                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    void push_all(const stack_name* stack) {                                             \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
      const int l = stack->length();                                                     \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
      for (int i = 0; i < l; i++) push(((etype*)(stack->_data))[i]);                     \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    }                                                                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
                                                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    etype at_grow(const int i, const etype fx) {                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
      if (i >= length()) grow(i, fx);                                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
      return ((etype*)_data)[i];                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    }                                                                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
                                                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    void at_put_grow(const int i, const etype x, const etype fx) {                       \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
      if (i >= length()) grow(i, fx);                                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
      ((etype*)_data)[i] = x;                                                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    }                                                                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
                                                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    void truncate(const int length) {                                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
      assert(0 <= length && length <= this->length(), "illegal length");                 \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
      _length = length;                                                                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    }                                                                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
                                                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    void remove_at(int i)                        { base_remove_at(esize, i); }           \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    void remove(etype x)                         { remove_at(index_of(x)); }             \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
                                                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    /* inserts the given element before the element at index i */                        \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    void insert_before(const int i, const etype el)  {                                   \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
      int len = length();                                                                \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
      int new_length = len + 1;                                                          \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
      if (new_length >= size()) expand(esize, new_length, _size);                        \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
      for (int j = len - 1; j >= i; j--) {                                               \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
        ((etype*)_data)[j + 1] = ((etype*)_data)[j];                                     \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
      }                                                                                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
      _length = new_length;                                                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
      at_put(i, el);                                                                     \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    }                                                                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
                                                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    /* inserts contents of the given stack before the element at index i */              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    void insert_before(const int i, const stack_name *st) {                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
      if (st->length() == 0) return;                                                     \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
      int len = length();                                                                \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
      int st_len = st->length();                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
      int new_length = len + st_len;                                                     \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
      if (new_length >= size()) expand(esize, new_length, _size);                        \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
      int j;                                                                             \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
      for (j = len - 1; j >= i; j--) {                                                   \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
        ((etype*)_data)[j + st_len] = ((etype*)_data)[j];                                \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
      }                                                                                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
      for (j = 0; j < st_len; j++) {                                                     \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
        ((etype*)_data)[i + j] = ((etype*)st->_data)[j];                                 \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
      }                                                                                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
      _length = new_length;                                                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    }                                                                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
                                                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
    /* deprecated operations - for compatibility with GrowableArray only */              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    int  capacity() const                        { return size(); }                      \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    void clear()                                 { truncate(0); }                        \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    void trunc_to(const int length)              { truncate(length); }                   \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    void append(const etype x)                   { push(x); }                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    void appendAll(const stack_name* stack)      { push_all(stack); }                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    etype last() const                           { return top(); }                       \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  };                                                                                     \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
#define define_resource_list(element_type)                                               \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  define_generic_array(element_type##Array, element_type, ResourceArray)                 \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  define_stack(element_type##List, element_type##Array)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
#define define_resource_pointer_list(element_type)                                       \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  define_generic_array(element_type##Array, element_type *, ResourceArray)               \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  define_stack(element_type##List, element_type##Array)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
#define define_c_heap_list(element_type)                                                 \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  define_generic_array(element_type##Array, element_type, CHeapArray)                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  define_stack(element_type##List, element_type##Array)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
#define define_c_heap_pointer_list(element_type)                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  define_generic_array(element_type##Array, element_type *, CHeapArray)                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  define_stack(element_type##List, element_type##Array)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
// Arrays for basic types
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
define_array(boolArray, bool)          define_stack(boolStack, boolArray)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
define_array(intArray , int )          define_stack(intStack , intArray )