NAMD
UniqueSortedArray.h
Go to the documentation of this file.
1 
7 #ifndef USRTARRAY_H
8 #define USRTARRAY_H
9 
10 #include "SortedArray.h"
11 
12 template <class Elem> class UniqueSortedArray : public SortedArray<Elem> {
13 
14  public:
15 
16  UniqueSortedArray(int s=0) : SortedArray<Elem>(s) { }
17 
19  SortedArray<Elem>(ua) { }
20 
22  this->uniq();
23  }
24 
25 /*
26  UniqueSortedArray(ResizeArray<Elem> &ra) : SortedArray<Elem>(ra) {
27  this->uniq();
28  }
29 */
30 
33  return(*this);
34  }
35 
38  this->uniq();
39  return(*this);
40  }
41 
42 /*
43  UniqueSortedArray<Elem>& operator =(ResizeArray<Elem> &ra) {
44  SortedArray<Elem>::operator=(ra);
45  this->uniq();
46  return(*this);
47  }
48 */
49 
50  int add(const Elem& elem) { return(insert(elem)); }
51 
52  inline int insert(const Elem& elem);
53 
54 };
55 
56 template <class Elem>
57 inline int
59  int found = this->bsearch(elem);
60  if (found == -1) {
61  return ResizeArray<Elem>::insert(elem, 0);
62  }
63  if (found < this->size() && this->rep[found] == elem) {
64  return -2;
65  }
66  if (found == (this->size()-1) && this->rep[found] < elem) {
67  return ResizeArray<Elem>::insert(elem, this->size());
68  } else {
69  return ResizeArray<Elem>::insert(elem, found);
70  }
71 }
72 #endif
UniqueSortedArray(UniqueSortedArray< Elem > &ua)
int insert(const Elem &elem, int index)
Definition: ResizeArray.h:109
int insert(const Elem &elem)
UniqueSortedArray< Elem > & operator=(UniqueSortedArray< Elem > &ua)
SortedArray< Elem > & operator=(SortedArray< Elem > &sa)
Definition: SortedArray.h:38
UniqueSortedArray(SortedArray< Elem > &sa)
int add(const Elem &elem)