General Library Map template class

Source: Internet
Author: User

/// Map template class of the general library
/**
* General Library version 4.0 <br>
* This is a ing class that provides basic Map functions. This ing is based on dynamic ordered arrays. Binary Search is used for searching. <br>
* Main methods include operator [], getValue (), getKey (), operator =, getLength (), RemoveByKey (), RemoveByIndex (), Clear (), Contains () and other methods <br>
* In addition, some methods such as getCapaity (), getFirstIndex (), and getLastIndex () are introduced.
* This Map defines the internal Entry struct: SEntry
* @ Author zdhsoft (Zhu Donghua)
* @ Version 4.0
* @ Date 2008-04-01
* @ File xmap. h
*/
# Ifndef _ X_MAP_H _
# Define _ X_MAP_H _
# Include <xarray. h>
Namespace zdh
{
Template <class K, class V>
Class XMap
{
/// Entries in Map
Struct SEntry
{
SEntry (const K & aKey)
: Key (aKey)
{}
SEntry (const K & aKey, const V & aValue)
: Key (aKey), Value (aValue)
{}
SEntry (const SEntry & aEntry)
: Key (aEntry. Key), Value (aEntry. Value)
{}
K Key;
V Value;
};
Public:
/// Default constructor
XMap (){}
/// Default copy constructor
XMap (const XMap <K, V> & aMap );
/// Default destructor
~ XMap () {Clear ();}
/// Clear all elements
Void Clear (bool bFree = false );
/// Determine the map capacity
Void ensureCapacity (XInt aMinimumCapacity) {m_Data.ensureCapacity (aMinimumCapacity );}
/// Number of map elements
XInt getLength () const {return m_Data.getLength ();}
//! Map capacity
XInt getCapacity () const {return m_Data.getCapacity ();}
/// Maximum map capacity
XInt getMaxCapacity () const {return 0x7FFFFFF0/sizeof (SEntry );}
/// Obtain the first subscript
XInt getFirstIndex () const {return m_Data.getFirstIndex ();}
/// Obtain the last subscript
XInt getLastIndex () const {return m_Data.getLastIndex ();}
/// Determine whether it is the first subscript
Bool isFirstInde

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.