/*!
  @header FTOrderedReferenceSetImpl
  @abstract Module of FT
 
  @availability OS X, GNUstep
  @copyright 2004, 2005, 2006 Free Software Foundation, Inc.
  
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA

  <pre>
  -------------------------------------------------------------------------
  Modification history

  11.09.05 ola     initial version
  23.08.06 ola     license changed
  -------------------------------------------------------------------------
  </pre>
*/

#if !defined(__FTOrderedReferenceSetImpl_H)
#define __FTOrderedReferenceSetImpl_H

#include <Foundation/Foundation.h>
#include <Encore/Encore.h>
#include <FT/FT.h>
#include <FT/FTOrderedReferenceSet.h>
#include <FT/FTReferenceImpl.h>

/*!
 * @class FTOrderedReferenceSetImpl
 * @abstract Used to manage an ordered set of references.

 */
@interface FTOrderedReferenceSetImpl : FTObject <FTOrderedReferenceSet> {
  @private
    /**
     * baseNode identifies the node for which this set is being defined
     */
    id <FTId> baseNodeId;
    
    
    /**
     * Array of all references as instances of FTReferenceImpl
     */
    NSMutableArray *references;
    
    
    /**
     * Maps a node id to an array of NSNUmber instances which refer to the
     * related entry of "references".
     * transient entry
     */
    NSMutableDictionary *nodeIdToIndexArray;
    
    
    /**
     * Maps an edge id to an NSNumber instance representing an entry within
     *   references
     * Transient entry
     */
    NSMutableDictionary *edgeIdToIndex;
}


/*!
 * @method initForBaseNode
 * @abstract Initializes this set based on a given base node
 * @param aNode node for which this set is being used
 * @result
 */
- initForBaseNode: (id <FTNode>) aNode;


/**
 * @method initWithCoder
 */
- (id) initWithCoder:(NSCoder *) decoder;


- (void) dealloc;


/*!
 * @method allReferences
 * @result all references in order
 */
- (id <ECIterator>) allReferences;


/*!
 * @method countReferences
 * @result returns the number of references in this set
 */
- (unsigned) countReferences;


/*!
 * @method createAndAppendReferenceToNode
 * @abstract creates a reference and appends it to the existing set
 * @param aNodeId identifier of the node to point to
 * @param anEdgeId identifier for the underlying edge
 * @result self
 * @throws ECIllegalArgumentException if the given reference already exists in
 *   this set.
 */
- createAndAppendReferenceToNode: (id <FTId>) aNodeId
  withEdgeId: (id <FTId>) anEdgeId;


/*!
 * @method createIndexes
 * @abstract used to initialize all internal maps
 * @discussion is an internal method
 * result self
 */
- createIndexes;


/*!
 * @method encodeWithCoder
 */ 
- (void) encodeWithCoder:(NSCoder *) encoder;


/*!
 * @method hash
 */
- (unsigned) hash;


/*!
 * @method isEqual
 */
- (BOOL) isEqual: (id) anObject;


/*!
 * @method referencesByNodeId
 * @param aNodeId node id to look for
 * @result all references having the specified node id
 */
- (id <ECIterator>) referencesByNodeId: (id <FTId>) aNodeId;


/*!
 * @method referenceByEdgeId
 * @param anEdgeId identifier for the edge
 * @result the reference corresponding to the given edge id or nil
 */
- (id <FTReference>) referenceByEdgeId: (id <FTId>) anEdgeId;


/*!
 * @method removeReference
 * @abstract removes a reference from the set
 * @discussion After a successful call the reference is no longer valid.
 * @param toRemove reference to remove.
 * @result self
 */
- removeReference: (id <FTReference>) toRemove;


/*!
 * @method updateIndex
 * @abstract update internal indexes used for searches
 * @param indexOfNewEntry index where the new entry has been added to and to
 *   which all index values have to point to
 * @param aReference new reference
 * @result self
 */
- updateIndexes: (NSNumber *) indexOfNewEntry 
  forReference: (FTReferenceImpl *) aReference;

@end
#endif
