C++ API Reference for Intel® Data Analytics Acceleration Library 2020 Update 1

indices_impl.h
1 /* file: indices_impl.h */
2 /*******************************************************************************
3 * Copyright 2014-2020 Intel Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *******************************************************************************/
17 
18 #ifndef __DATA_MANAGEMENT_FEATURES_INTERNAL_INDICES_IMPL_H__
19 #define __DATA_MANAGEMENT_FEATURES_INTERNAL_INDICES_IMPL_H__
20 
21 #include <map>
22 #include <string>
23 
24 #include "services/collection.h"
25 #include "services/internal/utilities.h"
26 #include "services/internal/error_handling_helpers.h"
27 
28 #include "data_management/features/indices.h"
29 
30 namespace daal
31 {
32 namespace data_management
33 {
34 namespace features
35 {
36 namespace internal
37 {
38 
43 class FeatureIndicesList : public FeatureIndices
44 {
45 public:
46  static services::SharedPtr<FeatureIndicesList> create(services::Status *status = NULL)
47  {
48  return services::internal::wrapSharedAndTryThrow<FeatureIndicesList>(new FeatureIndicesList(), status);
49  }
50 
51  virtual size_t size() const DAAL_C11_OVERRIDE
52  {
53  return _indices.size();
54  }
55 
56  virtual bool isPlainRange() const DAAL_C11_OVERRIDE
57  {
58  return false;
59  }
60 
61  virtual bool areRawFeatureIndicesAvailable() const DAAL_C11_OVERRIDE
62  {
63  return true;
64  }
65 
66  virtual FeatureIndex getFirst() const DAAL_C11_OVERRIDE
67  {
68  if (!size()) { return FeatureIndexTraits::invalid(); }
69  return _indices[0];
70  }
71 
72  virtual FeatureIndex getLast() const DAAL_C11_OVERRIDE
73  {
74  if (!size()) { return FeatureIndexTraits::invalid(); }
75  return _indices[_indices.size() - 1];
76  }
77 
78  virtual services::BufferView<FeatureIndex> getRawFeatureIndices() DAAL_C11_OVERRIDE
79  {
80  return services::BufferView<FeatureIndex>(_indices.data(), _indices.size());
81  }
82 
83  services::Status add(FeatureIndex index)
84  {
85  if (index > FeatureIndexTraits::maxIndex() || index == FeatureIndexTraits::invalid())
86  {
87  return services::throwIfPossible(services::ErrorIncorrectDataRange);
88  }
89 
90  if ( !_indices.safe_push_back(index) )
91  {
92  return services::throwIfPossible(services::ErrorMemoryAllocationFailed);
93  }
94 
95  return services::Status();
96  }
97 
98 private:
99  FeatureIndicesList() { }
100 
101  services::Collection<FeatureIndex> _indices;
102 };
103 typedef services::SharedPtr<FeatureIndicesList> FeatureIndicesListPtr;
104 
109 class FeatureIndicesRange : public FeatureIndices
110 {
111 public:
112  static services::SharedPtr<FeatureIndicesRange> create(FeatureIndex begin, FeatureIndex end,
113  services::Status *status = NULL)
114  {
115  if (begin == FeatureIndexTraits::invalid() ||
116  end == FeatureIndexTraits::invalid())
117  {
118  services::internal::tryAssignStatusAndThrow(status, services::ErrorIncorrectIndex);
119  return services::SharedPtr<FeatureIndicesRange>();
120  }
121  return services::internal::wrapSharedAndTryThrow<FeatureIndicesRange>(
122  new FeatureIndicesRange(begin, end), status);
123  }
124 
125  virtual size_t size() const DAAL_C11_OVERRIDE
126  {
127  return services::internal::maxValue(_begin, _end) -
128  services::internal::minValue(_begin, _end) + 1;
129  }
130 
131  virtual bool isPlainRange() const DAAL_C11_OVERRIDE
132  {
133  return true;
134  }
135 
136  virtual bool areRawFeatureIndicesAvailable() const DAAL_C11_OVERRIDE
137  {
138  return false;
139  }
140 
141  virtual FeatureIndex getFirst() const DAAL_C11_OVERRIDE
142  {
143  return _begin;
144  }
145 
146  virtual FeatureIndex getLast() const DAAL_C11_OVERRIDE
147  {
148  return _end;
149  }
150 
151  virtual services::BufferView<FeatureIndex> getRawFeatureIndices() DAAL_C11_OVERRIDE
152  {
153  return services::BufferView<FeatureIndex>();
154  }
155 
156 private:
157  explicit FeatureIndicesRange(FeatureIndex begin, FeatureIndex end) :
158  _begin(begin),
159  _end(end) { }
160 
161  FeatureIndex _begin;
162  FeatureIndex _end;
163 };
164 typedef services::SharedPtr<FeatureIndicesList> FeatureIndicesListPtr;
165 
166 } // namespace internal
167 } // namespace features
168 } // namespace data_management
169 } // namespace daal
170 
171 #endif
daal::data_management::features::internal::FeatureIndicesRange
Implementation of FeatureIndices to store a range of feature indices.
Definition: indices_impl.h:109
daal::services::ErrorIncorrectIndex
Definition: error_indexes.h:102
daal::services::ErrorIncorrectDataRange
Definition: error_indexes.h:79
daal::services::ErrorMemoryAllocationFailed
Definition: error_indexes.h:150
daal::data_management::features::internal::FeatureIndicesList
Implementation of FeatureIndices to store a list of feature indices.
Definition: indices_impl.h:43

For more complete information about compiler optimizations, see our Optimization Notice.