// IBM Open Class Library
//
// Licensed Materials - Property of IBM
//
// (C) Copyright IBM Corporation, 1992, 1997 All Rights Reserved
//
// Revision: 26 1.5.3.2 source/core/collect/iikssavl.c, collection, ioc.v400, 001006 
#ifndef _IIKSSAVL_C_
#define _IIKSSAVL_C_

#include <new.h>


#pragma info (nocls, nocnd, nocns, nocnv, noext, nognr, novft)


#ifdef IC_BUILD
#define __IOC_INLINE
#else
#define __IOC_INLINE inline
#endif

// -------------------------
// IKeySortedSetAsAvlTreeOps
// -------------------------

// public members

template <class Element, class Key,
          class ElementOps, class Implementation>
__IOC_INLINE
IKeySortedSetAsAvlTreeOps <Element, Key, ElementOps, Implementation>::
IKeySortedSetAsAvlTreeOps (INumber numberOfElements)
: Inherited (__isDTSClass (Element)),
  ivElementOps (),
  ivImpl (*this, numberOfElements)
{
}

template <class Element, class Key,
          class ElementOps, class Implementation>
__IOC_INLINE
IKeySortedSetAsAvlTreeOps <Element, Key, ElementOps, Implementation>::
IKeySortedSetAsAvlTreeOps (INumber numberOfElements, void* opsArg)
: Inherited (__isDTSClass (Element)),
  ivElementOps (opsArg),
  ivImpl (*this, numberOfElements)
{
}

template <class Element, class _Key,
          class ElementOps, class Implementation>
__IOC_INLINE
IKeySortedSetAsAvlTreeOps <Element, _Key, ElementOps, Implementation>::
IKeySortedSetAsAvlTreeOps
  (IKeySortedSetAsAvlTreeOps
    <Element, _Key, ElementOps, Implementation> const& collection)
: Inherited (__isDTSClass (Element)),
  ivElementOps (collection.ivElementOps),
  ivImpl (*this, collection.ivImpl)
{
}

template <class Element, class Key,
          class ElementOps, class Implementation>
__IOC_INLINE
IKeySortedSetAsAvlTreeOps <Element, Key, ElementOps, Implementation>::
~IKeySortedSetAsAvlTreeOps ()
{
}

template <class Element, class Key,
          class ElementOps, class Implementation>
__IOC_INLINE
void
IKeySortedSetAsAvlTreeOps <Element, Key, ElementOps, Implementation>::
Assign (void* element1, void const* element2) const
{ ivElementOps.Assign (*(Element*)element1, *(Element const*)element2);
}

template <class Element, class Key,
          class ElementOps, class Implementation>
__IOC_INLINE
IACollectionImpl*
IKeySortedSetAsAvlTreeOps <Element, Key, ElementOps, Implementation>::
Clone () const
{ return (Implementation*) *new Self (*this);
}

template <class Element, class _Key,
          class ElementOps, class Implementation>
__IOC_INLINE
long
IKeySortedSetAsAvlTreeOps <Element, _Key, ElementOps, Implementation>::
CompareKeys (void const* arg1, void const* arg2, IArgType argType) const
{ long comp = 0;
  switch (argType) {
    case kElementElement: {
      comp = ivElementOps.keyOps.Compare
        (ivElementOps.Key (*(Element const*)arg1),
         ivElementOps.Key (*(Element const*)arg2));
      break;
    }
    case kElementKey: {
      comp = ivElementOps.keyOps.Compare
        (ivElementOps.Key (*(Element const*)arg1),
         IKeyForOps ((_Key const*)arg2));
      break;
    }
    case kKeyKey: {
      comp = ivElementOps.keyOps.Compare
        (IKeyForOps ((_Key const*)arg1), IKeyForOps ((_Key const*)arg2));
    }
  }
  return comp;
}

template <class Element, class Key,
          class ElementOps, class Implementation>
__IOC_INLINE
void*
IKeySortedSetAsAvlTreeOps <Element, Key, ElementOps, Implementation>::
CreateNode (void const* element) const
{ void* node = ivElementOps.Allocate (sizeof (Node)

#if defined (__DEBUG_ALLOC__)
                                      ,__FILE__, __LINE__
#endif




                                     );
  return new (ivImpl.CheckPointer (node))
    Node (*(Element const*)element);
}

#if ! defined (__INO_STREAMING__)
template <class Element, class Key,
          class ElementOps, class Implementation>
__IOC_INLINE
void*
IKeySortedSetAsAvlTreeOps <Element, Key, ElementOps, Implementation>::
CreateNodeWithStreamer(IACollectionStreamer *streamer,
                       IDataStream& fromWhere) const
{ void* node = ivElementOps.Allocate (sizeof (Node)

#if defined (__DEBUG_ALLOC__)
                                      ,__FILE__, __LINE__
#endif

                                     );
  ivImpl.CheckPointer (node);
  ((Node*)node)->StreamIn (streamer, fromWhere);
  return node;
}
#endif

template <class Element, class Key,
          class ElementOps, class Implementation>
__IOC_INLINE
void
IKeySortedSetAsAvlTreeOps <Element, Key, ElementOps, Implementation>::
DeleteNode (void* node) const
{ ((Node*)node)->~Node ();
  ivElementOps.Deallocate (node

#if defined (__DEBUG_ALLOC__)
                           , __FILE__, __LINE__
#endif

                          );
}

template <class Element, class _Key,
          class ElementOps, class Implementation>
__IOC_INLINE
void*
IKeySortedSetAsAvlTreeOps <Element, _Key, ElementOps, Implementation>::
Key (void const* element) const
{ return IKeyFromOps
    (ivElementOps.Key (*(Element const*)element));
}

template <class Element, class Key,
          class ElementOps, class Implementation>
__IOC_INLINE
IKeySortedSetAsAvlTreeOps <Element, Key, ElementOps, Implementation>::
operator Implementation* ()
{ ivImpl.CheckPointer (this);
  return &ivImpl;
}


#pragma info (restore)


#endif // _IIKSSAVL_C_
