Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Disconnect
- /** Disconnect me from my current successor, if any. */
- void disconnect() {
- Sq next = _successor;
- if (next == null) {
- return;
- }
- _unconnected += 1; // increase number of squares that haven't been connected
- next._predecessor = _successor = null;
- if (_sequenceNum == 0) {
- // FIXME: If both this and next are now one-element groups,
- // release their former group and set both group
- // numbers to -1.
- // Otherwise, if either is now a one-element group, set
- // its group number to -1 without releasing the group
- // number.
- // Otherwise, the group has been split into two multi-
- // element groups. Create a new group for next.
- if ((this._predecessor == null) && (next._successor == null)) { // Cond 1
- releaseGroup(this._head._group);
- this._head._group = -1;
- next._head._group = -1;
- }
- else if ((this._predecessor == null) || (next._successor == null)) { // Cond 2
- if ((this._predecessor == null))
- this._head._group = -1;
- else
- next._head._group = -1;
- }
- else {
- next._head._group = newGroup();
- }
- } else {
- // FIXME: If neither this nor any square in its group that
- // precedes it has a fixed sequence number, set all
- // their sequence numbers to 0 and create a new group
- // for them if this has a current predecessor (other
- // set group to -1).
- // FIXME: If neither next nor any square in its group that
- // follows it has a fixed sequence number, set all
- // their sequence numbers to 0 and create a new
- // group for them if next has a current successor
- // (otherwise set next's group to -1.)
- boolean noFixedNums = this._hasFixedNum;
- Sq predecessorPtr = this._predecessor;
- while (predecessorPtr != null) {
- boolean tempBool = false;
- if (!(predecessorPtr._hasFixedNum))
- tempBool = true;
- noFixedNums = (noFixedNums && tempBool);
- predecessorPtr = predecessorPtr._predecessor;
- }
- if (noFixedNums) { // condition #1
- this._sequenceNum = 0;
- Sq predecessorPtr2 = this._predecessor;
- while (predecessorPtr2 != null) {
- predecessorPtr2._sequenceNum = 0;
- predecessorPtr2 = predecessorPtr2._predecessor;
- }
- if (this._predecessor != null) {
- this._head._group = newGroup();
- }
- else {
- this._head._group = -1;
- }
- }
- boolean noFixedNums2 = next._hasFixedNum;
- Sq successorPtr = next._successor;
- while (successorPtr != null) {
- boolean tempBool = false;
- if (!(successorPtr._hasFixedNum))
- tempBool = true;
- noFixedNums2 = (noFixedNums2 && tempBool);
- successorPtr = successorPtr._successor;
- }
- if (noFixedNums2) { // condition #2
- next._sequenceNum = 0;
- Sq successorPtr2 = next._successor;
- while (successorPtr2 != null) {
- successorPtr2._sequenceNum = 0;
- successorPtr2 = successorPtr2._successor;
- }
- if (next._successor != null) {
- next._head._group = newGroup();
- }
- else {
- next._head._group = -1;
- }
- }
- }
- // FIXME: Set the _head of next and all squares in its group to
- // next.
- next._head = next;
- Sq successorPtr = next._successor;
- while (successorPtr != null) {
- successorPtr._head = next;
- successorPtr = successorPtr._successor;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement