18 #ifndef _DECAF_UTIL_CONCURRENT_COPYONWRITEARRAYSET_H_
19 #define _DECAF_UTIL_CONCURRENT_COPYONWRITEARRAYSET_H_
33 namespace concurrent {
48 template<
typename E >
60 this->
copy(collection);
64 for (
int i = 0; i <
size; ++i) {
65 this->array.addIfAbsent(array[i]);
75 this->array.copy(collection);
79 return this->array.iterator();
83 return this->array.iterator();
87 return this->array.size();
91 return this->array.isEmpty();
94 virtual bool add(
const E& value) {
95 return this->array.addIfAbsent(value);
99 return this->array.addAllAbsent(collection) > 0 ?
true :
false;
107 return this->array.contains(value);
111 return this->array.containsAll(collection);
114 virtual bool remove(
const E& value) {
115 return this->array.remove(value);
119 return this->array.removeAll(collection);
123 return this->array.retainAll(collection);
127 return this->array.toArray();
132 if ((
void*)
this == &collection) {
136 const Set<E>* asSet =
dynamic_cast<const Set<E>*
> (&collection);
141 if (this->
size() != asSet->
size()) {
145 std::auto_ptr<Iterator<E> > setIter(asSet->
iterator());
149 int length = array.size();
152 while (setIter->hasNext()) {
153 E value = setIter->next();
154 int matchedAt = array.indexOf(value);
155 if (matchedAt >= 0) {
156 matched[matchedAt] =
true;
160 for (
int i = 0; i < length; ++i) {
161 if (matched[i] ==
false) {