/usr/include/shogun/lib/Set.h is in libshogun-dev 1.1.0-4ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | /*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Written (W) 2009 Soeren Sonnenburg
* Copyright (C) 2009 Fraunhofer Institute FIRST and Max-Planck-Society
*/
#ifndef _SET_H_
#define _SET_H_
#include <shogun/lib/common.h>
#include <shogun/mathematics/Math.h>
#include <shogun/base/DynArray.h>
#include <shogun/base/SGObject.h>
namespace shogun
{
/** @brief Template Set class
*
* Lazy implementation of a set. Set grows and shrinks dynamically and can be
* conveniently iterated through via the [] operator.
*/
template <class T> class CSet : public CSGObject
{
public:
/** Default constructor */
CSet(bool traceable=true)
{
array = new DynArray<T>(1024, traceable);
}
/** Default destructor */
~CSet()
{
delete array;
}
/** Add an element to the set
*
* @param e elemet to be added
*/
inline void add(T e)
{
if (!contains(e))
array->append_element(e);
}
/** Remove an element from the set
*
* @param e element to be removed
*/
inline void remove(T e)
{
int32_t idx=array->find_element(e);
if (idx>=0)
array->delete_element(idx);
}
/** Remove an element from the set
*
* @param e element to be looked for
*/
inline bool contains(T e)
{
int32_t idx=array->find_element(e);
return (idx!=-1);
}
/** Index of element in the set
*
* @param e element to be removed
* @return index of the element or -1 if not found
*/
inline int32_t index_of(T e)
{
return array->find_element(e);
}
/** get number of elements
*
* @return number of elements
*/
inline int32_t get_num_elements() const
{
return array->get_num_elements();
}
/** get set element at index
*
* (does NOT do bounds checking)
*
* @param index index
* @return array element at index
*/
inline T get_element(int32_t index) const
{
return array->get_element(index);
}
/** get set element at index as reference
*
* (does NOT do bounds checking)
*
* @param index index
* @return array element at index
*/
inline T* get_element_ptr(int32_t index)
{
return array->get_element_ptr(index);
}
/** operator overload for set read only access
* use add() for write access
*
* DOES NOT DO ANY BOUNDS CHECKING
*
* @param index index
* @return element at index
*/
inline T operator[](int32_t index) const
{
return array->get_element(index);
}
/** @return underlying array in memory */
inline T* get_array()
{
return array->get_array();
}
/** @return object name */
inline virtual const char* get_name() const { return "Set"; }
protected:
/** dynamic array the set is based on */
DynArray<T>* array;
};
}
#endif //_SET_H_
|