SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DynamicArray.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 1999-2009 Soeren Sonnenburg
8  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9  */
10 
11 #ifndef _DYNAMIC_ARRAY_H_
12 #define _DYNAMIC_ARRAY_H_
13 
14 #include <shogun/base/SGObject.h>
15 #include <shogun/base/DynArray.h>
16 #include <shogun/base/Parameter.h>
17 
18 namespace shogun
19 {
28 template <class T> class CDynamicArray :public CSGObject
29 {
30  public:
35  CDynamicArray(int32_t p_resize_granularity=128)
36  : CSGObject()
37  {
38  set_generic<T>();
39 
41  &m_array.num_elements, "array",
42  "Memory for dynamic array.");
43  m_parameters->add(&m_array.last_element_idx,
44  "last_element_idx",
45  "Element with largest index.");
46  m_parameters->add(&m_array.resize_granularity,
47  "resize_granularity",
48  "shrink/grow step size.");
49  }
50 
51  virtual ~CDynamicArray() {}
52 
58  inline int32_t set_granularity(int32_t g)
59  {
60  return m_array.set_granularity(g);
61  }
62 
67  inline int32_t get_array_size()
68  {
69  return m_array.get_array_size();
70  }
71 
76  inline int32_t get_num_elements() const
77  {
78  return m_array.get_num_elements();
79  }
80 
88  inline T get_element(int32_t index) const
89  {
90  return m_array.get_element(index);
91  }
92 
100  inline T get_element_safe(int32_t index) const
101  {
102  return m_array.get_element_safe(index);
103  }
104 
111  inline bool set_element(T element, int32_t index)
112  {
113  return m_array.set_element(element, index);
114  }
115 
122  inline bool insert_element(T element, int32_t index)
123  {
124  return m_array.insert_element(element, index);
125  }
126 
132  inline bool append_element(T element)
133  {
134  return m_array.append_element(element);
135  }
136 
142  inline void push_back(T element)
143  { m_array.push_back(element); }
144 
148  inline void pop_back()
149  {
150  m_array.pop_back();
151  }
152 
158  inline T back()
159  {
160  return m_array.back();
161  }
162 
169  inline int32_t find_element(T element)
170  {
171  return m_array.find_element(element);
172  }
173 
180  inline bool delete_element(int32_t idx)
181  {
182  return m_array.delete_element(idx);
183  }
184 
190  inline bool resize_array(int32_t n)
191  {
192  return m_array.resize_array(n);
193  }
194 
202  inline T* get_array() const
203  {
204  return m_array.get_array();
205  }
206 
213  inline void set_array(T* p_array, int32_t p_num_elements,
214  int32_t array_size)
215  {
216  m_array.set_array(p_array, p_num_elements, array_size);
217  }
218 
220  inline void clear_array()
221  {
222  m_array.clear_array();
223  }
224 
234  inline T operator[](int32_t index) const
235  {
236  return m_array[index];
237  }
238 
245  {
246  m_array = orig.m_array;
247  return *this;
248  }
249 
251  inline void shuffle() { m_array.shuffle(); }
252 
254  inline virtual const char* get_name() const
255  {
256  return "DynamicArray";
257  }
258 
259  protected:
260 
263 };
264 }
265 #endif /* _DYNAMIC_ARRAY_H_ */

SHOGUN Machine Learning Toolbox - Documentation