_nodeMarkBlue = 0; _faceSet = new FaceSet(256,0.25); _edgeSet = new EdgeSet(256,0.25); _nodeList = new NodeList(); _nmin = null;
EdgeSet edgeSet = new EdgeSet(16*countNodes(),0.5f); ArrayList<Edge> edgeList = new ArrayList<Edge>(8*countNodes()); NodeIterator inode = getNodes(); for (int inabor=0; inabor<nnabor; ++inabor) { Node nb = nabors[inabor]; if (edgeSet.add(na,nb,null,null)) { Tet tet = findTet(na,nb); Edge edge = new Edge(tet,na,nb); assert edgeSet.size()==0:"edges matched, size="+edgeSet.size(); edgeList.trimToSize(); _i = edgeList.iterator();
_edgeSet.clear(); for (boolean more=_faceSet.first(); more; more=_faceSet.next()) { Node a = _faceSet.a; Tet nabc = makeTet(node,a,b,c); linkTets(nabc,node,abcd,d); if (!_edgeSet.add(a,b,c,nabc)) linkTets(_edgeSet.nabc,_edgeSet.c,nabc,c); if (!_edgeSet.add(b,c,a,nabc)) linkTets(_edgeSet.nabc,_edgeSet.c,nabc,a); if (!_edgeSet.add(c,a,b,nabc)) linkTets(_edgeSet.nabc,_edgeSet.c,nabc,b);
/** * Removes the edge with specified index. */ private void remove(int i) { // Knuth, v. 3, 527, Algorithm R. --_n; for (;;) { _filled[i] = false; int j = i; int r; do { i = (i-1)&_mask; if (!_filled[i]) return; r = hash(_a[i],_b[i]); } while ((i<=r && r<j) || (r<j && j<i) || (j<i && i<=r)); _a[j] = _a[i]; _b[j] = _b[i]; _c[j] = _c[i]; _nabc[j] = _nabc[i]; _filled[j] = _filled[i]; } }
/** * Doubles the capacity of the set. */ private void doubleCapacity() { //trace("EdgeSet.doubleCapacity"); EdgeSet set = new EdgeSet(2*_nmax,_factor); if (_n>0) { for (int i=0; i<_nmax; ++i) { if (_filled[i]) set.add(_a[i],_b[i],_c[i],_nabc[i]); } } _a = set._a; _b = set._b; _c = set._c; _nabc = set._nabc; _filled = set._filled; _nmax = set._nmax; _n = set._n; _factor = set._factor; _shift = set._shift; _mask = set._mask; _index = set._index; } }
/** * If the set does not contain the mate of the specified edge, adds * the edge to the set, remembers the edge added, and returns true. * Otherwise, if the set already contains the mate, removes the mate * from the set, remembers the mate removed, and returns false. */ boolean add(Node a, Node b, Node c, Tet nabc) { _index = indexOfMate(a,b); if (_filled[_index]) { setCurrent(); remove(_index); return false; } else { _a[_index] = a; _b[_index] = b; _c[_index] = c; _nabc[_index] = nabc; _filled[_index] = true; ++_n; if (_n>_nmax*_factor && _nmax<MAX_CAPACITY) doubleCapacity(); setCurrent(); return true; } }
/** * Returns the index corresponding to the mate of the specified edge, * or, if the mate is not found, the index of an empty slot in the set. */ private int indexOfMate(Node a, Node b) { int i = hash(a,b); while (_filled[i]) { if (a==_b[i] && b==_a[i]) return i; i = (i-1)&_mask; } return i; }