Hi, On the topic of markers, attached is what I did when a year back when I was still interested in Go....
I am not at all saying that this is the best way to do it (there is a bit of overhead), but it is a cute trick that should bring a smile or two. Joel On Thu, Oct 30, 2008 at 9:40 PM, Mark Boon <[EMAIL PROTECTED]> wrote: > > On 30-okt-08, at 00:20, Christoph Birk wrote: > >> On Wed, 29 Oct 2008, Mark Boon wrote: >>> >>> the implementation with one that clears the array instead of increasing >>> the marker. And I'll only have to make changes in one place instead of >>> dozens, or more. Not that I had this in mind when I designed it, it's just >>> the beneficial side-effect of OO design in general. >> >> [troll on] >> What's that todo with OO design? >> You can do the same by writing a function (eg. in 'C'). >> [troll off] >> > > Because then in C you have only one of them. It has everything to do with OO > design. > > Mark > > _______________________________________________ > computer-go mailing list > computer-go@computer-go.org > http://www.computer-go.org/mailman/listinfo/computer-go/ >
#ifndef __POINTSET_HPP__ #define __POINTSET_HPP__ #include "goanna.hpp" /* Bounded Range Unique Integer Storage Entity M is the maximum number of elements in the container [0,N-1] is the range of values that the container can hold O(1) exists O(1) insert O(1) delete O(1) initialise using only O(N + M) memory. */ template<unsigned int N, unsigned int M> class Bruise { public: // construct an empty container Bruise<N, M>(void) : m_element_c(0) { } // copy constructor that only copies the necessary parts Bruise<N, M>(const Bruise<N, M> ©) { assignFrom(copy); } // assignment operator that only copies necessary parts Bruise<N, M> &operator=(const Bruise<N, M> &rhs) { if (this == &rhs) return *this; assignFrom(rhs); return *this; } // retrieve an item from the container bool exists(unsigned int n) const { if (n >= N) return false; return m_hash[n] < m_element_c && n == m_element[m_hash[n]]; } // insert an item into container, false on failure bool insert(unsigned int n) { if (m_element_c >= M) return false; if (exists(n)) return false; m_hash[n] = m_element_c; m_element[m_element_c++] = n; return true; } // remove an item from the container, false on failure bool remove(unsigned int n) { if (!exists(n)) return false; m_element[m_hash[n]] = m_element[m_element_c-1]; m_hash[m_element[m_element_c-1]] = m_hash[n]; m_element_c--; return true; } // grab the n'th element with no bounds checking unsigned int operator[](size_t n) const { return m_element[n]; } // determine the size of the container size_t size(void) const { return m_element_c; } // reset the point set void clear(void) { m_element_c = 0; } private: // fast copying for sparsely populated pointsets void assignFrom(const Bruise<N,M> ©) { m_element_c = copy.m_element_c; for (uint i=0; i < m_element_c; i++) { unsigned int elem = copy.m_element[i]; m_element[i] = elem; m_hash[elem] = i; } } unsigned int m_element_c; unsigned int m_element[M]; unsigned int m_hash[N]; }; typedef Bruise<MAX_POINTS, MAX_POINTS> PointSet; #endif // __POINTSET_HPP__
_______________________________________________ computer-go mailing list computer-go@computer-go.org http://www.computer-go.org/mailman/listinfo/computer-go/