Skip to content

Commit 21b1826

Browse files
committed
Add HashSet and LinkedList Java collection stubs
1 parent 3d1c185 commit 21b1826

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

src/Processing.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3636,6 +3636,40 @@ class PShader {
36363636

36373637

36383638
template<typename K, typename V>
3639+
// Java collection stubs
3640+
template<class T>
3641+
class HashSet {
3642+
public:
3643+
::std::unordered_set<T> data;
3644+
bool add(const T& v) { return data.insert(v).second; }
3645+
bool remove(const T& v) { return data.erase(v)>0; }
3646+
bool contains(const T& v) const{ return data.count(v)>0; }
3647+
int size() const{ return (int)data.size(); }
3648+
bool isEmpty() const{ return data.empty(); }
3649+
void clear() { data.clear(); }
3650+
auto begin() { return data.begin(); }
3651+
auto end() { return data.end(); }
3652+
auto begin() const { return data.begin(); }
3653+
auto end() const { return data.end(); }
3654+
};
3655+
template<class T>
3656+
class LinkedList {
3657+
public:
3658+
::std::deque<T> data;
3659+
void add(const T& v) { data.push_back(v); }
3660+
void addFirst(const T& v) { data.push_front(v); }
3661+
void addLast(const T& v) { data.push_back(v); }
3662+
T removeFirst() { T v=data.front(); data.pop_front(); return v; }
3663+
T removeLast() { T v=data.back(); data.pop_back(); return v; }
3664+
T& getFirst() { return data.front(); }
3665+
T& getLast() { return data.back(); }
3666+
int size() const{ return (int)data.size(); }
3667+
bool isEmpty() const{ return data.empty(); }
3668+
void clear() { data.clear(); }
3669+
auto begin() { return data.begin(); }
3670+
auto end() { return data.end(); }
3671+
};
3672+
36393673
class HashMap {
36403674
public:
36413675
::std::map<K,V> data;

0 commit comments

Comments
 (0)