tesuji.games.go
Class IntStack

java.lang.Object
  |
  +--tesuji.games.go.IntStack
All Implemented Interfaces:
FlyWeight

public class IntStack
extends java.lang.Object
implements FlyWeight

This class acts like a (usually small) list of integers. The only way to add items is through the 'push' method. But otherwise it acts just like an array of integers.

Creation date: (17-May-01 1:52:59 PM)

Product: Tesuji Software Go Library.

Copyright (c) 2001 Tesuji Software B.V.
All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, provided that the above copyright notice(s) and this permission notice appear in all copies of the Software and that both the above copyright notice(s) and this permission notice appear in supporting documentation.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of a Tesuji Software shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization of Tesuji Software.


Constructor Summary
IntStack()
          Default constructor.
IntStack(int size)
          IntStack constructor with a given capacity.
IntStack(java.util.Stack ownerStack)
          IntStack constructor.
 
Method Summary
 void add(IntStack otherStack)
           
 void clear()
          Clear the contents of the IntStack object.
 int get(int index)
           
 Cursor getIterator()
          Get a Cursor object that can be used to iterate over all the values in the IntStack.
 int[] getList()
           
 void getMembers(int startXY, byte[] board)
          This method clears the list and then starts to fill it with the coordinates of all the four-way-connected members of the same value in the board array.

For example this can be used to get the coordinates of all the stones that belong to the same chain.
 void getMoreMembers(int startXY, byte[] board)
          This method does the same as getMembers but it doesn't clear the list first, so the members get added to the existing members.
 int getSize()
           
 boolean isEmpty()
           
 int peek()
           
 int peek(int offset)
           
 int pop()
           
 void push(int value)
           
 void recycle()
           
 void remove(int value)
          Remove an item from the list.
 void setSize(int newSize)
          Setting the size of the number of items on the stack.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IntStack

public IntStack()
Default constructor. A GoArray is used so that we're sure the capacity is sufficient to store enough items to fill a board.

Creation date: (17-May-01 2:01:22 PM)


IntStack

public IntStack(int size)
IntStack constructor with a given capacity.

Creation date: (17-May-01 2:01:22 PM)


IntStack

public IntStack(java.util.Stack ownerStack)
IntStack constructor. The ownerStack is used so that the method 'recycle' can be used for deallocation.

Creation date: (17-May-01 2:01:22 PM)

Method Detail

push

public void push(int value)

pop

public int pop()

peek

public int peek()

peek

public int peek(int offset)

remove

public void remove(int value)
Remove an item from the list. This may cause the order of the items in the list to change, so don't use this method if the order of the items is important.

Creation date: (17-May-01 2:20:11 PM)


isEmpty

public boolean isEmpty()

getSize

public int getSize()

getMembers

public final void getMembers(int startXY,
                             byte[] board)
This method clears the list and then starts to fill it with the coordinates of all the four-way-connected members of the same value in the board array.

For example this can be used to get the coordinates of all the stones that belong to the same chain.

Creation date: (17-May-01 2:12:02 PM)


getIterator

public Cursor getIterator()
Get a Cursor object that can be used to iterate over all the values in the IntStack. Make sure to call 'recycle' when you're done with it for efficiency.

Creation date: (17-May-01 2:01:22 PM)


add

public void add(IntStack otherStack)

clear

public void clear()
Clear the contents of the IntStack object. It will now have size 0 and contain 0 items.

Creation date: (17-May-01 2:09:02 PM)


get

public final int get(int index)

getList

public final int[] getList()

getMoreMembers

public final void getMoreMembers(int startXY,
                                 byte[] board)
This method does the same as getMembers but it doesn't clear the list first, so the members get added to the existing members. It also doesn't clear the board-markers to prevent the same coordinates to be entered more than once. This implies that this method can only be used after getMembers has been used first.

Creation date: (17-May-01 2:12:02 PM)


recycle

public final void recycle()
Specified by:
recycle in interface FlyWeight

setSize

public void setSize(int newSize)
Setting the size of the number of items on the stack. Should only be used if the current size is greater than the new size and can be used to 'pop' more than one item. Use with care.

Creation date: (17-May-01 2:01:22 PM)