SHOGUN
v1.1.0
Main Page
Related Pages
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
shogun
lib
Set.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) 2009 Soeren Sonnenburg
8
* Copyright (C) 2009 Fraunhofer Institute FIRST and Max-Planck-Society
9
*/
10
11
#ifndef _SET_H_
12
#define _SET_H_
13
14
#include <
shogun/lib/common.h
>
15
#include <
shogun/mathematics/Math.h
>
16
#include <
shogun/base/DynArray.h
>
17
#include <
shogun/base/SGObject.h
>
18
19
namespace
shogun
20
{
26
template
<
class
T>
class
CSet
:
public
CSGObject
27
{
28
public
:
30
CSet
(
bool
traceable=
true
)
31
{
32
array
=
new
DynArray<T>
(1024, traceable);
33
}
34
36
~CSet
()
37
{
38
delete
array
;
39
}
40
45
inline
void
add
(T e)
46
{
47
if
(!
contains
(e))
48
array
->append_element(e);
49
}
50
55
inline
void
remove
(T e)
56
{
57
int32_t idx=
array
->find_element(e);
58
if
(idx>=0)
59
array
->delete_element(idx);
60
}
61
66
inline
bool
contains
(T e)
67
{
68
int32_t idx=
array
->find_element(e);
69
return
(idx!=-1);
70
}
71
77
inline
int32_t
index_of
(T e)
78
{
79
return
array
->find_element(e);
80
}
81
86
inline
int32_t
get_num_elements
()
const
87
{
88
return
array
->get_num_elements();
89
}
90
98
inline
T
get_element
(int32_t index)
const
99
{
100
return
array
->get_element(index);
101
}
102
110
inline
T*
get_element_ptr
(int32_t index)
111
{
112
return
array
->get_element_ptr(index);
113
}
114
123
inline
T
operator[]
(int32_t index)
const
124
{
125
return
array
->get_element(index);
126
}
127
129
inline
T*
get_array
()
130
{
131
return
array
->get_array();
132
}
133
135
inline
virtual
const
char
*
get_name
()
const
{
return
"Set"
; }
136
137
protected
:
139
DynArray<T>
*
array
;
140
};
141
}
142
#endif //_SET_H_
SHOGUN
Machine Learning Toolbox - Documentation