NTrace
GPU ray tracing framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
UnionFind.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009-2011, NVIDIA Corporation
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of NVIDIA Corporation nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #pragma once
29 #include "base/Array.hpp"
30 
31 namespace FW
32 {
33 //------------------------------------------------------------------------
34 
35 class UnionFind
36 {
37 public:
38  explicit UnionFind (int capacity = 0) { setCapacity(capacity); }
39  UnionFind (const UnionFind& other) { set(other); }
40  ~UnionFind (void) {}
41 
42  int unionSets (int idxA, int idxB);
43  int findSet (int idx) const;
44  bool isSameSet (int idxA, int idxB) const { return (findSet(idxA) == findSet(idxB)); }
45 
46  void clear (void) { m_sets.clear(); }
47  void reset (void) { m_sets.reset(); }
48  void setCapacity (int capacity) { m_sets.setCapacity(capacity); }
49  void set (const UnionFind& other) { m_sets = other.m_sets; }
50 
51  UnionFind& operator= (const UnionFind& other) { set(other); return *this; }
52  int operator[] (int idx) const { return findSet(idx); }
53 
54 private:
55  mutable Array<S32> m_sets;
56 };
57 
58 //------------------------------------------------------------------------
59 }
void set(const UnionFind &other)
Definition: UnionFind.hpp:49
UnionFind(int capacity=0)
Definition: UnionFind.hpp:38
UnionFind & operator=(const UnionFind &other)
Definition: UnionFind.hpp:51
~UnionFind(void)
Definition: UnionFind.hpp:40
void clear(void)
Definition: Array.hpp:359
bool isSameSet(int idxA, int idxB) const
Definition: UnionFind.hpp:44
void reset(S size=0)
Definition: Array.hpp:317
void setCapacity(int capacity)
Definition: UnionFind.hpp:48
void reset(void)
Definition: UnionFind.hpp:47
void setCapacity(S numElements)
Definition: Array.hpp:326
UnionFind(const UnionFind &other)
Definition: UnionFind.hpp:39
void clear(void)
Definition: UnionFind.hpp:46
int findSet(int idx) const
Definition: UnionFind.cpp:57
int unionSets(int idxA, int idxB)
Definition: UnionFind.cpp:34
int operator[](int idx) const
Definition: UnionFind.hpp:52