algorithm [...]: Update to SGI STL 3.11.

* algorithm alloc.h defalloc.h hash_map.h hash_set.h iterator
	memory pthread_alloc pthread_alloc.h rope ropeimpl.h stl_algo.h
	stl_algobase.h stl_alloc.h stl_bvector.h stl_config.h
	stl_construct.h stl_deque.h stl_function.h stl_hash_fun.h
	stl_hash_map.h stl_hash_set.h stl_hashtable.h stl_heap.h
	stl_iterator.h stl_list.h stl_map.h stl_multimap.h stl_multiset.h
	stl_numeric.h stl_pair.h stl_queue.h stl_raw_storage_iter.h
	stl_relops.h stl_rope.h stl_set.h stl_slist.h stl_stack.h
	stl_tempbuf.h stl_tree.h stl_uninitialized.h stl_vector.h
	tempbuf.h type_traits.h: Update to SGI STL 3.11.

From-SVN: r22190
This commit is contained in:
Jason Merrill 1998-09-02 17:25:15 +00:00 committed by Jason Merrill
parent 514a1f18ee
commit df9262681b
45 changed files with 14929 additions and 11189 deletions

View File

@ -1,3 +1,16 @@
1998-09-02 Jason Merrill <jason@yorick.cygnus.com>
* algorithm alloc.h defalloc.h hash_map.h hash_set.h iterator
memory pthread_alloc pthread_alloc.h rope ropeimpl.h stl_algo.h
stl_algobase.h stl_alloc.h stl_bvector.h stl_config.h
stl_construct.h stl_deque.h stl_function.h stl_hash_fun.h
stl_hash_map.h stl_hash_set.h stl_hashtable.h stl_heap.h
stl_iterator.h stl_list.h stl_map.h stl_multimap.h stl_multiset.h
stl_numeric.h stl_pair.h stl_queue.h stl_raw_storage_iter.h
stl_relops.h stl_rope.h stl_set.h stl_slist.h stl_stack.h
stl_tempbuf.h stl_tree.h stl_uninitialized.h stl_vector.h
tempbuf.h type_traits.h: Update to SGI STL 3.11.
Fri Jul 10 15:20:09 1998 Klaus-Georg Adams <Klaus-Georg.Adams@chemie.uni-karlsruhe.de>
* stl_tempbuf.h (temporary_buffer): Add missing typename.

View File

@ -29,6 +29,7 @@
#include <stl_algobase.h>
#include <stl_construct.h>
#include <stl_uninitialized.h>
#include <stl_tempbuf.h>
#include <stl_algo.h>

View File

@ -33,7 +33,9 @@ using __STD::single_client_alloc;
#ifdef __STL_STATIC_TEMPLATE_MEMBER_BUG
using __STD::__malloc_alloc_oom_handler;
#endif /* __STL_STATIC_TEMPLATE_MEMBER_BUG */
#ifdef __STL_USE_STD_ALLOCATORS
using __STD::allocator;
#endif /* __STL_USE_STD_ALLOCATORS */
#endif /* __STL_USE_NAMESPACES */

View File

@ -15,12 +15,13 @@
// Inclusion of this file is DEPRECATED. This is the original HP
// default allocator. It is provided only for backward compatibility.
//
// This file WILL BE REMOVED in a future release.
//
// DO NOT USE THIS FILE unless you have an old container implementation
// that requires an allocator with the HP-style interface. SGI STL
// uses a different allocator interface. SGI-style allocators are not
// parametrized with respect to the object type; they traffic in void *
// pointers. This file is not included by any other SGI STL header.
// that requires an allocator with the HP-style interface.
//
// Standard-conforming allocators have a very different interface. The
// standard default allocator is declared in the header <memory>.
#ifndef DEFALLOC_H
#define DEFALLOC_H

View File

@ -31,6 +31,7 @@
#include <stl_hashtable.h>
#endif
#include <algobase.h>
#include <stl_hash_map.h>
#ifdef __STL_USE_NAMESPACES

View File

@ -31,6 +31,7 @@
#include <stl_hashtable.h>
#endif
#include <algobase.h>
#include <stl_hash_set.h>
#ifdef __STL_USE_NAMESPACES

View File

@ -29,8 +29,12 @@
#include <stl_config.h>
#include <stl_relops.h>
#include <stddef.h>
#include <stddef.h> /* XXX should use <cstddef> */
#if 0 /* XXX define a flag for this */
#include <iostream>
#else
#include <iostream.h>
#endif
#include <stl_iterator.h>
#endif /* __SGI_STL_ITERATOR */

View File

@ -22,64 +22,83 @@
#include <stl_uninitialized.h>
#include <stl_raw_storage_iter.h>
// Note: auto_ptr is commented out in this release because the details
// of the interface are still being discussed by the C++ standardization
// committee. It will be included once the iterface is finalized.
#if 0
#if defined(_MUTABLE_IS_KEYWORD) && defined(_EXPLICIT_IS_KEYWORD) && \
defined(__STL_MEMBER_TEMPLATES)
#if defined(__STL_MEMBER_TEMPLATES)
__STL_BEGIN_NAMESPACE
template <class X> class auto_ptr {
template <class _Tp> class auto_ptr {
private:
X* ptr;
mutable bool owns;
_Tp* _M_ptr;
public:
typedef X element_type;
explicit auto_ptr(X* p = 0) __STL_NOTHROW : ptr(p), owns(p) {}
auto_ptr(const auto_ptr& a) __STL_NOTHROW : ptr(a.ptr), owns(a.owns) {
a.owns = 0;
typedef _Tp element_type;
explicit auto_ptr(_Tp* __p = 0) __STL_NOTHROW : _M_ptr(__p) {}
auto_ptr(auto_ptr& __a) __STL_NOTHROW : _M_ptr(__a.release()) {}
template <class _Tp1> auto_ptr(auto_ptr<_Tp1>& __a) __STL_NOTHROW
: _M_ptr(__a.release()) {}
auto_ptr& operator=(auto_ptr& __a) __STL_NOTHROW {
if (&__a != this) {
delete _M_ptr;
_M_ptr = __a.release();
}
return *this;
}
template <class T> auto_ptr(const auto_ptr<T>& a) __STL_NOTHROW
: ptr(a.ptr), owns(a.owns) {
a.owns = 0;
template <class _Tp1>
auto_ptr& operator=(auto_ptr<_Tp1>& __a) __STL_NOTHROW {
if (__a.get() != this->get()) {
delete _M_ptr;
_M_ptr = __a.release();
}
return *this;
}
~auto_ptr() __STL_NOTHROW { delete _M_ptr; }
_Tp& operator*() const __STL_NOTHROW {
return *_M_ptr;
}
_Tp* operator->() const __STL_NOTHROW {
return _M_ptr;
}
_Tp* get() const __STL_NOTHROW {
return _M_ptr;
}
_Tp* release() __STL_NOTHROW {
_Tp* __tmp = _M_ptr;
_M_ptr = 0;
return __tmp;
}
void reset(_Tp* __p = 0) __STL_NOTHROW {
delete _M_ptr;
_M_ptr = __p;
}
auto_ptr& operator=(const auto_ptr& a) __STL_NOTHROW {
if (&a != this) {
if (owns)
delete ptr;
owns = a.owns;
ptr = a.ptr;
a.owns = 0;
}
}
template <class T> auto_ptr& operator=(const auto_ptr<T>& a) __STL_NOTHROW {
if (&a != this) {
if (owns)
delete ptr;
owns = a.owns;
ptr = a.ptr;
a.owns = 0;
}
}
~auto_ptr() {
if (owns)
delete ptr;
}
// According to the C++ standard, these conversions are required. Most
// present-day compilers, however, do not enforce that requirement---and,
// in fact, most present-day compilers do not support the language
// features that these conversions rely on.
#ifdef __SGI_STL_USE_AUTO_PTR_CONVERSIONS
X& operator*() const __STL_NOTHROW { return *ptr; }
X* operator->() const __STL_NOTHROW { return ptr; }
X* get() const __STL_NOTHROW { return ptr; }
X* release const __STL_NOTHROW { owns = false; return ptr }
private:
template<class _Tp1> struct auto_ptr_ref {
_Tp1* _M_ptr;
auto_ptr_ref(_Tp1* __p) : _M_ptr(__p) {}
};
public:
auto_ptr(auto_ptr_ref<_Tp> __ref) __STL_NOTHROW
: _M_ptr(__ref._M_ptr) {}
template <class _Tp1> operator auto_ptr_ref<_Tp1>() __STL_NOTHROW
{ return auto_ptr_ref<_Tp>(this.release()); }
template <class _Tp1> operator auto_ptr<_Tp1>() __STL_NOTHROW
{ return auto_ptr<_Tp1>(this->release()) }
#endif /* __SGI_STL_USE_AUTO_PTR_CONVERSIONS */
};
__STL_END_NAMESPACE
#endif /* mutable && explicit && member templates */
#endif /* 0 */
#endif /* member templates */
#endif /* __SGI_STL_MEMORY */

View File

@ -20,7 +20,7 @@
// This should be reasonably fast even in the presence of threads.
// The down side is that storage may not be well-utilized.
// It is not an error to allocate memory in thread A and deallocate
// it n thread B. But this effectively transfers ownership of the memory,
// it in thread B. But this effectively transfers ownership of the memory,
// so that it can only be reallocated by thread B. Thus this can effectively
// result in a storage leak if it's done on a regular basis.
// It can also result in frequent sharing of
@ -35,308 +35,440 @@
__STL_BEGIN_NAMESPACE
// Note that this class has nonstatic members. We instantiate it once
// per thread.
template <bool dummy>
class __pthread_alloc_template {
#define __STL_DATA_ALIGNMENT 8
private:
enum {ALIGN = 8};
enum {MAX_BYTES = 128}; // power of 2
enum {NFREELISTS = MAX_BYTES/ALIGN};
union _Pthread_alloc_obj {
union _Pthread_alloc_obj * __free_list_link;
char __client_data[__STL_DATA_ALIGNMENT]; /* The client sees this. */
};
union obj {
union obj * free_list_link;
char client_data[ALIGN]; /* The client sees this. */
};
// Pthread allocators don't appear to the client to have meaningful
// instances. We do in fact need to associate some state with each
// thread. That state is represented by
// _Pthread_alloc_per_thread_state<_Max_size>.
// Per instance state
obj* volatile free_list[NFREELISTS];
__pthread_alloc_template<dummy>* next; // Free list link
static size_t ROUND_UP(size_t bytes) {
return (((bytes) + ALIGN-1) & ~(ALIGN - 1));
}
static size_t FREELIST_INDEX(size_t bytes) {
return (((bytes) + ALIGN-1)/ALIGN - 1);
template<size_t _Max_size>
struct _Pthread_alloc_per_thread_state {
typedef _Pthread_alloc_obj __obj;
enum { _S_NFREELISTS = _Max_size/__STL_DATA_ALIGNMENT };
_Pthread_alloc_obj* volatile __free_list[_S_NFREELISTS];
_Pthread_alloc_per_thread_state<_Max_size> * __next;
// Free list link for list of available per thread structures.
// When one of these becomes available for reuse due to thread
// termination, any objects in its free list remain associated
// with it. The whole structure may then be used by a newly
// created thread.
_Pthread_alloc_per_thread_state() : __next(0)
{
memset((void *)__free_list, 0, _S_NFREELISTS * sizeof(__obj *));
}
// Returns an object of size __n, and possibly adds to size n free list.
void *_M_refill(size_t __n);
};
// Pthread-specific allocator.
// The argument specifies the largest object size allocated from per-thread
// free lists. Larger objects are allocated using malloc_alloc.
// Max_size must be a power of 2.
template <size_t _Max_size = 128>
class _Pthread_alloc_template {
public: // but only for internal use:
typedef _Pthread_alloc_obj __obj;
// Returns an object of size n, and optionally adds to size n free list.
void *refill(size_t n);
// Allocates a chunk for nobjs of size "size". nobjs may be reduced
// if it is inconvenient to allocate the requested number.
static char *chunk_alloc(size_t size, int &nobjs);
static char *_S_chunk_alloc(size_t __size, int &__nobjs);
enum {_S_ALIGN = __STL_DATA_ALIGNMENT};
static size_t _S_round_up(size_t __bytes) {
return (((__bytes) + _S_ALIGN-1) & ~(_S_ALIGN - 1));
}
static size_t _S_freelist_index(size_t __bytes) {
return (((__bytes) + _S_ALIGN-1)/_S_ALIGN - 1);
}
private:
// Chunk allocation state. And other shared state.
// Protected by chunk_allocator_lock.
static pthread_mutex_t chunk_allocator_lock;
static char *start_free;
static char *end_free;
static size_t heap_size;
static __pthread_alloc_template<dummy>* free_allocators;
static pthread_key_t key;
static bool key_initialized;
// Pthread key under which allocator is stored.
// Allocator instances that are currently unclaimed by any thread.
static void destructor(void *instance);
// Function to be called on thread exit to reclaim allocator
// instance.
static __pthread_alloc_template<dummy> *new_allocator();
// Return a recycled or new allocator instance.
static __pthread_alloc_template<dummy> *get_allocator_instance();
// ensure that the current thread has an associated
// allocator instance.
class lock {
// Protected by _S_chunk_allocator_lock.
static pthread_mutex_t _S_chunk_allocator_lock;
static char *_S_start_free;
static char *_S_end_free;
static size_t _S_heap_size;
static _Pthread_alloc_per_thread_state<_Max_size>* _S_free_per_thread_states;
static pthread_key_t _S_key;
static bool _S_key_initialized;
// Pthread key under which per thread state is stored.
// Allocator instances that are currently unclaimed by any thread.
static void _S_destructor(void *instance);
// Function to be called on thread exit to reclaim per thread
// state.
static _Pthread_alloc_per_thread_state<_Max_size> *_S_new_per_thread_state();
// Return a recycled or new per thread state.
static _Pthread_alloc_per_thread_state<_Max_size> *_S_get_per_thread_state();
// ensure that the current thread has an associated
// per thread state.
friend class _M_lock;
class _M_lock {
public:
lock () { pthread_mutex_lock(&chunk_allocator_lock); }
~lock () { pthread_mutex_unlock(&chunk_allocator_lock); }
_M_lock () { pthread_mutex_lock(&_S_chunk_allocator_lock); }
~_M_lock () { pthread_mutex_unlock(&_S_chunk_allocator_lock); }
};
friend class lock;
public:
__pthread_alloc_template() : next(0)
/* n must be > 0 */
static void * allocate(size_t __n)
{
memset((void *)free_list, 0, NFREELISTS * sizeof(obj *));
}
__obj * volatile * __my_free_list;
__obj * __RESTRICT __result;
_Pthread_alloc_per_thread_state<_Max_size>* __a;
/* n must be > 0 */
static void * allocate(size_t n)
{
obj * volatile * my_free_list;
obj * __RESTRICT result;
__pthread_alloc_template<dummy>* a;
if (n > MAX_BYTES) {
return(malloc(n));
if (__n > _Max_size) {
return(malloc_alloc::allocate(__n));
}
if (!key_initialized ||
!(a = (__pthread_alloc_template<dummy>*)
pthread_getspecific(key))) {
a = get_allocator_instance();
if (!_S_key_initialized ||
!(__a = (_Pthread_alloc_per_thread_state<_Max_size>*)
pthread_getspecific(_S_key))) {
__a = _S_get_per_thread_state();
}
my_free_list = a -> free_list + FREELIST_INDEX(n);
result = *my_free_list;
if (result == 0) {
void *r = a -> refill(ROUND_UP(n));
return r;
__my_free_list = __a -> __free_list + _S_freelist_index(__n);
__result = *__my_free_list;
if (__result == 0) {
void *__r = __a -> _M_refill(_S_round_up(__n));
return __r;
}
*my_free_list = result -> free_list_link;
return (result);
*__my_free_list = __result -> __free_list_link;
return (__result);
};
/* p may not be 0 */
static void deallocate(void *p, size_t n)
static void deallocate(void *__p, size_t __n)
{
obj *q = (obj *)p;
obj * volatile * my_free_list;
__pthread_alloc_template<dummy>* a;
__obj *__q = (__obj *)__p;
__obj * volatile * __my_free_list;
_Pthread_alloc_per_thread_state<_Max_size>* __a;
if (n > MAX_BYTES) {
free(p);
return;
if (__n > _Max_size) {
malloc_alloc::deallocate(__p, __n);
return;
}
if (!key_initialized ||
!(a = (__pthread_alloc_template<dummy>*)
pthread_getspecific(key))) {
a = get_allocator_instance();
if (!_S_key_initialized ||
!(__a = (_Pthread_alloc_per_thread_state<_Max_size> *)
pthread_getspecific(_S_key))) {
__a = _S_get_per_thread_state();
}
my_free_list = a->free_list + FREELIST_INDEX(n);
q -> free_list_link = *my_free_list;
*my_free_list = q;
__my_free_list = __a->__free_list + _S_freelist_index(__n);
__q -> __free_list_link = *__my_free_list;
*__my_free_list = __q;
}
static void * reallocate(void *p, size_t old_sz, size_t new_sz);
static void * reallocate(void *__p, size_t __old_sz, size_t __new_sz);
} ;
typedef __pthread_alloc_template<false> pthread_alloc;
typedef _Pthread_alloc_template<> pthread_alloc;
template <bool dummy>
void __pthread_alloc_template<dummy>::destructor(void * instance)
template <size_t _Max_size>
void _Pthread_alloc_template<_Max_size>::_S_destructor(void * __instance)
{
__pthread_alloc_template<dummy>* a =
(__pthread_alloc_template<dummy>*)instance;
a -> next = free_allocators;
free_allocators = a;
_M_lock __lock_instance; // Need to acquire lock here.
_Pthread_alloc_per_thread_state<_Max_size>* __s =
(_Pthread_alloc_per_thread_state<_Max_size> *)__instance;
__s -> __next = _S_free_per_thread_states;
_S_free_per_thread_states = __s;
}
template <bool dummy>
__pthread_alloc_template<dummy>*
__pthread_alloc_template<dummy>::new_allocator()
{
if (0 != free_allocators) {
__pthread_alloc_template<dummy>* result = free_allocators;
free_allocators = free_allocators -> next;
return result;
template <size_t _Max_size>
_Pthread_alloc_per_thread_state<_Max_size> *
_Pthread_alloc_template<_Max_size>::_S_new_per_thread_state()
{
/* lock already held here. */
if (0 != _S_free_per_thread_states) {
_Pthread_alloc_per_thread_state<_Max_size> *__result =
_S_free_per_thread_states;
_S_free_per_thread_states = _S_free_per_thread_states -> __next;
return __result;
} else {
return new __pthread_alloc_template<dummy>;
return new _Pthread_alloc_per_thread_state<_Max_size>;
}
}
template <bool dummy>
__pthread_alloc_template<dummy>*
__pthread_alloc_template<dummy>::get_allocator_instance()
template <size_t _Max_size>
_Pthread_alloc_per_thread_state<_Max_size> *
_Pthread_alloc_template<_Max_size>::_S_get_per_thread_state()
{
__pthread_alloc_template<dummy>* result;
if (!key_initialized) {
/*REFERENCED*/
lock lock_instance;
if (!key_initialized) {
if (pthread_key_create(&key, destructor)) {
abort(); // failed
}
key_initialized = true;
}
/*REFERENCED*/
_M_lock __lock_instance; // Need to acquire lock here.
_Pthread_alloc_per_thread_state<_Max_size> * __result;
if (!_S_key_initialized) {
if (pthread_key_create(&_S_key, _S_destructor)) {
abort(); // failed
}
_S_key_initialized = true;
}
result = new_allocator();
if (pthread_setspecific(key, result)) abort();
return result;
__result = _S_new_per_thread_state();
if (pthread_setspecific(_S_key, __result)) abort();
return __result;
}
/* We allocate memory in large chunks in order to avoid fragmenting */
/* the malloc heap too much. */
/* We assume that size is properly aligned. */
template <bool dummy>
char *__pthread_alloc_template<dummy>
::chunk_alloc(size_t size, int &nobjs)
/* We allocate memory in large chunks in order to avoid fragmenting */
/* the malloc heap too much. */
/* We assume that size is properly aligned. */
template <size_t _Max_size>
char *_Pthread_alloc_template<_Max_size>
::_S_chunk_alloc(size_t __size, int &__nobjs)
{
{
char * result;
size_t total_bytes;
size_t bytes_left;
char * __result;
size_t __total_bytes;
size_t __bytes_left;
/*REFERENCED*/
lock lock_instance; // Acquire lock for this routine
_M_lock __lock_instance; // Acquire lock for this routine
total_bytes = size * nobjs;
bytes_left = end_free - start_free;
if (bytes_left >= total_bytes) {
result = start_free;
start_free += total_bytes;
return(result);
} else if (bytes_left >= size) {
nobjs = bytes_left/size;
total_bytes = size * nobjs;
result = start_free;
start_free += total_bytes;
return(result);
__total_bytes = __size * __nobjs;
__bytes_left = _S_end_free - _S_start_free;
if (__bytes_left >= __total_bytes) {
__result = _S_start_free;
_S_start_free += __total_bytes;
return(__result);
} else if (__bytes_left >= __size) {
__nobjs = __bytes_left/__size;
__total_bytes = __size * __nobjs;
__result = _S_start_free;
_S_start_free += __total_bytes;
return(__result);
} else {
size_t bytes_to_get = 2 * total_bytes + ROUND_UP(heap_size >> 4);
// Try to make use of the left-over piece.
if (bytes_left > 0) {
__pthread_alloc_template<dummy>* a =
(__pthread_alloc_template<dummy>*)pthread_getspecific(key);
obj * volatile * my_free_list =
a->free_list + FREELIST_INDEX(bytes_left);
size_t __bytes_to_get =
2 * __total_bytes + _S_round_up(_S_heap_size >> 4);
// Try to make use of the left-over piece.
if (__bytes_left > 0) {
_Pthread_alloc_per_thread_state<_Max_size>* __a =
(_Pthread_alloc_per_thread_state<_Max_size>*)
pthread_getspecific(_S_key);
__obj * volatile * __my_free_list =
__a->__free_list + _S_freelist_index(__bytes_left);
((obj *)start_free) -> free_list_link = *my_free_list;
*my_free_list = (obj *)start_free;
}
# ifdef _SGI_SOURCE
// Try to get memory that's aligned on something like a
// cache line boundary, so as to avoid parceling out
// parts of the same line to different threads and thus
// possibly different processors.
{
const int cache_line_size = 128; // probable upper bound
bytes_to_get &= ~(cache_line_size-1);
start_free = (char *)memalign(cache_line_size, bytes_to_get);
if (0 == start_free) {
start_free = (char *)malloc_alloc::allocate(bytes_to_get);
}
}
# else /* !SGI_SOURCE */
start_free = (char *)malloc_alloc::allocate(bytes_to_get);
((__obj *)_S_start_free) -> __free_list_link = *__my_free_list;
*__my_free_list = (__obj *)_S_start_free;
}
# ifdef _SGI_SOURCE
// Try to get memory that's aligned on something like a
// cache line boundary, so as to avoid parceling out
// parts of the same line to different threads and thus
// possibly different processors.
{
const int __cache_line_size = 128; // probable upper bound
__bytes_to_get &= ~(__cache_line_size-1);
_S_start_free = (char *)memalign(__cache_line_size, __bytes_to_get);
if (0 == _S_start_free) {
_S_start_free = (char *)malloc_alloc::allocate(__bytes_to_get);
}
}
# else /* !SGI_SOURCE */
_S_start_free = (char *)malloc_alloc::allocate(__bytes_to_get);
# endif
heap_size += bytes_to_get;
end_free = start_free + bytes_to_get;
_S_heap_size += __bytes_to_get;
_S_end_free = _S_start_free + __bytes_to_get;
}
}
// lock is released here
return(chunk_alloc(size, nobjs));
return(_S_chunk_alloc(__size, __nobjs));
}
/* Returns an object of size n, and optionally adds to size n free list.*/
/* We assume that n is properly aligned. */
/* We hold the allocation lock. */
template <bool dummy>
void *__pthread_alloc_template<dummy>
::refill(size_t n)
/* We assume that n is properly aligned. */
/* We hold the allocation lock. */
template <size_t _Max_size>
void *_Pthread_alloc_per_thread_state<_Max_size>
::_M_refill(size_t __n)
{
int nobjs = 128;
char * chunk = chunk_alloc(n, nobjs);
obj * volatile * my_free_list;
obj * result;
obj * current_obj, * next_obj;
int i;
int __nobjs = 128;
char * __chunk =
_Pthread_alloc_template<_Max_size>::_S_chunk_alloc(__n, __nobjs);
__obj * volatile * __my_free_list;
__obj * __result;
__obj * __current_obj, * __next_obj;
int __i;
if (1 == nobjs) {
return(chunk);
if (1 == __nobjs) {
return(__chunk);
}
my_free_list = free_list + FREELIST_INDEX(n);
__my_free_list = __free_list
+ _Pthread_alloc_template<_Max_size>::_S_freelist_index(__n);
/* Build free list in chunk */
result = (obj *)chunk;
*my_free_list = next_obj = (obj *)(chunk + n);
for (i = 1; ; i++) {
current_obj = next_obj;
next_obj = (obj *)((char *)next_obj + n);
if (nobjs - 1 == i) {
current_obj -> free_list_link = 0;
break;
} else {
current_obj -> free_list_link = next_obj;
}
__result = (__obj *)__chunk;
*__my_free_list = __next_obj = (__obj *)(__chunk + __n);
for (__i = 1; ; __i++) {
__current_obj = __next_obj;
__next_obj = (__obj *)((char *)__next_obj + __n);
if (__nobjs - 1 == __i) {
__current_obj -> __free_list_link = 0;
break;
} else {
__current_obj -> __free_list_link = __next_obj;
}
}
return(result);
return(__result);
}
template <bool dummy>
void *__pthread_alloc_template<dummy>
::reallocate(void *p, size_t old_sz, size_t new_sz)
template <size_t _Max_size>
void *_Pthread_alloc_template<_Max_size>
::reallocate(void *__p, size_t __old_sz, size_t __new_sz)
{
void * result;
size_t copy_sz;
void * __result;
size_t __copy_sz;
if (old_sz > MAX_BYTES && new_sz > MAX_BYTES) {
return(realloc(p, new_sz));
if (__old_sz > _Max_size
&& __new_sz > _Max_size) {
return(realloc(__p, __new_sz));
}
if (ROUND_UP(old_sz) == ROUND_UP(new_sz)) return(p);
result = allocate(new_sz);
copy_sz = new_sz > old_sz? old_sz : new_sz;
memcpy(result, p, copy_sz);
deallocate(p, old_sz);
return(result);
if (_S_round_up(__old_sz) == _S_round_up(__new_sz)) return(__p);
__result = allocate(__new_sz);
__copy_sz = __new_sz > __old_sz? __old_sz : __new_sz;
memcpy(__result, __p, __copy_sz);
deallocate(__p, __old_sz);
return(__result);
}
template <bool dummy>
__pthread_alloc_template<dummy> *
__pthread_alloc_template<dummy>::free_allocators = 0;
template <size_t _Max_size>
_Pthread_alloc_per_thread_state<_Max_size> *
_Pthread_alloc_template<_Max_size>::_S_free_per_thread_states = 0;
template <bool dummy>
pthread_key_t __pthread_alloc_template<dummy>::key;
template <size_t _Max_size>
pthread_key_t _Pthread_alloc_template<_Max_size>::_S_key;
template <bool dummy>
bool __pthread_alloc_template<dummy>::key_initialized = false;
template <size_t _Max_size>
bool _Pthread_alloc_template<_Max_size>::_S_key_initialized = false;
template <bool dummy>
pthread_mutex_t __pthread_alloc_template<dummy>::chunk_allocator_lock
template <size_t _Max_size>
pthread_mutex_t _Pthread_alloc_template<_Max_size>::_S_chunk_allocator_lock
= PTHREAD_MUTEX_INITIALIZER;
template <bool dummy>
char *__pthread_alloc_template<dummy>
::start_free = 0;
template <size_t _Max_size>
char *_Pthread_alloc_template<_Max_size>
::_S_start_free = 0;
template <bool dummy>
char *__pthread_alloc_template<dummy>
::end_free = 0;
template <size_t _Max_size>
char *_Pthread_alloc_template<_Max_size>
::_S_end_free = 0;
template <bool dummy>
size_t __pthread_alloc_template<dummy>
::heap_size = 0;
template <size_t _Max_size>
size_t _Pthread_alloc_template<_Max_size>
::_S_heap_size = 0;
#ifdef __STL_USE_STD_ALLOCATORS
template <class _Tp>
class pthread_allocator {
typedef pthread_alloc _S_Alloc; // The underlying allocator.
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef _Tp* pointer;
typedef const _Tp* const_pointer;
typedef _Tp& reference;
typedef const _Tp& const_reference;
typedef _Tp value_type;
template <class _U> struct rebind {
typedef pthread_allocator<_U> other;
};
pthread_allocator() __STL_NOTHROW {}
pthread_allocator(const pthread_allocator& a) __STL_NOTHROW {}
template <class _U> pthread_allocator(const pthread_allocator<_U>&)
__STL_NOTHROW {}
~pthread_allocator() __STL_NOTHROW {}
pointer address(reference __x) const { return &__x; }
const_pointer address(const_reference __x) const { return &__x; }
// __n is permitted to be 0. The C++ standard says nothing about what
// the return value is when __n == 0.
_Tp* allocate(size_type __n, const void* = 0) {
return __n != 0 ? static_cast<_Tp*>(_S_Alloc::allocate(__n * sizeof(_Tp)))
: 0;
}
// p is not permitted to be a null pointer.
void deallocate(pointer __p, size_type __n)
{ _S_Alloc::deallocate(__p, __n * sizeof(_Tp)); }
size_type max_size() const __STL_NOTHROW
{ return size_t(-1) / sizeof(_Tp); }
void construct(pointer __p, const _Tp& __val) { new(__p) _Tp(__val); }
void destroy(pointer _p) { _p->~_Tp(); }
};
template<>
class pthread_allocator<void> {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef void* pointer;
typedef const void* const_pointer;
typedef void value_type;
template <class _U> struct rebind {
typedef pthread_allocator<_U> other;
};
};
template <size_t _Max_size>
inline bool operator==(const _Pthread_alloc_template<_Max_size>&,
const _Pthread_alloc_template<_Max_size>&)
{
return true;
}
template <class _T1, class _T2>
inline bool operator==(const pthread_allocator<_T1>&,
const pthread_allocator<_T2>& a2)
{
return true;
}
template <class _T1, class _T2>
inline bool operator!=(const pthread_allocator<_T1>&,
const pthread_allocator<_T2>&)
{
return false;
}
template <class _Tp, size_t _Max_size>
struct _Alloc_traits<_Tp, _Pthread_alloc_template<_Max_size> >
{
static const bool _S_instanceless = true;
typedef simple_alloc<_Tp, _Pthread_alloc_template<_Max_size> > _Alloc_type;
typedef __allocator<_Tp, _Pthread_alloc_template<_Max_size> >
allocator_type;
};
template <class _Tp, class _U, size_t _Max>
struct _Alloc_traits<_Tp, __allocator<_U, _Pthread_alloc_template<_Max> > >
{
static const bool _S_instanceless = true;
typedef simple_alloc<_Tp, _Pthread_alloc_template<_Max> > _Alloc_type;
typedef __allocator<_Tp, _Pthread_alloc_template<_Max> > allocator_type;
};
template <class _Tp, class _U>
struct _Alloc_traits<_Tp, pthread_allocator<_U> >
{
static const bool _S_instanceless = true;
typedef simple_alloc<_Tp, _Pthread_alloc_template<> > _Alloc_type;
typedef pthread_allocator<_Tp> allocator_type;
};
#endif /* __STL_USE_STD_ALLOCATORS */
__STL_END_NAMESPACE

View File

@ -18,8 +18,8 @@
#ifdef __STL_USE_NAMESPACES
using __STD::__pthread_alloc_template;
using __STL::pthread_alloc;
using __STD::_Pthread_alloc_template;
using __STD::pthread_alloc;
#endif /* __STL_USE_NAMESPACES */

View File

@ -15,7 +15,7 @@
#define __SGI_STL_ROPE
#include <stl_algobase.h>
#include <tempbuf.h>
#include <stl_tempbuf.h>
#include <stl_algo.h>
#include <stl_function.h>
#include <stl_numeric.h>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,7 @@
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1996
* Copyright (c) 1996-1998
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
@ -58,381 +58,465 @@
__STL_BEGIN_NAMESPACE
template <class ForwardIterator1, class ForwardIterator2, class T>
inline void __iter_swap(ForwardIterator1 a, ForwardIterator2 b, T*) {
T tmp = *a;
*a = *b;
*b = tmp;
// swap and iter_swap
template <class _ForwardIter1, class _ForwardIter2, class _Tp>
inline void __iter_swap(_ForwardIter1 __a, _ForwardIter2 __b, _Tp*) {
_Tp __tmp = *__a;
*__a = *__b;
*__b = __tmp;
}
template <class ForwardIterator1, class ForwardIterator2>
inline void iter_swap(ForwardIterator1 a, ForwardIterator2 b) {
__iter_swap(a, b, value_type(a));
template <class _ForwardIter1, class _ForwardIter2>
inline void iter_swap(_ForwardIter1 __a, _ForwardIter2 __b) {
__iter_swap(__a, __b, __VALUE_TYPE(__a));
}
template <class T>
inline void swap(T& a, T& b) {
T tmp = a;
a = b;
b = tmp;
template <class _Tp>
inline void swap(_Tp& __a, _Tp& __b) {
_Tp __tmp = __a;
__a = __b;
__b = __tmp;
}
//--------------------------------------------------
// min and max
#ifndef __BORLANDC__
#undef min
#undef max
template <class T>
inline const T& min(const T& a, const T& b) {
return b < a ? b : a;
template <class _Tp>
inline const _Tp& min(const _Tp& __a, const _Tp& __b) {
return __b < __a ? __b : __a;
}
template <class T>
inline const T& max(const T& a, const T& b) {
return a < b ? b : a;
template <class _Tp>
inline const _Tp& max(const _Tp& __a, const _Tp& __b) {
return __a < __b ? __b : __a;
}
#endif /* __BORLANDC__ */
template <class T, class Compare>
inline const T& min(const T& a, const T& b, Compare comp) {
return comp(b, a) ? b : a;
template <class _Tp, class _Compare>
inline const _Tp& min(const _Tp& __a, const _Tp& __b, _Compare __comp) {
return __comp(__b, __a) ? __b : __a;
}
template <class T, class Compare>
inline const T& max(const T& a, const T& b, Compare comp) {
return comp(a, b) ? b : a;
template <class _Tp, class _Compare>
inline const _Tp& max(const _Tp& __a, const _Tp& __b, _Compare __comp) {
return __comp(__a, __b) ? __b : __a;
}
template <class InputIterator, class OutputIterator>
inline OutputIterator __copy(InputIterator first, InputIterator last,
OutputIterator result, input_iterator_tag)
//--------------------------------------------------
// copy
// All of these auxiliary functions serve two purposes. (1) Replace
// calls to copy with memmove whenever possible. (Memmove, not memcpy,
// because the input and output ranges are permitted to overlap.)
// (2) If we're using random access iterators, then write the loop as
// a for loop with an explicit count. The auxiliary class __copy_dispatch
// is a workaround for compilers that don't support partial ordering of
// function templates.
template <class _InputIter, class _OutputIter, class _Distance>
inline _OutputIter __copy(_InputIter __first, _InputIter __last,
_OutputIter __result,
input_iterator_tag, _Distance*)
{
for ( ; first != last; ++result, ++first)
*result = *first;
return result;
for ( ; __first != __last; ++__result, ++__first)
*__result = *__first;
return __result;
}
template <class RandomAccessIterator, class OutputIterator, class Distance>
inline OutputIterator
__copy_d(RandomAccessIterator first, RandomAccessIterator last,
OutputIterator result, Distance*)
template <class _RandomAccessIter, class _OutputIter, class _Distance>
inline _OutputIter
__copy(_RandomAccessIter __first, _RandomAccessIter __last,
_OutputIter __result, random_access_iterator_tag, _Distance*)
{
for (Distance n = last - first; n > 0; --n, ++result, ++first)
*result = *first;
return result;
}
template <class RandomAccessIterator, class OutputIterator>
inline OutputIterator
__copy(RandomAccessIterator first, RandomAccessIterator last,
OutputIterator result, random_access_iterator_tag)
{
return __copy_d(first, last, result, distance_type(first));
}
template <class InputIterator, class OutputIterator>
struct __copy_dispatch
{
OutputIterator operator()(InputIterator first, InputIterator last,
OutputIterator result) {
return __copy(first, last, result, iterator_category(first));
for (_Distance __n = __last - __first; __n > 0; --__n) {
*__result = *__first;
++__first;
++__result;
}
};
return __result;
}
template <class _Tp>
inline _Tp*
__copy_trivial(const _Tp* __first, const _Tp* __last, _Tp* __result) {
memmove(__result, __first, sizeof(_Tp) * (__last - __first));
return __result + (__last - __first);
}
#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
template <class T>
inline T* __copy_t(const T* first, const T* last, T* result, __true_type) {
memmove(result, first, sizeof(T) * (last - first));
return result + (last - first);
}
template <class T>
inline T* __copy_t(const T* first, const T* last, T* result, __false_type) {
return __copy_d(first, last, result, (ptrdiff_t*) 0);
}
template <class T>
struct __copy_dispatch<T*, T*>
{
T* operator()(T* first, T* last, T* result) {
typedef typename __type_traits<T>::has_trivial_assignment_operator t;
return __copy_t(first, last, result, t());
template <class _InputIter, class _OutputIter, class _BoolType>
struct __copy_dispatch {
static _OutputIter copy(_InputIter __first, _InputIter __last,
_OutputIter __result) {
typedef typename iterator_traits<_InputIter>::iterator_category _Category;
typedef typename iterator_traits<_InputIter>::difference_type _Distance;
return __copy(__first, __last, __result, _Category(), (_Distance*) 0);
}
};
template <class T>
struct __copy_dispatch<const T*, T*>
template <class _Tp>
struct __copy_dispatch<_Tp*, _Tp*, __true_type>
{
T* operator()(const T* first, const T* last, T* result) {
typedef typename __type_traits<T>::has_trivial_assignment_operator t;
return __copy_t(first, last, result, t());
static _Tp* copy(const _Tp* __first, const _Tp* __last, _Tp* __result) {
return __copy_trivial(__first, __last, __result);
}
};
template <class _Tp>
struct __copy_dispatch<const _Tp*, _Tp*, __true_type>
{
static _Tp* copy(const _Tp* __first, const _Tp* __last, _Tp* __result) {
return __copy_trivial(__first, __last, __result);
}
};
template <class _InputIter, class _OutputIter>
inline _OutputIter copy(_InputIter __first, _InputIter __last,
_OutputIter __result) {
typedef typename iterator_traits<_InputIter>::value_type _Tp;
typedef typename __type_traits<_Tp>::has_trivial_assignment_operator
_Trivial;
return __copy_dispatch<_InputIter, _OutputIter, _Trivial>
::copy(__first, __last, __result);
}
#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
template <class _InputIter, class _OutputIter>
inline _OutputIter copy(_InputIter __first, _InputIter __last,
_OutputIter __result)
{
return __copy(__first, __last, __result,
__ITERATOR_CATEGORY(__first),
__DISTANCE_TYPE(__first));
}
inline char* copy(const char* __first, const char* __last, char* __result) {
memmove(__result, __first, __last - __first);
return __result + (__last - __first);
}
inline wchar_t* copy(const wchar_t* __first, const wchar_t* __last,
wchar_t* __result) {
memmove(__result, __first, sizeof(wchar_t) * (__last - __first));
return __result + (__last - __first);
}
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
template <class InputIterator, class OutputIterator>
inline OutputIterator copy(InputIterator first, InputIterator last,
OutputIterator result)
//--------------------------------------------------
// copy_backward
template <class _BidirectionalIter1, class _BidirectionalIter2,
class _Distance>
inline _BidirectionalIter2 __copy_backward(_BidirectionalIter1 __first,
_BidirectionalIter1 __last,
_BidirectionalIter2 __result,
bidirectional_iterator_tag,
_Distance*)
{
return __copy_dispatch<InputIterator,OutputIterator>()(first, last, result);
while (__first != __last)
*--__result = *--__last;
return __result;
}
inline char* copy(const char* first, const char* last, char* result) {
memmove(result, first, last - first);
return result + (last - first);
template <class _RandomAccessIter, class _BidirectionalIter, class _Distance>
inline _BidirectionalIter __copy_backward(_RandomAccessIter __first,
_RandomAccessIter __last,
_BidirectionalIter __result,
random_access_iterator_tag,
_Distance*)
{
for (_Distance __n = __last - __first; __n > 0; --__n)
*--__result = *--__last;
return __result;
}
inline wchar_t* copy(const wchar_t* first, const wchar_t* last,
wchar_t* result) {
memmove(result, first, sizeof(wchar_t) * (last - first));
return result + (last - first);
}
#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
template <class BidirectionalIterator1, class BidirectionalIterator2>
inline BidirectionalIterator2 __copy_backward(BidirectionalIterator1 first,
BidirectionalIterator1 last,
BidirectionalIterator2 result) {
while (first != last) *--result = *--last;
return result;
}
// This dispatch class is a workaround for compilers that do not
// have partial ordering of function templates. All we're doing is
// creating a specialization so that we can turn a call to copy_backward
// into a memmove whenever possible.
template <class BidirectionalIterator1, class BidirectionalIterator2>
template <class _BidirectionalIter1, class _BidirectionalIter2,
class _BoolType>
struct __copy_backward_dispatch
{
BidirectionalIterator2 operator()(BidirectionalIterator1 first,
BidirectionalIterator1 last,
BidirectionalIterator2 result) {
return __copy_backward(first, last, result);
typedef typename iterator_traits<_BidirectionalIter1>::iterator_category
_Cat;
typedef typename iterator_traits<_BidirectionalIter1>::difference_type
_Distance;
static _BidirectionalIter2 copy(_BidirectionalIter1 __first,
_BidirectionalIter1 __last,
_BidirectionalIter2 __result) {
return __copy_backward(__first, __last, __result, _Cat(), (_Distance*) 0);
}
};
#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
template <class _Tp>
struct __copy_backward_dispatch<_Tp*, _Tp*, __true_type>
{
static _Tp* copy(const _Tp* __first, const _Tp* __last, _Tp* __result) {
const ptrdiff_t _Num = __last - __first;
memmove(__result - _Num, __first, sizeof(_Tp) * _Num);
return __result - _Num;
}
};
template <class T>
inline T* __copy_backward_t(const T* first, const T* last, T* result,
__true_type) {
const ptrdiff_t N = last - first;
memmove(result - N, first, sizeof(T) * N);
return result - N;
template <class _Tp>
struct __copy_backward_dispatch<const _Tp*, _Tp*, __true_type>
{
static _Tp* copy(const _Tp* __first, const _Tp* __last, _Tp* __result) {
return __copy_backward_dispatch<_Tp*, _Tp*, __true_type>
::copy(__first, __last, __result);
}
};
template <class _BI1, class _BI2>
inline _BI2 copy_backward(_BI1 __first, _BI1 __last, _BI2 __result) {
typedef typename __type_traits<typename iterator_traits<_BI2>::value_type>
::has_trivial_assignment_operator
_Trivial;
return __copy_backward_dispatch<_BI1, _BI2, _Trivial>
::copy(__first, __last, __result);
}
template <class T>
inline T* __copy_backward_t(const T* first, const T* last, T* result,
__false_type) {
return __copy_backward(first, last, result);
#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
template <class _BI1, class _BI2>
inline _BI2 copy_backward(_BI1 __first, _BI1 __last, _BI2 __result) {
return __copy_backward(__first, __last, __result,
__ITERATOR_CATEGORY(__first),
__DISTANCE_TYPE(__first));
}
template <class T>
struct __copy_backward_dispatch<T*, T*>
{
T* operator()(T* first, T* last, T* result) {
typedef typename __type_traits<T>::has_trivial_assignment_operator t;
return __copy_backward_t(first, last, result, t());
}
};
template <class T>
struct __copy_backward_dispatch<const T*, T*>
{
T* operator()(const T* first, const T* last, T* result) {
typedef typename __type_traits<T>::has_trivial_assignment_operator t;
return __copy_backward_t(first, last, result, t());
}
};
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
template <class BidirectionalIterator1, class BidirectionalIterator2>
inline BidirectionalIterator2 copy_backward(BidirectionalIterator1 first,
BidirectionalIterator1 last,
BidirectionalIterator2 result) {
return __copy_backward_dispatch<BidirectionalIterator1,
BidirectionalIterator2>()(first, last,
result);
//--------------------------------------------------
// copy_n (not part of the C++ standard)
template <class _InputIter, class _Size, class _OutputIter>
pair<_InputIter, _OutputIter> __copy_n(_InputIter __first, _Size __count,
_OutputIter __result,
input_iterator_tag) {
for ( ; __count > 0; --__count) {
*__result = *__first;
++__first;
++__result;
}
return pair<_InputIter, _OutputIter>(__first, __result);
}
template <class InputIterator, class Size, class OutputIterator>
pair<InputIterator, OutputIterator> __copy_n(InputIterator first, Size count,
OutputIterator result,
input_iterator_tag) {
for ( ; count > 0; --count, ++first, ++result)
*result = *first;
return pair<InputIterator, OutputIterator>(first, result);
}
template <class RandomAccessIterator, class Size, class OutputIterator>
inline pair<RandomAccessIterator, OutputIterator>
__copy_n(RandomAccessIterator first, Size count,
OutputIterator result,
template <class _RAIter, class _Size, class _OutputIter>
inline pair<_RAIter, _OutputIter>
__copy_n(_RAIter __first, _Size __count,
_OutputIter __result,
random_access_iterator_tag) {
RandomAccessIterator last = first + count;
return pair<RandomAccessIterator, OutputIterator>(last,
copy(first, last, result));
_RAIter __last = __first + __count;
return pair<_RAIter, _OutputIter>(__last, copy(__first, __last, __result));
}
template <class InputIterator, class Size, class OutputIterator>
inline pair<InputIterator, OutputIterator>
copy_n(InputIterator first, Size count,
OutputIterator result) {
return __copy_n(first, count, result, iterator_category(first));
template <class _InputIter, class _Size, class _OutputIter>
inline pair<_InputIter, _OutputIter>
__copy_n(_InputIter __first, _Size __count, _OutputIter __result) {
return __copy_n(__first, __count, __result,
__ITERATOR_CATEGORY(__first));
}
template <class ForwardIterator, class T>
void fill(ForwardIterator first, ForwardIterator last, const T& value) {
for ( ; first != last; ++first)
*first = value;
template <class _InputIter, class _Size, class _OutputIter>
inline pair<_InputIter, _OutputIter>
copy_n(_InputIter __first, _Size __count, _OutputIter __result) {
return __copy_n(__first, __count, __result);
}
template <class OutputIterator, class Size, class T>
OutputIterator fill_n(OutputIterator first, Size n, const T& value) {
for ( ; n > 0; --n, ++first)
*first = value;
return first;
//--------------------------------------------------
// fill and fill_n
template <class _ForwardIter, class _Tp>
void fill(_ForwardIter __first, _ForwardIter __last, const _Tp& __value) {
for ( ; __first != __last; ++__first)
*__first = __value;
}
template <class InputIterator1, class InputIterator2>
pair<InputIterator1, InputIterator2> mismatch(InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2) {
while (first1 != last1 && *first1 == *first2) {
++first1;
++first2;
template <class _OutputIter, class _Size, class _Tp>
_OutputIter fill_n(_OutputIter __first, _Size __n, const _Tp& __value) {
for ( ; __n > 0; --__n, ++__first)
*__first = __value;
return __first;
}
//--------------------------------------------------
// equal and mismatch
template <class _InputIter1, class _InputIter2>
pair<_InputIter1, _InputIter2> mismatch(_InputIter1 __first1,
_InputIter1 __last1,
_InputIter2 __first2) {
while (__first1 != __last1 && *__first1 == *__first2) {
++__first1;
++__first2;
}
return pair<InputIterator1, InputIterator2>(first1, first2);
return pair<_InputIter1, _InputIter2>(__first1, __first2);
}
template <class InputIterator1, class InputIterator2, class BinaryPredicate>
pair<InputIterator1, InputIterator2> mismatch(InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
BinaryPredicate binary_pred) {
while (first1 != last1 && binary_pred(*first1, *first2)) {
++first1;
++first2;
template <class _InputIter1, class _InputIter2, class _BinaryPredicate>
pair<_InputIter1, _InputIter2> mismatch(_InputIter1 __first1,
_InputIter1 __last1,
_InputIter2 __first2,
_BinaryPredicate __binary_pred) {
while (__first1 != __last1 && __binary_pred(*__first1, *__first2)) {
++__first1;
++__first2;
}
return pair<InputIterator1, InputIterator2>(first1, first2);
return pair<_InputIter1, _InputIter2>(__first1, __first2);
}
template <class InputIterator1, class InputIterator2>
inline bool equal(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2) {
for ( ; first1 != last1; ++first1, ++first2)
if (*first1 != *first2)
template <class _InputIter1, class _InputIter2>
inline bool equal(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2) {
for ( ; __first1 != __last1; ++__first1, ++__first2)
if (*__first1 != *__first2)
return false;
return true;
}
template <class InputIterator1, class InputIterator2, class BinaryPredicate>
inline bool equal(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, BinaryPredicate binary_pred) {
for ( ; first1 != last1; ++first1, ++first2)
if (!binary_pred(*first1, *first2))
template <class _InputIter1, class _InputIter2, class _BinaryPredicate>
inline bool equal(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _BinaryPredicate __binary_pred) {
for ( ; __first1 != __last1; ++__first1, ++__first2)
if (!__binary_pred(*__first1, *__first2))
return false;
return true;
}
template <class InputIterator1, class InputIterator2>
bool lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2) {
for ( ; first1 != last1 && first2 != last2; ++first1, ++first2) {
if (*first1 < *first2)
//--------------------------------------------------
// lexicographical_compare and lexicographical_compare_3way.
// (the latter is not part of the C++ standard.)
template <class _InputIter1, class _InputIter2>
bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2) {
for ( ; __first1 != __last1 && __first2 != __last2
; ++__first1, ++__first2) {
if (*__first1 < *__first2)
return true;
if (*first2 < *first1)
if (*__first2 < *__first1)
return false;
}
return first1 == last1 && first2 != last2;
return __first1 == __last1 && __first2 != __last2;
}
template <class InputIterator1, class InputIterator2, class Compare>
bool lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
Compare comp) {
for ( ; first1 != last1 && first2 != last2; ++first1, ++first2) {
if (comp(*first1, *first2))
template <class _InputIter1, class _InputIter2, class _Compare>
bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2,
_Compare __comp) {
for ( ; __first1 != __last1 && __first2 != __last2
; ++__first1, ++__first2) {
if (__comp(*__first1, *__first2))
return true;
if (comp(*first2, *first1))
if (__comp(*__first2, *__first1))
return false;
}
return first1 == last1 && first2 != last2;
return __first1 == __last1 && __first2 != __last2;
}
inline bool
lexicographical_compare(const unsigned char* first1,
const unsigned char* last1,
const unsigned char* first2,
const unsigned char* last2)
lexicographical_compare(const unsigned char* __first1,
const unsigned char* __last1,
const unsigned char* __first2,
const unsigned char* __last2)
{
const size_t len1 = last1 - first1;
const size_t len2 = last2 - first2;
const int result = memcmp(first1, first2, min(len1, len2));
return result != 0 ? result < 0 : len1 < len2;
const size_t __len1 = __last1 - __first1;
const size_t __len2 = __last2 - __first2;
const int __result = memcmp(__first1, __first2, min(__len1, __len2));
return __result != 0 ? __result < 0 : __len1 < __len2;
}
inline bool lexicographical_compare(const char* first1, const char* last1,
const char* first2, const char* last2)
inline bool lexicographical_compare(const char* __first1, const char* __last1,
const char* __first2, const char* __last2)
{
#if CHAR_MAX == SCHAR_MAX
return lexicographical_compare((const signed char*) first1,
(const signed char*) last1,
(const signed char*) first2,
(const signed char*) last2);
#else
return lexicographical_compare((const unsigned char*) first1,
(const unsigned char*) last1,
(const unsigned char*) first2,
(const unsigned char*) last2);
#endif
return lexicographical_compare((const signed char*) __first1,
(const signed char*) __last1,
(const signed char*) __first2,
(const signed char*) __last2);
#else /* CHAR_MAX == SCHAR_MAX */
return lexicographical_compare((const unsigned char*) __first1,
(const unsigned char*) __last1,
(const unsigned char*) __first2,
(const unsigned char*) __last2);
#endif /* CHAR_MAX == SCHAR_MAX */
}
template <class InputIterator1, class InputIterator2>
int lexicographical_compare_3way(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2)
template <class _InputIter1, class _InputIter2>
int __lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2)
{
while (first1 != last1 && first2 != last2) {
if (*first1 < *first2) return -1;
if (*first2 < *first1) return 1;
++first1; ++first2;
while (__first1 != __last1 && __first2 != __last2) {
if (*__first1 < *__first2)
return -1;
if (*__first2 < *__first1)
return 1;
++__first1;
++__first2;
}
if (first2 == last2) {
return !(first1 == last1);
} else {
if (__first2 == __last2) {
return !(__first1 == __last1);
}
else {
return -1;
}
}
inline int
lexicographical_compare_3way(const unsigned char* first1,
const unsigned char* last1,
const unsigned char* first2,
const unsigned char* last2)
__lexicographical_compare_3way(const unsigned char* __first1,
const unsigned char* __last1,
const unsigned char* __first2,
const unsigned char* __last2)
{
const ptrdiff_t len1 = last1 - first1;
const ptrdiff_t len2 = last2 - first2;
const int result = memcmp(first1, first2, min(len1, len2));
return result != 0 ? result : (len1 == len2 ? 0 : (len1 < len2 ? -1 : 1));
const ptrdiff_t __len1 = __last1 - __first1;
const ptrdiff_t __len2 = __last2 - __first2;
const int __result = memcmp(__first1, __first2, min(__len1, __len2));
return __result != 0 ? __result
: (__len1 == __len2 ? 0 : (__len1 < __len2 ? -1 : 1));
}
inline int lexicographical_compare_3way(const char* first1, const char* last1,
const char* first2, const char* last2)
inline int
__lexicographical_compare_3way(const char* __first1, const char* __last1,
const char* __first2, const char* __last2)
{
#if CHAR_MAX == SCHAR_MAX
return lexicographical_compare_3way(
(const signed char*) first1,
(const signed char*) last1,
(const signed char*) first2,
(const signed char*) last2);
return __lexicographical_compare_3way(
(const signed char*) __first1,
(const signed char*) __last1,
(const signed char*) __first2,
(const signed char*) __last2);
#else
return lexicographical_compare_3way((const unsigned char*) first1,
(const unsigned char*) last1,
(const unsigned char*) first2,
(const unsigned char*) last2);
return __lexicographical_compare_3way((const unsigned char*) __first1,
(const unsigned char*) __last1,
(const unsigned char*) __first2,
(const unsigned char*) __last2);
#endif
}
template <class _InputIter1, class _InputIter2>
int lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2)
{
return __lexicographical_compare_3way(__first1, __last1, __first2, __last2);
}
__STL_END_NAMESPACE
#endif /* __SGI_STL_INTERNAL_ALGOBASE_H */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -27,49 +27,75 @@
#ifndef __STL_CONFIG_H
# define __STL_CONFIG_H
// What this file does.
// (1) Defines bool, true, and false if the compiler doesn't do so already.
// (2) Defines __STL_NO_DRAND48 if the compiler's standard library does
// not support the drand48() function.
// (3) Defines __STL_STATIC_TEMPLATE_MEMBER_BUG if the compiler can't
// handle static members of template classes.
// (4) Defines 'typename' as a null macro if the compiler does not support
// the typename keyword.
// (5) Defines __STL_CLASS_PARTIAL_SPECIALIZATION if the compiler
// supports partial specialization of class templates.
// (6) Defines __STL_FUNCTION_TMPL_PARTIAL_ORDER if the compiler supports
// partial ordering of function templates (a.k.a partial specialization
// of function templates.
// (7) Defines __STL_EXPLICIT_FUNCTION_TMPL_ARGS if the compiler
// supports calling a function template by providing its template
// arguments explicitly.
// (8) Defines __STL_MEMBER_TEMPLATES if the compiler supports
// template members of classes.
// (9) Defines 'explicit' as a null macro if the compiler does not support
// the explicit keyword.
// (10) Defines __STL_LIMITED_DEFAULT_TEMPLATES if the compiler is
// unable to handle default template parameters that depend on
// previous template parameters.
// (11) Defines __STL_NON_TYPE_TMPL_PARAM_BUG if the compiler has
// trouble performing function template argument deduction for
// non-type template parameters.
// (12) Defines __SGI_STL_NO_ARROW_OPERATOR if the compiler is unable
// to support the -> operator for iterators.
// (13) Defines __STL_USE_EXCEPTIONS if the compiler (in the current
// compilation mode) supports exceptions.
// (14) Define __STL_USE_NAMESPACES if we're putting the STL into a
// namespace.
// (15) Defines __STL_SGI_THREADS if this is being compiled on an SGI
// compiler, and if the user hasn't selected pthreads or no threads
// instead.
// (16) Defines __STL_WIN32THREADS if this is being compiled on a
// WIN32 compiler in multithreaded mode.
// (17) Define namespace-related macros (__STD, __STL_BEGIN_NAMESPACE, etc.)
// apropriately.
// (18) Define exception-related macros (__STL_TRY, __STL_UNWIND, etc.)
// appropriately.
// (19) Defines __stl_assert either as a test or as a null macro,
// depending on whether or not __STL_ASSERTIONS is defined.
// Flags:
// * __STL_NO_BOOL: defined if the compiler doesn't have bool as a builtin
// type.
// * __STL_HAS_WCHAR_T: defined if the compier has wchar_t as a builtin type.
// * __STL_NO_DRAND48: defined if the compiler doesn't have the drand48
// function.
// * __STL_STATIC_TEMPLATE_MEMBER_BUG: defined if the compiler can't handle
// static members of template classes.
// * __STL_CLASS_PARTIAL_SPECIALIZATION: defined if the compiler supports
// partial specialization of template classes.
// * __STL_PARTIAL_SPECIALIZATION_SYNTAX: defined if the compiler
// supports partial specialization syntax for full specialization of
// class templates. (Even if it doesn't actually support partial
// specialization itself.)
// * __STL_FUNCTION_TMPL_PARTIAL_ORDER: defined if the compiler supports
// partial ordering of function templates. (a.k.a partial specialization
// of function templates.)
// * __STL_MEMBER_TEMPLATES: defined if the compiler supports template
// member functions of classes.
// * __STL_MEMBER_TEMPLATE_CLASSES: defined if the compiler supports
// nested classes that are member templates of other classes.
// * __STL_EXPLICIT_FUNCTION_TMPL_ARGS: defined if the compiler
// supports calling a function template by providing its template
// arguments explicitly.
// * __STL_LIMITED_DEFAULT_TEMPLATES: defined if the compiler is unable
// to handle default template parameters that depend on previous template
// parameters.
// * __STL_NON_TYPE_TMPL_PARAM_BUG: defined if the compiler has trouble with
// function template argument deduction for non-type template parameters.
// * __SGI_STL_NO_ARROW_OPERATOR: defined if the compiler is unable
// to support the -> operator for iterators.
// * __STL_USE_EXCEPTIONS: defined if the compiler (in the current compilation
// mode) supports exceptions.
// * __STL_USE_NAMESPACES: defined if the compiler has the necessary
// support for namespaces.
// * __STL_NO_EXCEPTION_HEADER: defined if the compiler does not have a
// standard-conforming header <exception>.
// * __STL_SGI_THREADS: defined if this is being compiled for an SGI IRIX
// system in multithreaded mode, using native SGI threads instead of
// pthreads.
// * __STL_WIN32THREADS: defined if this is being compiled on a WIN32
// compiler in multithreaded mode.
// * __STL_LONG_LONG if the compiler has long long and unsigned long long
// types. (They're not in the C++ standard, but they are expected to be
// included in the forthcoming C9X standard.)
// User-settable macros that control compilation:
// * __STL_USE_SGI_ALLOCATORS: if defined, then the STL will use older
// SGI-style allocators, instead of standard-conforming allocators,
// even if the compiler supports all of the language features needed
// for standard-conforming allocators.
// * __STL_NO_NAMESPACES: if defined, don't put the library in namespace
// std, even if the compiler supports namespaces.
// * __STL_ASSERTIONS: if defined, then enable runtime checking through the
// __stl_assert macro.
// * _PTHREADS: if defined, use Posix threads for multithreading support.
// * _NOTHREADS: if defined, don't use any multithreading support.
// Other macros defined by this file:
// * bool, true, and false, if __STL_NO_BOOL is defined.
// * typename, as a null macro if it's not already a keyword.
// * explicit, as a null macro if it's not already a keyword.
// * namespace-related macros (__STD, __STL_BEGIN_NAMESPACE, etc.)
// * exception-related macros (__STL_TRY, __STL_UNWIND, etc.)
// * __stl_assert, either as a test or as a null macro, depending on
// whether or not __STL_ASSERTIONS is defined.
#ifdef _PTHREADS
# define __STL_PTHREADS
@ -77,7 +103,10 @@
# if defined(__sgi) && !defined(__GNUC__)
# if !defined(_BOOL)
# define __STL_NEED_BOOL
# define __STL_NO_BOOL
# endif
# if defined(_WCHAR_T_IS_KEYWORD)
# define __STL_HAS_WCHAR_T
# endif
# if !defined(_TYPENAME_IS_KEYWORD)
# define __STL_NEED_TYPENAME
@ -87,6 +116,13 @@
# endif
# ifdef _MEMBER_TEMPLATES
# define __STL_MEMBER_TEMPLATES
# define __STL_MEMBER_TEMPLATE_CLASSES
# endif
# if defined(_MEMBER_TEMPLATE_KEYWORD)
# define __STL_MEMBER_TEMPLATE_KEYWORD
# endif
# if (_COMPILER_VERSION >= 730) && defined(_MIPS_SIM) && _MIPS_SIM != _ABIO32
# define __STL_MEMBER_TEMPLATE_KEYWORD
# endif
# if !defined(_EXPLICIT_IS_KEYWORD)
# define __STL_NEED_EXPLICIT
@ -95,11 +131,17 @@
# define __STL_USE_EXCEPTIONS
# endif
# if (_COMPILER_VERSION >= 721) && defined(_NAMESPACES)
# define __STL_USE_NAMESPACES
# define __STL_HAS_NAMESPACES
# endif
# if (_COMPILER_VERSION < 721)
# define __STL_NO_EXCEPTION_HEADER
# endif
# if !defined(_NOTHREADS) && !defined(__STL_PTHREADS)
# define __STL_SGI_THREADS
# endif
# if defined(_LONGLONG) && defined(_SGIAPI) && _SGIAPI
# define __STL_LONG_LONG
# endif
# endif
# ifdef __GNUC__
@ -113,6 +155,8 @@
# define __STL_FUNCTION_TMPL_PARTIAL_ORDER
# define __STL_EXPLICIT_FUNCTION_TMPL_ARGS
# define __STL_MEMBER_TEMPLATES
// g++ 2.8.1 supports member template functions, but not member
// template nested classes.
# endif
/* glibc pre 2.0 is very buggy. We have to disable thread for it.
It should be upgraded to glibc 2.0 or later. */
@ -129,7 +173,7 @@
# endif
# if defined(__SUNPRO_CC)
# define __STL_NEED_BOOL
# define __STL_NO_BOOL
# define __STL_NEED_TYPENAME
# define __STL_NEED_EXPLICIT
# define __STL_USE_EXCEPTIONS
@ -137,21 +181,22 @@
# if defined(__COMO__)
# define __STL_MEMBER_TEMPLATES
# define __STL_MEMBER_TEMPLATE_CLASSES
# define __STL_CLASS_PARTIAL_SPECIALIZATION
# define __STL_USE_EXCEPTIONS
# define __STL_USE_NAMESPACES
# define __STL_HAS_NAMESPACES
# endif
# if defined(_MSC_VER)
# if _MSC_VER > 1000
# include <yvals.h>
# else
# define __STL_NEED_BOOL
# endif
# define __STL_NO_DRAND48
# define __STL_NEED_TYPENAME
# if _MSC_VER < 1100
# if _MSC_VER < 1100 /* 1000 is version 4.0, 1100 is 5.0, 1200 is 6.0. */
# define __STL_NEED_EXPLICIT
# define __STL_NO_BOOL
# if _MSC_VER > 1000
# include <yvals.h>
# define __STL_DONT_USE_BOOL_TYPEDEF
# endif
# endif
# define __STL_NON_TYPE_TMPL_PARAM_BUG
# define __SGI_STL_NO_ARROW_OPERATOR
@ -161,6 +206,11 @@
# ifdef _MT
# define __STL_WIN32THREADS
# endif
# if _MSC_VER >= 1200
# define __STL_PARTIAL_SPECIALIZATION_SYNTAX
# define __STL_HAS_NAMESPACES
# define __STL_NO_NAMESPACES
# endif
# endif
# if defined(__BORLANDC__)
@ -177,8 +227,7 @@
# endif
# endif
# if defined(__STL_NEED_BOOL)
# if defined(__STL_NO_BOOL) && !defined(__STL_DONT_USE_BOOL_TYPEDEF)
typedef int bool;
# define true 1
# define false 0
@ -188,6 +237,12 @@
# define typename
# endif
# ifdef __STL_MEMBER_TEMPLATE_KEYWORD
# define __STL_TEMPLATE template
# else
# define __STL_TEMPLATE
# endif
# ifdef __STL_NEED_EXPLICIT
# define explicit
# endif
@ -198,22 +253,46 @@
# define __STL_NULL_TMPL_ARGS
# endif
# ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
# if defined(__STL_CLASS_PARTIAL_SPECIALIZATION) \
|| defined (__STL_PARTIAL_SPECIALIZATION_SYNTAX)
# define __STL_TEMPLATE_NULL template<>
# else
# define __STL_TEMPLATE_NULL
# endif
// Use standard-conforming allocators if we have the necessary language
// features. __STL_USE_SGI_ALLOCATORS is a hook so that users can
// disable new-style allocators, and continue to use the same kind of
// allocators as before, without having to edit library headers.
# if defined(__STL_CLASS_PARTIAL_SPECIALIZATION) && \
defined(__STL_MEMBER_TEMPLATES) && \
defined(__STL_MEMBER_TEMPLATE_CLASSES) && \
!defined(__STL_NO_BOOL) && \
!defined(__STL_NON_TYPE_TMPL_PARAM_BUG) && \
!defined(__STL_LIMITED_DEFAULT_TEMPLATES) && \
!defined(__STL_USE_SGI_ALLOCATORS)
# define __STL_USE_STD_ALLOCATORS
# endif
# ifndef __STL_DEFAULT_ALLOCATOR
# ifdef __STL_USE_STD_ALLOCATORS
# define __STL_DEFAULT_ALLOCATOR(T) allocator<T>
# else
# define __STL_DEFAULT_ALLOCATOR(T) alloc
# endif
# endif
// __STL_NO_NAMESPACES is a hook so that users can disable namespaces
// without having to edit library headers.
# if defined(__STL_USE_NAMESPACES) && !defined(__STL_NO_NAMESPACES)
# if defined(__STL_HAS_NAMESPACES) && !defined(__STL_NO_NAMESPACES)
# define __STD std
# define __STL_BEGIN_NAMESPACE namespace std {
# define __STL_END_NAMESPACE }
# define __STL_USE_NAMESPACE_FOR_RELOPS
# define __STL_USE_NAMESPACE_FOR_RELOPS
# define __STL_BEGIN_RELOPS_NAMESPACE namespace std {
# define __STL_END_RELOPS_NAMESPACE }
# define __STD_RELOPS std
# define __STL_USE_NAMESPACES
# else
# define __STD
# define __STL_BEGIN_NAMESPACE
@ -222,17 +301,20 @@
# define __STL_BEGIN_RELOPS_NAMESPACE
# define __STL_END_RELOPS_NAMESPACE
# define __STD_RELOPS
# undef __STL_USE_NAMESPACES
# endif
# ifdef __STL_USE_EXCEPTIONS
# define __STL_TRY try
# define __STL_CATCH_ALL catch(...)
# define __STL_THROW(x) throw x
# define __STL_RETHROW throw
# define __STL_NOTHROW throw()
# define __STL_UNWIND(action) catch(...) { action; throw; }
# else
# define __STL_TRY
# define __STL_CATCH_ALL if (false)
# define __STL_THROW(x)
# define __STL_RETHROW
# define __STL_NOTHROW
# define __STL_UNWIND(action)

View File

@ -35,35 +35,47 @@
__STL_BEGIN_NAMESPACE
template <class T>
inline void destroy(T* pointer) {
pointer->~T();
// construct and destroy. These functions are not part of the C++ standard,
// and are provided for backward compatibility with the HP STL.
template <class _Tp>
inline void destroy(_Tp* __pointer) {
__pointer->~_Tp();
}
template <class T1, class T2>
inline void construct(T1* p, const T2& value) {
new (p) T1(value);
template <class _T1, class _T2>
inline void construct(_T1* __p, const _T2& __value) {
new (__p) _T1(__value);
}
template <class ForwardIterator>
template <class _T1>
inline void construct(_T1* __p) {
new (__p) _T1();
}
template <class _ForwardIterator>
inline void
__destroy_aux(ForwardIterator first, ForwardIterator last, __false_type) {
for ( ; first < last; ++first)
destroy(&*first);
__destroy_aux(_ForwardIterator __first, _ForwardIterator __last, __false_type)
{
for ( ; __first < __last; ++__first)
destroy(&*__first);
}
template <class ForwardIterator>
inline void __destroy_aux(ForwardIterator, ForwardIterator, __true_type) {}
template <class _ForwardIterator>
inline void __destroy_aux(_ForwardIterator, _ForwardIterator, __true_type) {}
template <class ForwardIterator, class T>
inline void __destroy(ForwardIterator first, ForwardIterator last, T*) {
typedef typename __type_traits<T>::has_trivial_destructor trivial_destructor;
__destroy_aux(first, last, trivial_destructor());
template <class _ForwardIterator, class _Tp>
inline void
__destroy(_ForwardIterator __first, _ForwardIterator __last, _Tp*)
{
typedef typename __type_traits<_Tp>::has_trivial_destructor
_Trivial_destructor;
__destroy_aux(__first, __last, _Trivial_destructor());
}
template <class ForwardIterator>
inline void destroy(ForwardIterator first, ForwardIterator last) {
__destroy(first, last, value_type(first));
template <class _ForwardIterator>
inline void destroy(_ForwardIterator __first, _ForwardIterator __last) {
__destroy(__first, __last, __VALUE_TYPE(__first));
}
inline void destroy(char*, char*) {}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996
* Copyright (c) 1996-1998
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
@ -35,53 +35,53 @@
__STL_BEGIN_NAMESPACE
template <class Key> struct hash { };
template <class _Key> struct hash { };
inline size_t __stl_hash_string(const char* s)
inline size_t __stl_hash_string(const char* __s)
{
unsigned long h = 0;
for ( ; *s; ++s)
h = 5*h + *s;
unsigned long __h = 0;
for ( ; *__s; ++__s)
__h = 5*__h + *__s;
return size_t(h);
return size_t(__h);
}
__STL_TEMPLATE_NULL struct hash<char*>
{
size_t operator()(const char* s) const { return __stl_hash_string(s); }
size_t operator()(const char* __s) const { return __stl_hash_string(__s); }
};
__STL_TEMPLATE_NULL struct hash<const char*>
{
size_t operator()(const char* s) const { return __stl_hash_string(s); }
size_t operator()(const char* __s) const { return __stl_hash_string(__s); }
};
__STL_TEMPLATE_NULL struct hash<char> {
size_t operator()(char x) const { return x; }
size_t operator()(char __x) const { return __x; }
};
__STL_TEMPLATE_NULL struct hash<unsigned char> {
size_t operator()(unsigned char x) const { return x; }
size_t operator()(unsigned char __x) const { return __x; }
};
__STL_TEMPLATE_NULL struct hash<signed char> {
size_t operator()(unsigned char x) const { return x; }
size_t operator()(unsigned char __x) const { return __x; }
};
__STL_TEMPLATE_NULL struct hash<short> {
size_t operator()(short x) const { return x; }
size_t operator()(short __x) const { return __x; }
};
__STL_TEMPLATE_NULL struct hash<unsigned short> {
size_t operator()(unsigned short x) const { return x; }
size_t operator()(unsigned short __x) const { return __x; }
};
__STL_TEMPLATE_NULL struct hash<int> {
size_t operator()(int x) const { return x; }
size_t operator()(int __x) const { return __x; }
};
__STL_TEMPLATE_NULL struct hash<unsigned int> {
size_t operator()(unsigned int x) const { return x; }
size_t operator()(unsigned int __x) const { return __x; }
};
__STL_TEMPLATE_NULL struct hash<long> {
size_t operator()(long x) const { return x; }
size_t operator()(long __x) const { return __x; }
};
__STL_TEMPLATE_NULL struct hash<unsigned long> {
size_t operator()(unsigned long x) const { return x; }
size_t operator()(unsigned long __x) const { return __x; }
};
__STL_END_NAMESPACE

View File

@ -36,317 +36,375 @@ __STL_BEGIN_NAMESPACE
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
#pragma set woff 1174
#pragma set woff 1375
#endif
#ifndef __STL_LIMITED_DEFAULT_TEMPLATES
template <class Key, class T, class HashFcn = hash<Key>,
class EqualKey = equal_to<Key>,
class Alloc = alloc>
template <class _Key, class _Tp, class _HashFcn = hash<_Key>,
class _EqualKey = equal_to<_Key>,
class _Alloc = __STL_DEFAULT_ALLOCATOR(_Tp) >
#else
template <class Key, class T, class HashFcn, class EqualKey,
class Alloc = alloc>
template <class _Key, class _Tp, class _HashFcn, class _EqualKey,
class _Alloc = __STL_DEFAULT_ALLOCATOR(_Tp) >
#endif
class hash_map
{
private:
typedef hashtable<pair<const Key, T>, Key, HashFcn,
select1st<pair<const Key, T> >, EqualKey, Alloc> ht;
ht rep;
typedef hashtable<pair<const _Key,_Tp>,_Key,_HashFcn,
_Select1st<pair<const _Key,_Tp> >,_EqualKey,_Alloc> _Ht;
_Ht _M_ht;
public:
typedef typename ht::key_type key_type;
typedef T data_type;
typedef T mapped_type;
typedef typename ht::value_type value_type;
typedef typename ht::hasher hasher;
typedef typename ht::key_equal key_equal;
typedef typename _Ht::key_type key_type;
typedef _Tp data_type;
typedef _Tp mapped_type;
typedef typename _Ht::value_type value_type;
typedef typename _Ht::hasher hasher;
typedef typename _Ht::key_equal key_equal;
typedef typename _Ht::size_type size_type;
typedef typename _Ht::difference_type difference_type;
typedef typename _Ht::pointer pointer;
typedef typename _Ht::const_pointer const_pointer;
typedef typename _Ht::reference reference;
typedef typename _Ht::const_reference const_reference;
typedef typename ht::size_type size_type;
typedef typename ht::difference_type difference_type;
typedef typename ht::pointer pointer;
typedef typename ht::const_pointer const_pointer;
typedef typename ht::reference reference;
typedef typename ht::const_reference const_reference;
typedef typename _Ht::iterator iterator;
typedef typename _Ht::const_iterator const_iterator;
typedef typename ht::iterator iterator;
typedef typename ht::const_iterator const_iterator;
typedef typename _Ht::allocator_type allocator_type;
hasher hash_funct() const { return rep.hash_funct(); }
key_equal key_eq() const { return rep.key_eq(); }
hasher hash_funct() const { return _M_ht.hash_funct(); }
key_equal key_eq() const { return _M_ht.key_eq(); }
allocator_type get_allocator() const { return _M_ht.get_allocator(); }
public:
hash_map() : rep(100, hasher(), key_equal()) {}
explicit hash_map(size_type n) : rep(n, hasher(), key_equal()) {}
hash_map(size_type n, const hasher& hf) : rep(n, hf, key_equal()) {}
hash_map(size_type n, const hasher& hf, const key_equal& eql)
: rep(n, hf, eql) {}
hash_map() : _M_ht(100, hasher(), key_equal(), allocator_type()) {}
explicit hash_map(size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type()) {}
hash_map(size_type __n, const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type()) {}
hash_map(size_type __n, const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a) {}
#ifdef __STL_MEMBER_TEMPLATES
template <class InputIterator>
hash_map(InputIterator f, InputIterator l)
: rep(100, hasher(), key_equal()) { rep.insert_unique(f, l); }
template <class InputIterator>
hash_map(InputIterator f, InputIterator l, size_type n)
: rep(n, hasher(), key_equal()) { rep.insert_unique(f, l); }
template <class InputIterator>
hash_map(InputIterator f, InputIterator l, size_type n,
const hasher& hf)
: rep(n, hf, key_equal()) { rep.insert_unique(f, l); }
template <class InputIterator>
hash_map(InputIterator f, InputIterator l, size_type n,
const hasher& hf, const key_equal& eql)
: rep(n, hf, eql) { rep.insert_unique(f, l); }
template <class _InputIterator>
hash_map(_InputIterator __f, _InputIterator __l)
: _M_ht(100, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
template <class _InputIterator>
hash_map(_InputIterator __f, _InputIterator __l, size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
template <class _InputIterator>
hash_map(_InputIterator __f, _InputIterator __l, size_type __n,
const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
template <class _InputIterator>
hash_map(_InputIterator __f, _InputIterator __l, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a)
{ _M_ht.insert_unique(__f, __l); }
#else
hash_map(const value_type* f, const value_type* l)
: rep(100, hasher(), key_equal()) { rep.insert_unique(f, l); }
hash_map(const value_type* f, const value_type* l, size_type n)
: rep(n, hasher(), key_equal()) { rep.insert_unique(f, l); }
hash_map(const value_type* f, const value_type* l, size_type n,
const hasher& hf)
: rep(n, hf, key_equal()) { rep.insert_unique(f, l); }
hash_map(const value_type* f, const value_type* l, size_type n,
const hasher& hf, const key_equal& eql)
: rep(n, hf, eql) { rep.insert_unique(f, l); }
hash_map(const value_type* __f, const value_type* __l)
: _M_ht(100, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
hash_map(const value_type* __f, const value_type* __l, size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
hash_map(const value_type* __f, const value_type* __l, size_type __n,
const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
hash_map(const value_type* __f, const value_type* __l, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a)
{ _M_ht.insert_unique(__f, __l); }
hash_map(const_iterator f, const_iterator l)
: rep(100, hasher(), key_equal()) { rep.insert_unique(f, l); }
hash_map(const_iterator f, const_iterator l, size_type n)
: rep(n, hasher(), key_equal()) { rep.insert_unique(f, l); }
hash_map(const_iterator f, const_iterator l, size_type n,
const hasher& hf)
: rep(n, hf, key_equal()) { rep.insert_unique(f, l); }
hash_map(const_iterator f, const_iterator l, size_type n,
const hasher& hf, const key_equal& eql)
: rep(n, hf, eql) { rep.insert_unique(f, l); }
hash_map(const_iterator __f, const_iterator __l)
: _M_ht(100, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
hash_map(const_iterator __f, const_iterator __l, size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
hash_map(const_iterator __f, const_iterator __l, size_type __n,
const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
hash_map(const_iterator __f, const_iterator __l, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a)
{ _M_ht.insert_unique(__f, __l); }
#endif /*__STL_MEMBER_TEMPLATES */
public:
size_type size() const { return rep.size(); }
size_type max_size() const { return rep.max_size(); }
bool empty() const { return rep.empty(); }
void swap(hash_map& hs) { rep.swap(hs.rep); }
size_type size() const { return _M_ht.size(); }
size_type max_size() const { return _M_ht.max_size(); }
bool empty() const { return _M_ht.empty(); }
void swap(hash_map& __hs) { _M_ht.swap(__hs._M_ht); }
friend bool
operator== __STL_NULL_TMPL_ARGS (const hash_map&, const hash_map&);
iterator begin() { return rep.begin(); }
iterator end() { return rep.end(); }
const_iterator begin() const { return rep.begin(); }
const_iterator end() const { return rep.end(); }
iterator begin() { return _M_ht.begin(); }
iterator end() { return _M_ht.end(); }
const_iterator begin() const { return _M_ht.begin(); }
const_iterator end() const { return _M_ht.end(); }
public:
pair<iterator, bool> insert(const value_type& obj)
{ return rep.insert_unique(obj); }
pair<iterator,bool> insert(const value_type& __obj)
{ return _M_ht.insert_unique(__obj); }
#ifdef __STL_MEMBER_TEMPLATES
template <class InputIterator>
void insert(InputIterator f, InputIterator l) { rep.insert_unique(f,l); }
template <class _InputIterator>
void insert(_InputIterator __f, _InputIterator __l)
{ _M_ht.insert_unique(__f,__l); }
#else
void insert(const value_type* f, const value_type* l) {
rep.insert_unique(f,l);
void insert(const value_type* __f, const value_type* __l) {
_M_ht.insert_unique(__f,__l);
}
void insert(const_iterator f, const_iterator l) { rep.insert_unique(f, l); }
void insert(const_iterator __f, const_iterator __l)
{ _M_ht.insert_unique(__f, __l); }
#endif /*__STL_MEMBER_TEMPLATES */
pair<iterator, bool> insert_noresize(const value_type& obj)
{ return rep.insert_unique_noresize(obj); }
pair<iterator,bool> insert_noresize(const value_type& __obj)
{ return _M_ht.insert_unique_noresize(__obj); }
iterator find(const key_type& key) { return rep.find(key); }
const_iterator find(const key_type& key) const { return rep.find(key); }
iterator find(const key_type& __key) { return _M_ht.find(__key); }
const_iterator find(const key_type& __key) const
{ return _M_ht.find(__key); }
T& operator[](const key_type& key) {
return rep.find_or_insert(value_type(key, T())).second;
_Tp& operator[](const key_type& __key) {
return _M_ht.find_or_insert(value_type(__key, _Tp())).second;
}
size_type count(const key_type& key) const { return rep.count(key); }
size_type count(const key_type& __key) const { return _M_ht.count(__key); }
pair<iterator, iterator> equal_range(const key_type& key)
{ return rep.equal_range(key); }
pair<const_iterator, const_iterator> equal_range(const key_type& key) const
{ return rep.equal_range(key); }
pair<iterator, iterator> equal_range(const key_type& __key)
{ return _M_ht.equal_range(__key); }
pair<const_iterator, const_iterator>
equal_range(const key_type& __key) const
{ return _M_ht.equal_range(__key); }
size_type erase(const key_type& key) {return rep.erase(key); }
void erase(iterator it) { rep.erase(it); }
void erase(iterator f, iterator l) { rep.erase(f, l); }
void clear() { rep.clear(); }
size_type erase(const key_type& __key) {return _M_ht.erase(__key); }
void erase(iterator __it) { _M_ht.erase(__it); }
void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); }
void clear() { _M_ht.clear(); }
public:
void resize(size_type hint) { rep.resize(hint); }
size_type bucket_count() const { return rep.bucket_count(); }
size_type max_bucket_count() const { return rep.max_bucket_count(); }
size_type elems_in_bucket(size_type n) const
{ return rep.elems_in_bucket(n); }
void resize(size_type __hint) { _M_ht.resize(__hint); }
size_type bucket_count() const { return _M_ht.bucket_count(); }
size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
size_type elems_in_bucket(size_type __n) const
{ return _M_ht.elems_in_bucket(__n); }
};
template <class Key, class T, class HashFcn, class EqualKey, class Alloc>
inline bool operator==(const hash_map<Key, T, HashFcn, EqualKey, Alloc>& hm1,
const hash_map<Key, T, HashFcn, EqualKey, Alloc>& hm2)
template <class _Key, class _Tp, class _HashFcn, class _EqlKey, class _Alloc>
inline bool
operator==(const hash_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm1,
const hash_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm2)
{
return hm1.rep == hm2.rep;
return __hm1._M_ht == __hm2._M_ht;
}
#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
template <class Key, class T, class HashFcn, class EqualKey, class Alloc>
inline void swap(hash_map<Key, T, HashFcn, EqualKey, Alloc>& hm1,
hash_map<Key, T, HashFcn, EqualKey, Alloc>& hm2)
template <class _Key, class _Tp, class _HashFcn, class _EqlKey, class _Alloc>
inline void
swap(hash_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm1,
hash_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm2)
{
hm1.swap(hm2);
__hm1.swap(__hm2);
}
#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
#ifndef __STL_LIMITED_DEFAULT_TEMPLATES
template <class Key, class T, class HashFcn = hash<Key>,
class EqualKey = equal_to<Key>,
class Alloc = alloc>
template <class _Key, class _Tp, class _HashFcn = hash<_Key>,
class _EqualKey = equal_to<_Key>,
class _Alloc = __STL_DEFAULT_ALLOCATOR(_Tp) >
#else
template <class Key, class T, class HashFcn, class EqualKey,
class Alloc = alloc>
template <class _Key, class _Tp, class _HashFcn, class _EqualKey,
class _Alloc = __STL_DEFAULT_ALLOCATOR(_Tp) >
#endif
class hash_multimap
{
private:
typedef hashtable<pair<const Key, T>, Key, HashFcn,
select1st<pair<const Key, T> >, EqualKey, Alloc> ht;
ht rep;
typedef hashtable<pair<const _Key, _Tp>, _Key, _HashFcn,
_Select1st<pair<const _Key, _Tp> >, _EqualKey, _Alloc>
_Ht;
_Ht _M_ht;
public:
typedef typename ht::key_type key_type;
typedef T data_type;
typedef T mapped_type;
typedef typename ht::value_type value_type;
typedef typename ht::hasher hasher;
typedef typename ht::key_equal key_equal;
typedef typename _Ht::key_type key_type;
typedef _Tp data_type;
typedef _Tp mapped_type;
typedef typename _Ht::value_type value_type;
typedef typename _Ht::hasher hasher;
typedef typename _Ht::key_equal key_equal;
typedef typename ht::size_type size_type;
typedef typename ht::difference_type difference_type;
typedef typename ht::pointer pointer;
typedef typename ht::const_pointer const_pointer;
typedef typename ht::reference reference;
typedef typename ht::const_reference const_reference;
typedef typename _Ht::size_type size_type;
typedef typename _Ht::difference_type difference_type;
typedef typename _Ht::pointer pointer;
typedef typename _Ht::const_pointer const_pointer;
typedef typename _Ht::reference reference;
typedef typename _Ht::const_reference const_reference;
typedef typename ht::iterator iterator;
typedef typename ht::const_iterator const_iterator;
typedef typename _Ht::iterator iterator;
typedef typename _Ht::const_iterator const_iterator;
hasher hash_funct() const { return rep.hash_funct(); }
key_equal key_eq() const { return rep.key_eq(); }
typedef typename _Ht::allocator_type allocator_type;
hasher hash_funct() const { return _M_ht.hash_funct(); }
key_equal key_eq() const { return _M_ht.key_eq(); }
allocator_type get_allocator() const { return _M_ht.get_allocator(); }
public:
hash_multimap() : rep(100, hasher(), key_equal()) {}
explicit hash_multimap(size_type n) : rep(n, hasher(), key_equal()) {}
hash_multimap(size_type n, const hasher& hf) : rep(n, hf, key_equal()) {}
hash_multimap(size_type n, const hasher& hf, const key_equal& eql)
: rep(n, hf, eql) {}
hash_multimap() : _M_ht(100, hasher(), key_equal(), allocator_type()) {}
explicit hash_multimap(size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type()) {}
hash_multimap(size_type __n, const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type()) {}
hash_multimap(size_type __n, const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a) {}
#ifdef __STL_MEMBER_TEMPLATES
template <class InputIterator>
hash_multimap(InputIterator f, InputIterator l)
: rep(100, hasher(), key_equal()) { rep.insert_equal(f, l); }
template <class InputIterator>
hash_multimap(InputIterator f, InputIterator l, size_type n)
: rep(n, hasher(), key_equal()) { rep.insert_equal(f, l); }
template <class InputIterator>
hash_multimap(InputIterator f, InputIterator l, size_type n,
const hasher& hf)
: rep(n, hf, key_equal()) { rep.insert_equal(f, l); }
template <class InputIterator>
hash_multimap(InputIterator f, InputIterator l, size_type n,
const hasher& hf, const key_equal& eql)
: rep(n, hf, eql) { rep.insert_equal(f, l); }
template <class _InputIterator>
hash_multimap(_InputIterator __f, _InputIterator __l)
: _M_ht(100, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
template <class _InputIterator>
hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
template <class _InputIterator>
hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n,
const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
template <class _InputIterator>
hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a)
{ _M_ht.insert_equal(__f, __l); }
#else
hash_multimap(const value_type* f, const value_type* l)
: rep(100, hasher(), key_equal()) { rep.insert_equal(f, l); }
hash_multimap(const value_type* f, const value_type* l, size_type n)
: rep(n, hasher(), key_equal()) { rep.insert_equal(f, l); }
hash_multimap(const value_type* f, const value_type* l, size_type n,
const hasher& hf)
: rep(n, hf, key_equal()) { rep.insert_equal(f, l); }
hash_multimap(const value_type* f, const value_type* l, size_type n,
const hasher& hf, const key_equal& eql)
: rep(n, hf, eql) { rep.insert_equal(f, l); }
hash_multimap(const value_type* __f, const value_type* __l)
: _M_ht(100, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
hash_multimap(const value_type* __f, const value_type* __l, size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
hash_multimap(const value_type* __f, const value_type* __l, size_type __n,
const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
hash_multimap(const value_type* __f, const value_type* __l, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a)
{ _M_ht.insert_equal(__f, __l); }
hash_multimap(const_iterator f, const_iterator l)
: rep(100, hasher(), key_equal()) { rep.insert_equal(f, l); }
hash_multimap(const_iterator f, const_iterator l, size_type n)
: rep(n, hasher(), key_equal()) { rep.insert_equal(f, l); }
hash_multimap(const_iterator f, const_iterator l, size_type n,
const hasher& hf)
: rep(n, hf, key_equal()) { rep.insert_equal(f, l); }
hash_multimap(const_iterator f, const_iterator l, size_type n,
const hasher& hf, const key_equal& eql)
: rep(n, hf, eql) { rep.insert_equal(f, l); }
hash_multimap(const_iterator __f, const_iterator __l)
: _M_ht(100, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
hash_multimap(const_iterator __f, const_iterator __l, size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
hash_multimap(const_iterator __f, const_iterator __l, size_type __n,
const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
hash_multimap(const_iterator __f, const_iterator __l, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a)
{ _M_ht.insert_equal(__f, __l); }
#endif /*__STL_MEMBER_TEMPLATES */
public:
size_type size() const { return rep.size(); }
size_type max_size() const { return rep.max_size(); }
bool empty() const { return rep.empty(); }
void swap(hash_multimap& hs) { rep.swap(hs.rep); }
size_type size() const { return _M_ht.size(); }
size_type max_size() const { return _M_ht.max_size(); }
bool empty() const { return _M_ht.empty(); }
void swap(hash_multimap& __hs) { _M_ht.swap(__hs._M_ht); }
friend bool
operator== __STL_NULL_TMPL_ARGS (const hash_multimap&, const hash_multimap&);
operator== __STL_NULL_TMPL_ARGS (const hash_multimap&,
const hash_multimap&);
iterator begin() { return rep.begin(); }
iterator end() { return rep.end(); }
const_iterator begin() const { return rep.begin(); }
const_iterator end() const { return rep.end(); }
iterator begin() { return _M_ht.begin(); }
iterator end() { return _M_ht.end(); }
const_iterator begin() const { return _M_ht.begin(); }
const_iterator end() const { return _M_ht.end(); }
public:
iterator insert(const value_type& obj) { return rep.insert_equal(obj); }
iterator insert(const value_type& __obj)
{ return _M_ht.insert_equal(__obj); }
#ifdef __STL_MEMBER_TEMPLATES
template <class InputIterator>
void insert(InputIterator f, InputIterator l) { rep.insert_equal(f,l); }
template <class _InputIterator>
void insert(_InputIterator __f, _InputIterator __l)
{ _M_ht.insert_equal(__f,__l); }
#else
void insert(const value_type* f, const value_type* l) {
rep.insert_equal(f,l);
void insert(const value_type* __f, const value_type* __l) {
_M_ht.insert_equal(__f,__l);
}
void insert(const_iterator f, const_iterator l) { rep.insert_equal(f, l); }
void insert(const_iterator __f, const_iterator __l)
{ _M_ht.insert_equal(__f, __l); }
#endif /*__STL_MEMBER_TEMPLATES */
iterator insert_noresize(const value_type& obj)
{ return rep.insert_equal_noresize(obj); }
iterator insert_noresize(const value_type& __obj)
{ return _M_ht.insert_equal_noresize(__obj); }
iterator find(const key_type& key) { return rep.find(key); }
const_iterator find(const key_type& key) const { return rep.find(key); }
iterator find(const key_type& __key) { return _M_ht.find(__key); }
const_iterator find(const key_type& __key) const
{ return _M_ht.find(__key); }
size_type count(const key_type& key) const { return rep.count(key); }
size_type count(const key_type& __key) const { return _M_ht.count(__key); }
pair<iterator, iterator> equal_range(const key_type& key)
{ return rep.equal_range(key); }
pair<const_iterator, const_iterator> equal_range(const key_type& key) const
{ return rep.equal_range(key); }
pair<iterator, iterator> equal_range(const key_type& __key)
{ return _M_ht.equal_range(__key); }
pair<const_iterator, const_iterator>
equal_range(const key_type& __key) const
{ return _M_ht.equal_range(__key); }
size_type erase(const key_type& key) {return rep.erase(key); }
void erase(iterator it) { rep.erase(it); }
void erase(iterator f, iterator l) { rep.erase(f, l); }
void clear() { rep.clear(); }
size_type erase(const key_type& __key) {return _M_ht.erase(__key); }
void erase(iterator __it) { _M_ht.erase(__it); }
void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); }
void clear() { _M_ht.clear(); }
public:
void resize(size_type hint) { rep.resize(hint); }
size_type bucket_count() const { return rep.bucket_count(); }
size_type max_bucket_count() const { return rep.max_bucket_count(); }
size_type elems_in_bucket(size_type n) const
{ return rep.elems_in_bucket(n); }
void resize(size_type __hint) { _M_ht.resize(__hint); }
size_type bucket_count() const { return _M_ht.bucket_count(); }
size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
size_type elems_in_bucket(size_type __n) const
{ return _M_ht.elems_in_bucket(__n); }
};
template <class Key, class T, class HF, class EqKey, class Alloc>
inline bool operator==(const hash_multimap<Key, T, HF, EqKey, Alloc>& hm1,
const hash_multimap<Key, T, HF, EqKey, Alloc>& hm2)
template <class _Key, class _Tp, class _HF, class _EqKey, class _Alloc>
inline bool
operator==(const hash_multimap<_Key,_Tp,_HF,_EqKey,_Alloc>& __hm1,
const hash_multimap<_Key,_Tp,_HF,_EqKey,_Alloc>& __hm2)
{
return hm1.rep == hm2.rep;
return __hm1._M_ht == __hm2._M_ht;
}
#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
template <class Key, class T, class HashFcn, class EqualKey, class Alloc>
inline void swap(hash_multimap<Key, T, HashFcn, EqualKey, Alloc>& hm1,
hash_multimap<Key, T, HashFcn, EqualKey, Alloc>& hm2)
template <class _Key, class _Tp, class _HashFcn, class _EqlKey, class _Alloc>
inline void
swap(hash_multimap<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm1,
hash_multimap<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm2)
{
hm1.swap(hm2);
__hm1.swap(__hm2);
}
#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
#pragma reset woff 1174
#pragma reset woff 1375
#endif
__STL_END_NAMESPACE

View File

@ -35,303 +35,361 @@ __STL_BEGIN_NAMESPACE
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
#pragma set woff 1174
#pragma set woff 1375
#endif
#ifndef __STL_LIMITED_DEFAULT_TEMPLATES
template <class Value, class HashFcn = hash<Value>,
class EqualKey = equal_to<Value>,
class Alloc = alloc>
template <class _Value, class _HashFcn = hash<_Value>,
class _EqualKey = equal_to<_Value>,
class _Alloc = __STL_DEFAULT_ALLOCATOR(_Value) >
#else
template <class Value, class HashFcn, class EqualKey, class Alloc = alloc>
template <class _Value, class _HashFcn, class _EqualKey,
class _Alloc = __STL_DEFAULT_ALLOCATOR(_Value) >
#endif
class hash_set
{
private:
typedef hashtable<Value, Value, HashFcn, identity<Value>,
EqualKey, Alloc> ht;
ht rep;
typedef hashtable<_Value, _Value, _HashFcn, _Identity<_Value>,
_EqualKey, _Alloc> _Ht;
_Ht _M_ht;
public:
typedef typename ht::key_type key_type;
typedef typename ht::value_type value_type;
typedef typename ht::hasher hasher;
typedef typename ht::key_equal key_equal;
typedef typename _Ht::key_type key_type;
typedef typename _Ht::value_type value_type;
typedef typename _Ht::hasher hasher;
typedef typename _Ht::key_equal key_equal;
typedef typename ht::size_type size_type;
typedef typename ht::difference_type difference_type;
typedef typename ht::const_pointer pointer;
typedef typename ht::const_pointer const_pointer;
typedef typename ht::const_reference reference;
typedef typename ht::const_reference const_reference;
typedef typename _Ht::size_type size_type;
typedef typename _Ht::difference_type difference_type;
typedef typename _Ht::const_pointer pointer;
typedef typename _Ht::const_pointer const_pointer;
typedef typename _Ht::const_reference reference;
typedef typename _Ht::const_reference const_reference;
typedef typename ht::const_iterator iterator;
typedef typename ht::const_iterator const_iterator;
typedef typename _Ht::const_iterator iterator;
typedef typename _Ht::const_iterator const_iterator;
hasher hash_funct() const { return rep.hash_funct(); }
key_equal key_eq() const { return rep.key_eq(); }
typedef typename _Ht::allocator_type allocator_type;
hasher hash_funct() const { return _M_ht.hash_funct(); }
key_equal key_eq() const { return _M_ht.key_eq(); }
allocator_type get_allocator() const { return _M_ht.get_allocator(); }
public:
hash_set() : rep(100, hasher(), key_equal()) {}
explicit hash_set(size_type n) : rep(n, hasher(), key_equal()) {}
hash_set(size_type n, const hasher& hf) : rep(n, hf, key_equal()) {}
hash_set(size_type n, const hasher& hf, const key_equal& eql)
: rep(n, hf, eql) {}
hash_set()
: _M_ht(100, hasher(), key_equal(), allocator_type()) {}
explicit hash_set(size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type()) {}
hash_set(size_type __n, const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type()) {}
hash_set(size_type __n, const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a) {}
#ifdef __STL_MEMBER_TEMPLATES
template <class InputIterator>
hash_set(InputIterator f, InputIterator l)
: rep(100, hasher(), key_equal()) { rep.insert_unique(f, l); }
template <class InputIterator>
hash_set(InputIterator f, InputIterator l, size_type n)
: rep(n, hasher(), key_equal()) { rep.insert_unique(f, l); }
template <class InputIterator>
hash_set(InputIterator f, InputIterator l, size_type n,
const hasher& hf)
: rep(n, hf, key_equal()) { rep.insert_unique(f, l); }
template <class InputIterator>
hash_set(InputIterator f, InputIterator l, size_type n,
const hasher& hf, const key_equal& eql)
: rep(n, hf, eql) { rep.insert_unique(f, l); }
template <class _InputIterator>
hash_set(_InputIterator __f, _InputIterator __l)
: _M_ht(100, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
template <class _InputIterator>
hash_set(_InputIterator __f, _InputIterator __l, size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
template <class _InputIterator>
hash_set(_InputIterator __f, _InputIterator __l, size_type __n,
const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
template <class _InputIterator>
hash_set(_InputIterator __f, _InputIterator __l, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a)
{ _M_ht.insert_unique(__f, __l); }
#else
hash_set(const value_type* f, const value_type* l)
: rep(100, hasher(), key_equal()) { rep.insert_unique(f, l); }
hash_set(const value_type* f, const value_type* l, size_type n)
: rep(n, hasher(), key_equal()) { rep.insert_unique(f, l); }
hash_set(const value_type* f, const value_type* l, size_type n,
const hasher& hf)
: rep(n, hf, key_equal()) { rep.insert_unique(f, l); }
hash_set(const value_type* f, const value_type* l, size_type n,
const hasher& hf, const key_equal& eql)
: rep(n, hf, eql) { rep.insert_unique(f, l); }
hash_set(const value_type* __f, const value_type* __l)
: _M_ht(100, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
hash_set(const value_type* __f, const value_type* __l, size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
hash_set(const value_type* __f, const value_type* __l, size_type __n,
const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
hash_set(const value_type* __f, const value_type* __l, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a)
{ _M_ht.insert_unique(__f, __l); }
hash_set(const_iterator f, const_iterator l)
: rep(100, hasher(), key_equal()) { rep.insert_unique(f, l); }
hash_set(const_iterator f, const_iterator l, size_type n)
: rep(n, hasher(), key_equal()) { rep.insert_unique(f, l); }
hash_set(const_iterator f, const_iterator l, size_type n,
const hasher& hf)
: rep(n, hf, key_equal()) { rep.insert_unique(f, l); }
hash_set(const_iterator f, const_iterator l, size_type n,
const hasher& hf, const key_equal& eql)
: rep(n, hf, eql) { rep.insert_unique(f, l); }
hash_set(const_iterator __f, const_iterator __l)
: _M_ht(100, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
hash_set(const_iterator __f, const_iterator __l, size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
hash_set(const_iterator __f, const_iterator __l, size_type __n,
const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
hash_set(const_iterator __f, const_iterator __l, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a)
{ _M_ht.insert_unique(__f, __l); }
#endif /*__STL_MEMBER_TEMPLATES */
public:
size_type size() const { return rep.size(); }
size_type max_size() const { return rep.max_size(); }
bool empty() const { return rep.empty(); }
void swap(hash_set& hs) { rep.swap(hs.rep); }
size_type size() const { return _M_ht.size(); }
size_type max_size() const { return _M_ht.max_size(); }
bool empty() const { return _M_ht.empty(); }
void swap(hash_set& __hs) { _M_ht.swap(__hs._M_ht); }
friend bool operator== __STL_NULL_TMPL_ARGS (const hash_set&,
const hash_set&);
iterator begin() const { return rep.begin(); }
iterator end() const { return rep.end(); }
iterator begin() const { return _M_ht.begin(); }
iterator end() const { return _M_ht.end(); }
public:
pair<iterator, bool> insert(const value_type& obj)
pair<iterator, bool> insert(const value_type& __obj)
{
pair<typename ht::iterator, bool> p = rep.insert_unique(obj);
return pair<iterator, bool>(p.first, p.second);
pair<typename _Ht::iterator, bool> __p = _M_ht.insert_unique(__obj);
return pair<iterator,bool>(__p.first, __p.second);
}
#ifdef __STL_MEMBER_TEMPLATES
template <class InputIterator>
void insert(InputIterator f, InputIterator l) { rep.insert_unique(f,l); }
template <class _InputIterator>
void insert(_InputIterator __f, _InputIterator __l)
{ _M_ht.insert_unique(__f,__l); }
#else
void insert(const value_type* f, const value_type* l) {
rep.insert_unique(f,l);
void insert(const value_type* __f, const value_type* __l) {
_M_ht.insert_unique(__f,__l);
}
void insert(const_iterator f, const_iterator l) {rep.insert_unique(f, l); }
void insert(const_iterator __f, const_iterator __l)
{_M_ht.insert_unique(__f, __l); }
#endif /*__STL_MEMBER_TEMPLATES */
pair<iterator, bool> insert_noresize(const value_type& obj)
pair<iterator, bool> insert_noresize(const value_type& __obj)
{
pair<typename ht::iterator, bool> p = rep.insert_unique_noresize(obj);
return pair<iterator, bool>(p.first, p.second);
pair<typename _Ht::iterator, bool> __p =
_M_ht.insert_unique_noresize(__obj);
return pair<iterator, bool>(__p.first, __p.second);
}
iterator find(const key_type& key) const { return rep.find(key); }
iterator find(const key_type& __key) const { return _M_ht.find(__key); }
size_type count(const key_type& key) const { return rep.count(key); }
size_type count(const key_type& __key) const { return _M_ht.count(__key); }
pair<iterator, iterator> equal_range(const key_type& key) const
{ return rep.equal_range(key); }
pair<iterator, iterator> equal_range(const key_type& __key) const
{ return _M_ht.equal_range(__key); }
size_type erase(const key_type& key) {return rep.erase(key); }
void erase(iterator it) { rep.erase(it); }
void erase(iterator f, iterator l) { rep.erase(f, l); }
void clear() { rep.clear(); }
size_type erase(const key_type& __key) {return _M_ht.erase(__key); }
void erase(iterator __it) { _M_ht.erase(__it); }
void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); }
void clear() { _M_ht.clear(); }
public:
void resize(size_type hint) { rep.resize(hint); }
size_type bucket_count() const { return rep.bucket_count(); }
size_type max_bucket_count() const { return rep.max_bucket_count(); }
size_type elems_in_bucket(size_type n) const
{ return rep.elems_in_bucket(n); }
void resize(size_type __hint) { _M_ht.resize(__hint); }
size_type bucket_count() const { return _M_ht.bucket_count(); }
size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
size_type elems_in_bucket(size_type __n) const
{ return _M_ht.elems_in_bucket(__n); }
};
template <class Value, class HashFcn, class EqualKey, class Alloc>
inline bool operator==(const hash_set<Value, HashFcn, EqualKey, Alloc>& hs1,
const hash_set<Value, HashFcn, EqualKey, Alloc>& hs2)
template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
inline bool
operator==(const hash_set<_Value,_HashFcn,_EqualKey,_Alloc>& __hs1,
const hash_set<_Value,_HashFcn,_EqualKey,_Alloc>& __hs2)
{
return hs1.rep == hs2.rep;
return __hs1._M_ht == __hs2._M_ht;
}
#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
template <class Val, class HashFcn, class EqualKey, class Alloc>
inline void swap(hash_set<Val, HashFcn, EqualKey, Alloc>& hs1,
hash_set<Val, HashFcn, EqualKey, Alloc>& hs2) {
hs1.swap(hs2);
template <class _Val, class _HashFcn, class _EqualKey, class _Alloc>
inline void
swap(hash_set<_Val,_HashFcn,_EqualKey,_Alloc>& __hs1,
hash_set<_Val,_HashFcn,_EqualKey,_Alloc>& __hs2)
{
__hs1.swap(__hs2);
}
#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
#ifndef __STL_LIMITED_DEFAULT_TEMPLATES
template <class Value, class HashFcn = hash<Value>,
class EqualKey = equal_to<Value>,
class Alloc = alloc>
template <class _Value, class _HashFcn = hash<_Value>,
class _EqualKey = equal_to<_Value>,
class _Alloc = __STL_DEFAULT_ALLOCATOR(_Value) >
#else
template <class Value, class HashFcn, class EqualKey, class Alloc = alloc>
template <class _Value, class _HashFcn, class _EqualKey,
class _Alloc = __STL_DEFAULT_ALLOCATOR(_Value) >
#endif
class hash_multiset
{
private:
typedef hashtable<Value, Value, HashFcn, identity<Value>,
EqualKey, Alloc> ht;
ht rep;
typedef hashtable<_Value, _Value, _HashFcn, _Identity<_Value>,
_EqualKey, _Alloc> _Ht;
_Ht _M_ht;
public:
typedef typename ht::key_type key_type;
typedef typename ht::value_type value_type;
typedef typename ht::hasher hasher;
typedef typename ht::key_equal key_equal;
typedef typename _Ht::key_type key_type;
typedef typename _Ht::value_type value_type;
typedef typename _Ht::hasher hasher;
typedef typename _Ht::key_equal key_equal;
typedef typename ht::size_type size_type;
typedef typename ht::difference_type difference_type;
typedef typename ht::const_pointer pointer;
typedef typename ht::const_pointer const_pointer;
typedef typename ht::const_reference reference;
typedef typename ht::const_reference const_reference;
typedef typename _Ht::size_type size_type;
typedef typename _Ht::difference_type difference_type;
typedef typename _Ht::const_pointer pointer;
typedef typename _Ht::const_pointer const_pointer;
typedef typename _Ht::const_reference reference;
typedef typename _Ht::const_reference const_reference;
typedef typename ht::const_iterator iterator;
typedef typename ht::const_iterator const_iterator;
typedef typename _Ht::const_iterator iterator;
typedef typename _Ht::const_iterator const_iterator;
hasher hash_funct() const { return rep.hash_funct(); }
key_equal key_eq() const { return rep.key_eq(); }
typedef typename _Ht::allocator_type allocator_type;
hasher hash_funct() const { return _M_ht.hash_funct(); }
key_equal key_eq() const { return _M_ht.key_eq(); }
allocator_type get_allocator() const { return _M_ht.get_allocator(); }
public:
hash_multiset() : rep(100, hasher(), key_equal()) {}
explicit hash_multiset(size_type n) : rep(n, hasher(), key_equal()) {}
hash_multiset(size_type n, const hasher& hf) : rep(n, hf, key_equal()) {}
hash_multiset(size_type n, const hasher& hf, const key_equal& eql)
: rep(n, hf, eql) {}
hash_multiset()
: _M_ht(100, hasher(), key_equal(), allocator_type()) {}
explicit hash_multiset(size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type()) {}
hash_multiset(size_type __n, const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type()) {}
hash_multiset(size_type __n, const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a) {}
#ifdef __STL_MEMBER_TEMPLATES
template <class InputIterator>
hash_multiset(InputIterator f, InputIterator l)
: rep(100, hasher(), key_equal()) { rep.insert_equal(f, l); }
template <class InputIterator>
hash_multiset(InputIterator f, InputIterator l, size_type n)
: rep(n, hasher(), key_equal()) { rep.insert_equal(f, l); }
template <class InputIterator>
hash_multiset(InputIterator f, InputIterator l, size_type n,
const hasher& hf)
: rep(n, hf, key_equal()) { rep.insert_equal(f, l); }
template <class InputIterator>
hash_multiset(InputIterator f, InputIterator l, size_type n,
const hasher& hf, const key_equal& eql)
: rep(n, hf, eql) { rep.insert_equal(f, l); }
template <class _InputIterator>
hash_multiset(_InputIterator __f, _InputIterator __l)
: _M_ht(100, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
template <class _InputIterator>
hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
template <class _InputIterator>
hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n,
const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
template <class _InputIterator>
hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a)
{ _M_ht.insert_equal(__f, __l); }
#else
hash_multiset(const value_type* f, const value_type* l)
: rep(100, hasher(), key_equal()) { rep.insert_equal(f, l); }
hash_multiset(const value_type* f, const value_type* l, size_type n)
: rep(n, hasher(), key_equal()) { rep.insert_equal(f, l); }
hash_multiset(const value_type* f, const value_type* l, size_type n,
const hasher& hf)
: rep(n, hf, key_equal()) { rep.insert_equal(f, l); }
hash_multiset(const value_type* f, const value_type* l, size_type n,
const hasher& hf, const key_equal& eql)
: rep(n, hf, eql) { rep.insert_equal(f, l); }
hash_multiset(const value_type* __f, const value_type* __l)
: _M_ht(100, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
hash_multiset(const value_type* __f, const value_type* __l, size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
hash_multiset(const value_type* __f, const value_type* __l, size_type __n,
const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
hash_multiset(const value_type* __f, const value_type* __l, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a)
{ _M_ht.insert_equal(__f, __l); }
hash_multiset(const_iterator f, const_iterator l)
: rep(100, hasher(), key_equal()) { rep.insert_equal(f, l); }
hash_multiset(const_iterator f, const_iterator l, size_type n)
: rep(n, hasher(), key_equal()) { rep.insert_equal(f, l); }
hash_multiset(const_iterator f, const_iterator l, size_type n,
const hasher& hf)
: rep(n, hf, key_equal()) { rep.insert_equal(f, l); }
hash_multiset(const_iterator f, const_iterator l, size_type n,
const hasher& hf, const key_equal& eql)
: rep(n, hf, eql) { rep.insert_equal(f, l); }
hash_multiset(const_iterator __f, const_iterator __l)
: _M_ht(100, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
hash_multiset(const_iterator __f, const_iterator __l, size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
hash_multiset(const_iterator __f, const_iterator __l, size_type __n,
const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
hash_multiset(const_iterator __f, const_iterator __l, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a)
{ _M_ht.insert_equal(__f, __l); }
#endif /*__STL_MEMBER_TEMPLATES */
public:
size_type size() const { return rep.size(); }
size_type max_size() const { return rep.max_size(); }
bool empty() const { return rep.empty(); }
void swap(hash_multiset& hs) { rep.swap(hs.rep); }
size_type size() const { return _M_ht.size(); }
size_type max_size() const { return _M_ht.max_size(); }
bool empty() const { return _M_ht.empty(); }
void swap(hash_multiset& hs) { _M_ht.swap(hs._M_ht); }
friend bool operator== __STL_NULL_TMPL_ARGS (const hash_multiset&,
const hash_multiset&);
iterator begin() const { return rep.begin(); }
iterator end() const { return rep.end(); }
iterator begin() const { return _M_ht.begin(); }
iterator end() const { return _M_ht.end(); }
public:
iterator insert(const value_type& obj) { return rep.insert_equal(obj); }
iterator insert(const value_type& __obj)
{ return _M_ht.insert_equal(__obj); }
#ifdef __STL_MEMBER_TEMPLATES
template <class InputIterator>
void insert(InputIterator f, InputIterator l) { rep.insert_equal(f,l); }
template <class _InputIterator>
void insert(_InputIterator __f, _InputIterator __l)
{ _M_ht.insert_equal(__f,__l); }
#else
void insert(const value_type* f, const value_type* l) {
rep.insert_equal(f,l);
void insert(const value_type* __f, const value_type* __l) {
_M_ht.insert_equal(__f,__l);
}
void insert(const_iterator f, const_iterator l) { rep.insert_equal(f, l); }
void insert(const_iterator __f, const_iterator __l)
{ _M_ht.insert_equal(__f, __l); }
#endif /*__STL_MEMBER_TEMPLATES */
iterator insert_noresize(const value_type& obj)
{ return rep.insert_equal_noresize(obj); }
iterator insert_noresize(const value_type& __obj)
{ return _M_ht.insert_equal_noresize(__obj); }
iterator find(const key_type& key) const { return rep.find(key); }
iterator find(const key_type& __key) const { return _M_ht.find(__key); }
size_type count(const key_type& key) const { return rep.count(key); }
size_type count(const key_type& __key) const { return _M_ht.count(__key); }
pair<iterator, iterator> equal_range(const key_type& key) const
{ return rep.equal_range(key); }
pair<iterator, iterator> equal_range(const key_type& __key) const
{ return _M_ht.equal_range(__key); }
size_type erase(const key_type& key) {return rep.erase(key); }
void erase(iterator it) { rep.erase(it); }
void erase(iterator f, iterator l) { rep.erase(f, l); }
void clear() { rep.clear(); }
size_type erase(const key_type& __key) {return _M_ht.erase(__key); }
void erase(iterator __it) { _M_ht.erase(__it); }
void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); }
void clear() { _M_ht.clear(); }
public:
void resize(size_type hint) { rep.resize(hint); }
size_type bucket_count() const { return rep.bucket_count(); }
size_type max_bucket_count() const { return rep.max_bucket_count(); }
size_type elems_in_bucket(size_type n) const
{ return rep.elems_in_bucket(n); }
void resize(size_type __hint) { _M_ht.resize(__hint); }
size_type bucket_count() const { return _M_ht.bucket_count(); }
size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
size_type elems_in_bucket(size_type __n) const
{ return _M_ht.elems_in_bucket(__n); }
};
template <class Val, class HashFcn, class EqualKey, class Alloc>
inline bool operator==(const hash_multiset<Val, HashFcn, EqualKey, Alloc>& hs1,
const hash_multiset<Val, HashFcn, EqualKey, Alloc>& hs2)
template <class _Val, class _HashFcn, class _EqualKey, class _Alloc>
inline bool
operator==(const hash_multiset<_Val,_HashFcn,_EqualKey,_Alloc>& __hs1,
const hash_multiset<_Val,_HashFcn,_EqualKey,_Alloc>& __hs2)
{
return hs1.rep == hs2.rep;
return __hs1._M_ht == __hs2._M_ht;
}
#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
template <class Val, class HashFcn, class EqualKey, class Alloc>
inline void swap(hash_multiset<Val, HashFcn, EqualKey, Alloc>& hs1,
hash_multiset<Val, HashFcn, EqualKey, Alloc>& hs2)
{
hs1.swap(hs2);
template <class _Val, class _HashFcn, class _EqualKey, class _Alloc>
inline void
swap(hash_multiset<_Val,_HashFcn,_EqualKey,_Alloc>& __hs1,
hash_multiset<_Val,_HashFcn,_EqualKey,_Alloc>& __hs2) {
__hs1.swap(__hs2);
}
#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
#pragma reset woff 1174
#pragma reset woff 1375
#endif
__STL_END_NAMESPACE

File diff suppressed because it is too large Load Diff

View File

@ -36,181 +36,236 @@ __STL_BEGIN_NAMESPACE
#pragma set woff 1209
#endif
template <class RandomAccessIterator, class Distance, class T>
void __push_heap(RandomAccessIterator first, Distance holeIndex,
Distance topIndex, T value) {
Distance parent = (holeIndex - 1) / 2;
while (holeIndex > topIndex && *(first + parent) < value) {
*(first + holeIndex) = *(first + parent);
holeIndex = parent;
parent = (holeIndex - 1) / 2;
// Heap-manipulation functions: push_heap, pop_heap, make_heap, sort_heap.
template <class _RandomAccessIterator, class _Distance, class _Tp>
void
__push_heap(_RandomAccessIterator __first,
_Distance __holeIndex, _Distance __topIndex, _Tp __value)
{
_Distance __parent = (__holeIndex - 1) / 2;
while (__holeIndex > __topIndex && *(__first + __parent) < __value) {
*(__first + __holeIndex) = *(__first + __parent);
__holeIndex = __parent;
__parent = (__holeIndex - 1) / 2;
}
*(first + holeIndex) = value;
*(__first + __holeIndex) = __value;
}
template <class RandomAccessIterator, class Distance, class T>
inline void __push_heap_aux(RandomAccessIterator first,
RandomAccessIterator last, Distance*, T*) {
__push_heap(first, Distance((last - first) - 1), Distance(0),
T(*(last - 1)));
template <class _RandomAccessIterator, class _Distance, class _Tp>
inline void
__push_heap_aux(_RandomAccessIterator __first,
_RandomAccessIterator __last, _Distance*, _Tp*)
{
__push_heap(__first, _Distance((__last - __first) - 1), _Distance(0),
_Tp(*(__last - 1)));
}
template <class RandomAccessIterator>
inline void push_heap(RandomAccessIterator first, RandomAccessIterator last) {
__push_heap_aux(first, last, distance_type(first), value_type(first));
template <class _RandomAccessIterator>
inline void
push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
__push_heap_aux(__first, __last,
__DISTANCE_TYPE(__first), __VALUE_TYPE(__first));
}
template <class RandomAccessIterator, class Distance, class T, class Compare>
void __push_heap(RandomAccessIterator first, Distance holeIndex,
Distance topIndex, T value, Compare comp) {
Distance parent = (holeIndex - 1) / 2;
while (holeIndex > topIndex && comp(*(first + parent), value)) {
*(first + holeIndex) = *(first + parent);
holeIndex = parent;
parent = (holeIndex - 1) / 2;
template <class _RandomAccessIterator, class _Distance, class _Tp,
class _Compare>
void
__push_heap(_RandomAccessIterator __first, _Distance __holeIndex,
_Distance __topIndex, _Tp __value, _Compare __comp)
{
_Distance __parent = (__holeIndex - 1) / 2;
while (__holeIndex > __topIndex && __comp(*(__first + __parent), __value)) {
*(__first + __holeIndex) = *(__first + __parent);
__holeIndex = __parent;
__parent = (__holeIndex - 1) / 2;
}
*(first + holeIndex) = value;
*(__first + __holeIndex) = __value;
}
template <class RandomAccessIterator, class Compare, class Distance, class T>
inline void __push_heap_aux(RandomAccessIterator first,
RandomAccessIterator last, Compare comp,
Distance*, T*) {
__push_heap(first, Distance((last - first) - 1), Distance(0),
T(*(last - 1)), comp);
template <class _RandomAccessIterator, class _Compare,
class _Distance, class _Tp>
inline void
__push_heap_aux(_RandomAccessIterator __first,
_RandomAccessIterator __last, _Compare __comp,
_Distance*, _Tp*)
{
__push_heap(__first, _Distance((__last - __first) - 1), _Distance(0),
_Tp(*(__last - 1)), __comp);
}
template <class RandomAccessIterator, class Compare>
inline void push_heap(RandomAccessIterator first, RandomAccessIterator last,
Compare comp) {
__push_heap_aux(first, last, comp, distance_type(first), value_type(first));
template <class _RandomAccessIterator, class _Compare>
inline void
push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
_Compare __comp)
{
__push_heap_aux(__first, __last, __comp,
__DISTANCE_TYPE(__first), __VALUE_TYPE(__first));
}
template <class RandomAccessIterator, class Distance, class T>
void __adjust_heap(RandomAccessIterator first, Distance holeIndex,
Distance len, T value) {
Distance topIndex = holeIndex;
Distance secondChild = 2 * holeIndex + 2;
while (secondChild < len) {
if (*(first + secondChild) < *(first + (secondChild - 1)))
secondChild--;
*(first + holeIndex) = *(first + secondChild);
holeIndex = secondChild;
secondChild = 2 * (secondChild + 1);
template <class _RandomAccessIterator, class _Distance, class _Tp>
void
__adjust_heap(_RandomAccessIterator __first, _Distance __holeIndex,
_Distance __len, _Tp __value)
{
_Distance __topIndex = __holeIndex;
_Distance __secondChild = 2 * __holeIndex + 2;
while (__secondChild < __len) {
if (*(__first + __secondChild) < *(__first + (__secondChild - 1)))
__secondChild--;
*(__first + __holeIndex) = *(__first + __secondChild);
__holeIndex = __secondChild;
__secondChild = 2 * (__secondChild + 1);
}
if (secondChild == len) {
*(first + holeIndex) = *(first + (secondChild - 1));
holeIndex = secondChild - 1;
if (__secondChild == __len) {
*(__first + __holeIndex) = *(__first + (__secondChild - 1));
__holeIndex = __secondChild - 1;
}
__push_heap(first, holeIndex, topIndex, value);
__push_heap(__first, __holeIndex, __topIndex, __value);
}
template <class RandomAccessIterator, class T, class Distance>
inline void __pop_heap(RandomAccessIterator first, RandomAccessIterator last,
RandomAccessIterator result, T value, Distance*) {
*result = *first;
__adjust_heap(first, Distance(0), Distance(last - first), value);
template <class _RandomAccessIterator, class _Tp, class _Distance>
inline void
__pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
_RandomAccessIterator __result, _Tp __value, _Distance*)
{
*__result = *__first;
__adjust_heap(__first, _Distance(0), _Distance(__last - __first), __value);
}
template <class RandomAccessIterator, class T>
inline void __pop_heap_aux(RandomAccessIterator first,
RandomAccessIterator last, T*) {
__pop_heap(first, last - 1, last - 1, T(*(last - 1)), distance_type(first));
template <class _RandomAccessIterator, class _Tp>
inline void
__pop_heap_aux(_RandomAccessIterator __first, _RandomAccessIterator __last,
_Tp*)
{
__pop_heap(__first, __last - 1, __last - 1,
_Tp(*(__last - 1)), __DISTANCE_TYPE(__first));
}
template <class RandomAccessIterator>
inline void pop_heap(RandomAccessIterator first, RandomAccessIterator last) {
__pop_heap_aux(first, last, value_type(first));
template <class _RandomAccessIterator>
inline void pop_heap(_RandomAccessIterator __first,
_RandomAccessIterator __last)
{
__pop_heap_aux(__first, __last, __VALUE_TYPE(__first));
}
template <class RandomAccessIterator, class Distance, class T, class Compare>
void __adjust_heap(RandomAccessIterator first, Distance holeIndex,
Distance len, T value, Compare comp) {
Distance topIndex = holeIndex;
Distance secondChild = 2 * holeIndex + 2;
while (secondChild < len) {
if (comp(*(first + secondChild), *(first + (secondChild - 1))))
secondChild--;
*(first + holeIndex) = *(first + secondChild);
holeIndex = secondChild;
secondChild = 2 * (secondChild + 1);
template <class _RandomAccessIterator, class _Distance,
class _Tp, class _Compare>
void
__adjust_heap(_RandomAccessIterator __first, _Distance __holeIndex,
_Distance __len, _Tp __value, _Compare __comp)
{
_Distance __topIndex = __holeIndex;
_Distance __secondChild = 2 * __holeIndex + 2;
while (__secondChild < __len) {
if (__comp(*(__first + __secondChild), *(__first + (__secondChild - 1))))
__secondChild--;
*(__first + __holeIndex) = *(__first + __secondChild);
__holeIndex = __secondChild;
__secondChild = 2 * (__secondChild + 1);
}
if (secondChild == len) {
*(first + holeIndex) = *(first + (secondChild - 1));
holeIndex = secondChild - 1;
if (__secondChild == __len) {
*(__first + __holeIndex) = *(__first + (__secondChild - 1));
__holeIndex = __secondChild - 1;
}
__push_heap(first, holeIndex, topIndex, value, comp);
__push_heap(__first, __holeIndex, __topIndex, __value, __comp);
}
template <class RandomAccessIterator, class T, class Compare, class Distance>
inline void __pop_heap(RandomAccessIterator first, RandomAccessIterator last,
RandomAccessIterator result, T value, Compare comp,
Distance*) {
*result = *first;
__adjust_heap(first, Distance(0), Distance(last - first), value, comp);
template <class _RandomAccessIterator, class _Tp, class _Compare,
class _Distance>
inline void
__pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
_RandomAccessIterator __result, _Tp __value, _Compare __comp,
_Distance*)
{
*__result = *__first;
__adjust_heap(__first, _Distance(0), _Distance(__last - __first),
__value, __comp);
}
template <class RandomAccessIterator, class T, class Compare>
inline void __pop_heap_aux(RandomAccessIterator first,
RandomAccessIterator last, T*, Compare comp) {
__pop_heap(first, last - 1, last - 1, T(*(last - 1)), comp,
distance_type(first));
template <class _RandomAccessIterator, class _Tp, class _Compare>
inline void
__pop_heap_aux(_RandomAccessIterator __first,
_RandomAccessIterator __last, _Tp*, _Compare __comp)
{
__pop_heap(__first, __last - 1, __last - 1, _Tp(*(__last - 1)), __comp,
__DISTANCE_TYPE(__first));
}
template <class RandomAccessIterator, class Compare>
inline void pop_heap(RandomAccessIterator first, RandomAccessIterator last,
Compare comp) {
__pop_heap_aux(first, last, value_type(first), comp);
template <class _RandomAccessIterator, class _Compare>
inline void
pop_heap(_RandomAccessIterator __first,
_RandomAccessIterator __last, _Compare __comp)
{
__pop_heap_aux(__first, __last, __VALUE_TYPE(__first), __comp);
}
template <class RandomAccessIterator, class T, class Distance>
void __make_heap(RandomAccessIterator first, RandomAccessIterator last, T*,
Distance*) {
if (last - first < 2) return;
Distance len = last - first;
Distance parent = (len - 2)/2;
template <class _RandomAccessIterator, class _Tp, class _Distance>
void
__make_heap(_RandomAccessIterator __first,
_RandomAccessIterator __last, _Tp*, _Distance*)
{
if (__last - __first < 2) return;
_Distance __len = __last - __first;
_Distance __parent = (__len - 2)/2;
while (true) {
__adjust_heap(first, parent, len, T(*(first + parent)));
if (parent == 0) return;
parent--;
__adjust_heap(__first, __parent, __len, _Tp(*(__first + __parent)));
if (__parent == 0) return;
__parent--;
}
}
template <class RandomAccessIterator>
inline void make_heap(RandomAccessIterator first, RandomAccessIterator last) {
__make_heap(first, last, value_type(first), distance_type(first));
template <class _RandomAccessIterator>
inline void
make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
__make_heap(__first, __last,
__VALUE_TYPE(__first), __DISTANCE_TYPE(__first));
}
template <class RandomAccessIterator, class Compare, class T, class Distance>
void __make_heap(RandomAccessIterator first, RandomAccessIterator last,
Compare comp, T*, Distance*) {
if (last - first < 2) return;
Distance len = last - first;
Distance parent = (len - 2)/2;
template <class _RandomAccessIterator, class _Compare,
class _Tp, class _Distance>
void
__make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
_Compare __comp, _Tp*, _Distance*)
{
if (__last - __first < 2) return;
_Distance __len = __last - __first;
_Distance __parent = (__len - 2)/2;
while (true) {
__adjust_heap(first, parent, len, T(*(first + parent)), comp);
if (parent == 0) return;
parent--;
__adjust_heap(__first, __parent, __len, _Tp(*(__first + __parent)),
__comp);
if (__parent == 0) return;
__parent--;
}
}
template <class RandomAccessIterator, class Compare>
inline void make_heap(RandomAccessIterator first, RandomAccessIterator last,
Compare comp) {
__make_heap(first, last, comp, value_type(first), distance_type(first));
template <class _RandomAccessIterator, class _Compare>
inline void
make_heap(_RandomAccessIterator __first,
_RandomAccessIterator __last, _Compare __comp)
{
__make_heap(__first, __last, __comp,
__VALUE_TYPE(__first), __DISTANCE_TYPE(__first));
}
template <class RandomAccessIterator>
void sort_heap(RandomAccessIterator first, RandomAccessIterator last) {
while (last - first > 1) pop_heap(first, last--);
template <class _RandomAccessIterator>
void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
while (__last - __first > 1)
pop_heap(__first, __last--);
}
template <class RandomAccessIterator, class Compare>
void sort_heap(RandomAccessIterator first, RandomAccessIterator last,
Compare comp) {
while (last - first > 1) pop_heap(first, last--, comp);
template <class _RandomAccessIterator, class _Compare>
void
sort_heap(_RandomAccessIterator __first,
_RandomAccessIterator __last, _Compare __comp)
{
while (__last - __first > 1)
pop_heap(__first, __last--, __comp);
}
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -35,177 +35,202 @@ __STL_BEGIN_NAMESPACE
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
#pragma set woff 1174
#pragma set woff 1375
#endif
#ifndef __STL_LIMITED_DEFAULT_TEMPLATES
template <class Key, class T, class Compare = less<Key>, class Alloc = alloc>
template <class _Key, class _Tp, class _Compare = less<_Key>,
class _Alloc = __STL_DEFAULT_ALLOCATOR(_Tp) >
#else
template <class Key, class T, class Compare, class Alloc = alloc>
template <class _Key, class _Tp, class _Compare,
class _Alloc = __STL_DEFAULT_ALLOCATOR(_Tp) >
#endif
class map {
public:
// typedefs:
typedef Key key_type;
typedef T data_type;
typedef T mapped_type;
typedef pair<const Key, T> value_type;
typedef Compare key_compare;
typedef _Key key_type;
typedef _Tp data_type;
typedef _Tp mapped_type;
typedef pair<const _Key, _Tp> value_type;
typedef _Compare key_compare;
class value_compare
: public binary_function<value_type, value_type, bool> {
friend class map<Key, T, Compare, Alloc>;
friend class map<_Key,_Tp,_Compare,_Alloc>;
protected :
Compare comp;
value_compare(Compare c) : comp(c) {}
_Compare _M_comp;
value_compare(_Compare __c) : _M_comp(__c) {}
public:
bool operator()(const value_type& x, const value_type& y) const {
return comp(x.first, y.first);
bool operator()(const value_type& __x, const value_type& __y) const {
return _M_comp(__x.first, __y.first);
}
};
private:
typedef rb_tree<key_type, value_type,
select1st<value_type>, key_compare, Alloc> rep_type;
rep_type t; // red-black tree representing map
typedef _Rb_tree<key_type, value_type,
_Select1st<value_type>, key_compare, _Alloc> _Rep_type;
_Rep_type _M_t; // red-black tree representing map
public:
typedef typename rep_type::pointer pointer;
typedef typename rep_type::const_pointer const_pointer;
typedef typename rep_type::reference reference;
typedef typename rep_type::const_reference const_reference;
typedef typename rep_type::iterator iterator;
typedef typename rep_type::const_iterator const_iterator;
typedef typename rep_type::reverse_iterator reverse_iterator;
typedef typename rep_type::const_reverse_iterator const_reverse_iterator;
typedef typename rep_type::size_type size_type;
typedef typename rep_type::difference_type difference_type;
typedef typename _Rep_type::pointer pointer;
typedef typename _Rep_type::const_pointer const_pointer;
typedef typename _Rep_type::reference reference;
typedef typename _Rep_type::const_reference const_reference;
typedef typename _Rep_type::iterator iterator;
typedef typename _Rep_type::const_iterator const_iterator;
typedef typename _Rep_type::reverse_iterator reverse_iterator;
typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
typedef typename _Rep_type::size_type size_type;
typedef typename _Rep_type::difference_type difference_type;
typedef typename _Rep_type::allocator_type allocator_type;
// allocation/deallocation
map() : t(Compare()) {}
explicit map(const Compare& comp) : t(comp) {}
map() : _M_t(_Compare(), allocator_type()) {}
explicit map(const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) {}
#ifdef __STL_MEMBER_TEMPLATES
template <class InputIterator>
map(InputIterator first, InputIterator last)
: t(Compare()) { t.insert_unique(first, last); }
template <class _InputIterator>
map(_InputIterator __first, _InputIterator __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_unique(__first, __last); }
template <class InputIterator>
map(InputIterator first, InputIterator last, const Compare& comp)
: t(comp) { t.insert_unique(first, last); }
template <class _InputIterator>
map(_InputIterator __first, _InputIterator __last, const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
#else
map(const value_type* first, const value_type* last)
: t(Compare()) { t.insert_unique(first, last); }
map(const value_type* first, const value_type* last, const Compare& comp)
: t(comp) { t.insert_unique(first, last); }
map(const value_type* __first, const value_type* __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_unique(__first, __last); }
map(const value_type* __first,
const value_type* __last, const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
map(const_iterator __first, const_iterator __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_unique(__first, __last); }
map(const_iterator __first, const_iterator __last, const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
map(const_iterator first, const_iterator last)
: t(Compare()) { t.insert_unique(first, last); }
map(const_iterator first, const_iterator last, const Compare& comp)
: t(comp) { t.insert_unique(first, last); }
#endif /* __STL_MEMBER_TEMPLATES */
map(const map<Key, T, Compare, Alloc>& x) : t(x.t) {}
map<Key, T, Compare, Alloc>& operator=(const map<Key, T, Compare, Alloc>& x)
map(const map<_Key,_Tp,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {}
map<_Key,_Tp,_Compare,_Alloc>&
operator=(const map<_Key, _Tp, _Compare, _Alloc>& __x)
{
t = x.t;
_M_t = __x._M_t;
return *this;
}
// accessors:
key_compare key_comp() const { return t.key_comp(); }
value_compare value_comp() const { return value_compare(t.key_comp()); }
iterator begin() { return t.begin(); }
const_iterator begin() const { return t.begin(); }
iterator end() { return t.end(); }
const_iterator end() const { return t.end(); }
reverse_iterator rbegin() { return t.rbegin(); }
const_reverse_iterator rbegin() const { return t.rbegin(); }
reverse_iterator rend() { return t.rend(); }
const_reverse_iterator rend() const { return t.rend(); }
bool empty() const { return t.empty(); }
size_type size() const { return t.size(); }
size_type max_size() const { return t.max_size(); }
T& operator[](const key_type& k) {
return (*((insert(value_type(k, T()))).first)).second;
key_compare key_comp() const { return _M_t.key_comp(); }
value_compare value_comp() const { return value_compare(_M_t.key_comp()); }
allocator_type get_allocator() const { return _M_t.get_allocator(); }
iterator begin() { return _M_t.begin(); }
const_iterator begin() const { return _M_t.begin(); }
iterator end() { return _M_t.end(); }
const_iterator end() const { return _M_t.end(); }
reverse_iterator rbegin() { return _M_t.rbegin(); }
const_reverse_iterator rbegin() const { return _M_t.rbegin(); }
reverse_iterator rend() { return _M_t.rend(); }
const_reverse_iterator rend() const { return _M_t.rend(); }
bool empty() const { return _M_t.empty(); }
size_type size() const { return _M_t.size(); }
size_type max_size() const { return _M_t.max_size(); }
_Tp& operator[](const key_type& __k) {
iterator __i = lower_bound(__k);
// __i->first is greater than or equivalent to __k.
if (__i == end() || key_comp()(__k, (*__i).first))
__i = insert(__i, value_type(__k, _Tp()));
return (*__i).second;
}
void swap(map<Key, T, Compare, Alloc>& x) { t.swap(x.t); }
void swap(map<_Key,_Tp,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
// insert/erase
pair<iterator,bool> insert(const value_type& x) { return t.insert_unique(x); }
iterator insert(iterator position, const value_type& x) {
return t.insert_unique(position, x);
}
pair<iterator,bool> insert(const value_type& __x)
{ return _M_t.insert_unique(__x); }
iterator insert(iterator position, const value_type& __x)
{ return _M_t.insert_unique(position, __x); }
#ifdef __STL_MEMBER_TEMPLATES
template <class InputIterator>
void insert(InputIterator first, InputIterator last) {
t.insert_unique(first, last);
template <class _InputIterator>
void insert(_InputIterator __first, _InputIterator __last) {
_M_t.insert_unique(__first, __last);
}
#else
void insert(const value_type* first, const value_type* last) {
t.insert_unique(first, last);
void insert(const value_type* __first, const value_type* __last) {
_M_t.insert_unique(__first, __last);
}
void insert(const_iterator first, const_iterator last) {
t.insert_unique(first, last);
void insert(const_iterator __first, const_iterator __last) {
_M_t.insert_unique(__first, __last);
}
#endif /* __STL_MEMBER_TEMPLATES */
void erase(iterator position) { t.erase(position); }
size_type erase(const key_type& x) { return t.erase(x); }
void erase(iterator first, iterator last) { t.erase(first, last); }
void clear() { t.clear(); }
void erase(iterator __position) { _M_t.erase(__position); }
size_type erase(const key_type& __x) { return _M_t.erase(__x); }
void erase(iterator __first, iterator __last)
{ _M_t.erase(__first, __last); }
void clear() { _M_t.clear(); }
// map operations:
iterator find(const key_type& x) { return t.find(x); }
const_iterator find(const key_type& x) const { return t.find(x); }
size_type count(const key_type& x) const { return t.count(x); }
iterator lower_bound(const key_type& x) {return t.lower_bound(x); }
const_iterator lower_bound(const key_type& x) const {
return t.lower_bound(x);
iterator find(const key_type& __x) { return _M_t.find(__x); }
const_iterator find(const key_type& __x) const { return _M_t.find(__x); }
size_type count(const key_type& __x) const { return _M_t.count(__x); }
iterator lower_bound(const key_type& __x) {return _M_t.lower_bound(__x); }
const_iterator lower_bound(const key_type& __x) const {
return _M_t.lower_bound(__x);
}
iterator upper_bound(const key_type& x) {return t.upper_bound(x); }
const_iterator upper_bound(const key_type& x) const {
return t.upper_bound(x);
iterator upper_bound(const key_type& __x) {return _M_t.upper_bound(__x); }
const_iterator upper_bound(const key_type& __x) const {
return _M_t.upper_bound(__x);
}
pair<iterator,iterator> equal_range(const key_type& x) {
return t.equal_range(x);
pair<iterator,iterator> equal_range(const key_type& __x) {
return _M_t.equal_range(__x);
}
pair<const_iterator,const_iterator> equal_range(const key_type& x) const {
return t.equal_range(x);
pair<const_iterator,const_iterator> equal_range(const key_type& __x) const {
return _M_t.equal_range(__x);
}
friend bool operator== __STL_NULL_TMPL_ARGS (const map&, const map&);
friend bool operator< __STL_NULL_TMPL_ARGS (const map&, const map&);
};
template <class Key, class T, class Compare, class Alloc>
inline bool operator==(const map<Key, T, Compare, Alloc>& x,
const map<Key, T, Compare, Alloc>& y) {
return x.t == y.t;
template <class _Key, class _Tp, class _Compare, class _Alloc>
inline bool operator==(const map<_Key,_Tp,_Compare,_Alloc>& __x,
const map<_Key,_Tp,_Compare,_Alloc>& __y) {
return __x._M_t == __y._M_t;
}
template <class Key, class T, class Compare, class Alloc>
inline bool operator<(const map<Key, T, Compare, Alloc>& x,
const map<Key, T, Compare, Alloc>& y) {
return x.t < y.t;
template <class _Key, class _Tp, class _Compare, class _Alloc>
inline bool operator<(const map<_Key,_Tp,_Compare,_Alloc>& __x,
const map<_Key,_Tp,_Compare,_Alloc>& __y) {
return __x._M_t < __y._M_t;
}
#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
template <class Key, class T, class Compare, class Alloc>
inline void swap(map<Key, T, Compare, Alloc>& x,
map<Key, T, Compare, Alloc>& y) {
x.swap(y);
template <class _Key, class _Tp, class _Compare, class _Alloc>
inline void swap(map<_Key,_Tp,_Compare,_Alloc>& __x,
map<_Key,_Tp,_Compare,_Alloc>& __y) {
__x.swap(__y);
}
#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
#pragma reset woff 1174
#pragma reset woff 1375
#endif
__STL_END_NAMESPACE

View File

@ -35,143 +35,160 @@ __STL_BEGIN_NAMESPACE
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
#pragma set woff 1174
#pragma set woff 1375
#endif
#ifndef __STL_LIMITED_DEFAULT_TEMPLATES
template <class Key, class T, class Compare = less<Key>, class Alloc = alloc>
template <class _Key, class _Tp, class _Compare = less<_Key>,
class _Alloc = __STL_DEFAULT_ALLOCATOR(_Tp) >
#else
template <class Key, class T, class Compare, class Alloc = alloc>
template <class _Key, class _Tp, class _Compare,
class _Alloc = __STL_DEFAULT_ALLOCATOR(_Tp) >
#endif
class multimap {
public:
// typedefs:
typedef Key key_type;
typedef T data_type;
typedef T mapped_type;
typedef pair<const Key, T> value_type;
typedef Compare key_compare;
typedef _Key key_type;
typedef _Tp data_type;
typedef _Tp mapped_type;
typedef pair<const _Key, _Tp> value_type;
typedef _Compare key_compare;
class value_compare : public binary_function<value_type, value_type, bool> {
friend class multimap<Key, T, Compare, Alloc>;
friend class multimap<_Key,_Tp,_Compare,_Alloc>;
protected:
Compare comp;
value_compare(Compare c) : comp(c) {}
_Compare _M_comp;
value_compare(_Compare __c) : _M_comp(__c) {}
public:
bool operator()(const value_type& x, const value_type& y) const {
return comp(x.first, y.first);
bool operator()(const value_type& __x, const value_type& __y) const {
return _M_comp(__x.first, __y.first);
}
};
private:
typedef rb_tree<key_type, value_type,
select1st<value_type>, key_compare, Alloc> rep_type;
rep_type t; // red-black tree representing multimap
typedef _Rb_tree<key_type, value_type,
_Select1st<value_type>, key_compare, _Alloc> _Rep_type;
_Rep_type _M_t; // red-black tree representing multimap
public:
typedef typename rep_type::pointer pointer;
typedef typename rep_type::const_pointer const_pointer;
typedef typename rep_type::reference reference;
typedef typename rep_type::const_reference const_reference;
typedef typename rep_type::iterator iterator;
typedef typename rep_type::const_iterator const_iterator;
typedef typename rep_type::reverse_iterator reverse_iterator;
typedef typename rep_type::const_reverse_iterator const_reverse_iterator;
typedef typename rep_type::size_type size_type;
typedef typename rep_type::difference_type difference_type;
typedef typename _Rep_type::pointer pointer;
typedef typename _Rep_type::const_pointer const_pointer;
typedef typename _Rep_type::reference reference;
typedef typename _Rep_type::const_reference const_reference;
typedef typename _Rep_type::iterator iterator;
typedef typename _Rep_type::const_iterator const_iterator;
typedef typename _Rep_type::reverse_iterator reverse_iterator;
typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
typedef typename _Rep_type::size_type size_type;
typedef typename _Rep_type::difference_type difference_type;
typedef typename _Rep_type::allocator_type allocator_type;
// allocation/deallocation
multimap() : t(Compare()) { }
explicit multimap(const Compare& comp) : t(comp) { }
multimap() : _M_t(_Compare(), allocator_type()) { }
explicit multimap(const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { }
#ifdef __STL_MEMBER_TEMPLATES
template <class InputIterator>
multimap(InputIterator first, InputIterator last)
: t(Compare()) { t.insert_equal(first, last); }
template <class _InputIterator>
multimap(_InputIterator __first, _InputIterator __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_equal(__first, __last); }
template <class InputIterator>
multimap(InputIterator first, InputIterator last, const Compare& comp)
: t(comp) { t.insert_equal(first, last); }
template <class _InputIterator>
multimap(_InputIterator __first, _InputIterator __last,
const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
#else
multimap(const value_type* first, const value_type* last)
: t(Compare()) { t.insert_equal(first, last); }
multimap(const value_type* first, const value_type* last,
const Compare& comp)
: t(comp) { t.insert_equal(first, last); }
multimap(const value_type* __first, const value_type* __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_equal(__first, __last); }
multimap(const value_type* __first, const value_type* __last,
const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
multimap(const_iterator first, const_iterator last)
: t(Compare()) { t.insert_equal(first, last); }
multimap(const_iterator first, const_iterator last, const Compare& comp)
: t(comp) { t.insert_equal(first, last); }
multimap(const_iterator __first, const_iterator __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_equal(__first, __last); }
multimap(const_iterator __first, const_iterator __last,
const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
#endif /* __STL_MEMBER_TEMPLATES */
multimap(const multimap<Key, T, Compare, Alloc>& x) : t(x.t) { }
multimap<Key, T, Compare, Alloc>&
operator=(const multimap<Key, T, Compare, Alloc>& x) {
t = x.t;
multimap(const multimap<_Key,_Tp,_Compare,_Alloc>& __x) : _M_t(__x._M_t) { }
multimap<_Key,_Tp,_Compare,_Alloc>&
operator=(const multimap<_Key,_Tp,_Compare,_Alloc>& __x) {
_M_t = __x._M_t;
return *this;
}
// accessors:
key_compare key_comp() const { return t.key_comp(); }
value_compare value_comp() const { return value_compare(t.key_comp()); }
iterator begin() { return t.begin(); }
const_iterator begin() const { return t.begin(); }
iterator end() { return t.end(); }
const_iterator end() const { return t.end(); }
reverse_iterator rbegin() { return t.rbegin(); }
const_reverse_iterator rbegin() const { return t.rbegin(); }
reverse_iterator rend() { return t.rend(); }
const_reverse_iterator rend() const { return t.rend(); }
bool empty() const { return t.empty(); }
size_type size() const { return t.size(); }
size_type max_size() const { return t.max_size(); }
void swap(multimap<Key, T, Compare, Alloc>& x) { t.swap(x.t); }
key_compare key_comp() const { return _M_t.key_comp(); }
value_compare value_comp() const { return value_compare(_M_t.key_comp()); }
allocator_type get_allocator() const { return _M_t.get_allocator(); }
iterator begin() { return _M_t.begin(); }
const_iterator begin() const { return _M_t.begin(); }
iterator end() { return _M_t.end(); }
const_iterator end() const { return _M_t.end(); }
reverse_iterator rbegin() { return _M_t.rbegin(); }
const_reverse_iterator rbegin() const { return _M_t.rbegin(); }
reverse_iterator rend() { return _M_t.rend(); }
const_reverse_iterator rend() const { return _M_t.rend(); }
bool empty() const { return _M_t.empty(); }
size_type size() const { return _M_t.size(); }
size_type max_size() const { return _M_t.max_size(); }
void swap(multimap<_Key,_Tp,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
// insert/erase
iterator insert(const value_type& x) { return t.insert_equal(x); }
iterator insert(iterator position, const value_type& x) {
return t.insert_equal(position, x);
iterator insert(const value_type& __x) { return _M_t.insert_equal(__x); }
iterator insert(iterator __position, const value_type& __x) {
return _M_t.insert_equal(__position, __x);
}
#ifdef __STL_MEMBER_TEMPLATES
template <class InputIterator>
void insert(InputIterator first, InputIterator last) {
t.insert_equal(first, last);
template <class _InputIterator>
void insert(_InputIterator __first, _InputIterator __last) {
_M_t.insert_equal(__first, __last);
}
#else
void insert(const value_type* first, const value_type* last) {
t.insert_equal(first, last);
void insert(const value_type* __first, const value_type* __last) {
_M_t.insert_equal(__first, __last);
}
void insert(const_iterator first, const_iterator last) {
t.insert_equal(first, last);
void insert(const_iterator __first, const_iterator __last) {
_M_t.insert_equal(__first, __last);
}
#endif /* __STL_MEMBER_TEMPLATES */
void erase(iterator position) { t.erase(position); }
size_type erase(const key_type& x) { return t.erase(x); }
void erase(iterator first, iterator last) { t.erase(first, last); }
void clear() { t.clear(); }
void erase(iterator __position) { _M_t.erase(__position); }
size_type erase(const key_type& __x) { return _M_t.erase(__x); }
void erase(iterator __first, iterator __last)
{ _M_t.erase(__first, __last); }
void clear() { _M_t.clear(); }
// multimap operations:
iterator find(const key_type& x) { return t.find(x); }
const_iterator find(const key_type& x) const { return t.find(x); }
size_type count(const key_type& x) const { return t.count(x); }
iterator lower_bound(const key_type& x) {return t.lower_bound(x); }
const_iterator lower_bound(const key_type& x) const {
return t.lower_bound(x);
iterator find(const key_type& __x) { return _M_t.find(__x); }
const_iterator find(const key_type& __x) const { return _M_t.find(__x); }
size_type count(const key_type& __x) const { return _M_t.count(__x); }
iterator lower_bound(const key_type& __x) {return _M_t.lower_bound(__x); }
const_iterator lower_bound(const key_type& __x) const {
return _M_t.lower_bound(__x);
}
iterator upper_bound(const key_type& x) {return t.upper_bound(x); }
const_iterator upper_bound(const key_type& x) const {
return t.upper_bound(x);
iterator upper_bound(const key_type& __x) {return _M_t.upper_bound(__x); }
const_iterator upper_bound(const key_type& __x) const {
return _M_t.upper_bound(__x);
}
pair<iterator,iterator> equal_range(const key_type& x) {
return t.equal_range(x);
pair<iterator,iterator> equal_range(const key_type& __x) {
return _M_t.equal_range(__x);
}
pair<const_iterator,const_iterator> equal_range(const key_type& x) const {
return t.equal_range(x);
pair<const_iterator,const_iterator> equal_range(const key_type& __x) const {
return _M_t.equal_range(__x);
}
friend bool operator== __STL_NULL_TMPL_ARGS (const multimap&,
const multimap&);
@ -179,30 +196,31 @@ public:
const multimap&);
};
template <class Key, class T, class Compare, class Alloc>
inline bool operator==(const multimap<Key, T, Compare, Alloc>& x,
const multimap<Key, T, Compare, Alloc>& y) {
return x.t == y.t;
template <class _Key, class _Tp, class _Compare, class _Alloc>
inline bool operator==(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
const multimap<_Key,_Tp,_Compare,_Alloc>& __y) {
return __x._M_t == __y._M_t;
}
template <class Key, class T, class Compare, class Alloc>
inline bool operator<(const multimap<Key, T, Compare, Alloc>& x,
const multimap<Key, T, Compare, Alloc>& y) {
return x.t < y.t;
template <class _Key, class _Tp, class _Compare, class _Alloc>
inline bool operator<(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
const multimap<_Key,_Tp,_Compare,_Alloc>& __y) {
return __x._M_t < __y._M_t;
}
#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
template <class Key, class T, class Compare, class Alloc>
inline void swap(multimap<Key, T, Compare, Alloc>& x,
multimap<Key, T, Compare, Alloc>& y) {
x.swap(y);
template <class _Key, class _Tp, class _Compare, class _Alloc>
inline void swap(multimap<_Key,_Tp,_Compare,_Alloc>& __x,
multimap<_Key,_Tp,_Compare,_Alloc>& __y) {
__x.swap(__y);
}
#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
#pragma reset woff 1174
#pragma reset woff 1375
#endif
__STL_END_NAMESPACE

View File

@ -35,129 +35,152 @@ __STL_BEGIN_NAMESPACE
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
#pragma set woff 1174
#pragma set woff 1375
#endif
#ifndef __STL_LIMITED_DEFAULT_TEMPLATES
template <class Key, class Compare = less<Key>, class Alloc = alloc>
template <class _Key, class _Compare = less<_Key>,
class _Alloc = __STL_DEFAULT_ALLOCATOR(_Key) >
#else
template <class Key, class Compare, class Alloc = alloc>
template <class _Key, class _Compare,
class _Alloc = __STL_DEFAULT_ALLOCATOR(_Key) >
#endif
class multiset {
public:
// typedefs:
typedef Key key_type;
typedef Key value_type;
typedef Compare key_compare;
typedef Compare value_compare;
typedef _Key key_type;
typedef _Key value_type;
typedef _Compare key_compare;
typedef _Compare value_compare;
private:
typedef rb_tree<key_type, value_type,
identity<value_type>, key_compare, Alloc> rep_type;
rep_type t; // red-black tree representing multiset
typedef _Rb_tree<key_type, value_type,
_Identity<value_type>, key_compare, _Alloc> _Rep_type;
_Rep_type _M_t; // red-black tree representing multiset
public:
typedef typename rep_type::const_pointer pointer;
typedef typename rep_type::const_pointer const_pointer;
typedef typename rep_type::const_reference reference;
typedef typename rep_type::const_reference const_reference;
typedef typename rep_type::const_iterator iterator;
typedef typename rep_type::const_iterator const_iterator;
typedef typename rep_type::const_reverse_iterator reverse_iterator;
typedef typename rep_type::const_reverse_iterator const_reverse_iterator;
typedef typename rep_type::size_type size_type;
typedef typename rep_type::difference_type difference_type;
typedef typename _Rep_type::const_pointer pointer;
typedef typename _Rep_type::const_pointer const_pointer;
typedef typename _Rep_type::const_reference reference;
typedef typename _Rep_type::const_reference const_reference;
typedef typename _Rep_type::const_iterator iterator;
typedef typename _Rep_type::const_iterator const_iterator;
typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
typedef typename _Rep_type::size_type size_type;
typedef typename _Rep_type::difference_type difference_type;
typedef typename _Rep_type::allocator_type allocator_type;
// allocation/deallocation
multiset() : t(Compare()) {}
explicit multiset(const Compare& comp) : t(comp) {}
multiset() : _M_t(_Compare(), allocator_type()) {}
explicit multiset(const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) {}
#ifdef __STL_MEMBER_TEMPLATES
template <class InputIterator>
multiset(InputIterator first, InputIterator last)
: t(Compare()) { t.insert_equal(first, last); }
template <class InputIterator>
multiset(InputIterator first, InputIterator last, const Compare& comp)
: t(comp) { t.insert_equal(first, last); }
#else
multiset(const value_type* first, const value_type* last)
: t(Compare()) { t.insert_equal(first, last); }
multiset(const value_type* first, const value_type* last,
const Compare& comp)
: t(comp) { t.insert_equal(first, last); }
multiset(const_iterator first, const_iterator last)
: t(Compare()) { t.insert_equal(first, last); }
multiset(const_iterator first, const_iterator last, const Compare& comp)
: t(comp) { t.insert_equal(first, last); }
template <class _InputIterator>
multiset(_InputIterator __first, _InputIterator __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_equal(__first, __last); }
template <class _InputIterator>
multiset(_InputIterator __first, _InputIterator __last,
const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
#else
multiset(const value_type* __first, const value_type* __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_equal(__first, __last); }
multiset(const value_type* __first, const value_type* __last,
const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
multiset(const_iterator __first, const_iterator __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_equal(__first, __last); }
multiset(const_iterator __first, const_iterator __last,
const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
#endif /* __STL_MEMBER_TEMPLATES */
multiset(const multiset<Key, Compare, Alloc>& x) : t(x.t) {}
multiset<Key, Compare, Alloc>&
operator=(const multiset<Key, Compare, Alloc>& x) {
t = x.t;
multiset(const multiset<_Key,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {}
multiset<_Key,_Compare,_Alloc>&
operator=(const multiset<_Key,_Compare,_Alloc>& __x) {
_M_t = __x._M_t;
return *this;
}
// accessors:
key_compare key_comp() const { return t.key_comp(); }
value_compare value_comp() const { return t.key_comp(); }
iterator begin() const { return t.begin(); }
iterator end() const { return t.end(); }
reverse_iterator rbegin() const { return t.rbegin(); }
reverse_iterator rend() const { return t.rend(); }
bool empty() const { return t.empty(); }
size_type size() const { return t.size(); }
size_type max_size() const { return t.max_size(); }
void swap(multiset<Key, Compare, Alloc>& x) { t.swap(x.t); }
key_compare key_comp() const { return _M_t.key_comp(); }
value_compare value_comp() const { return _M_t.key_comp(); }
allocator_type get_allocator() const { return _M_t.get_allocator(); }
iterator begin() const { return _M_t.begin(); }
iterator end() const { return _M_t.end(); }
reverse_iterator rbegin() const { return _M_t.rbegin(); }
reverse_iterator rend() const { return _M_t.rend(); }
bool empty() const { return _M_t.empty(); }
size_type size() const { return _M_t.size(); }
size_type max_size() const { return _M_t.max_size(); }
void swap(multiset<_Key,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
// insert/erase
iterator insert(const value_type& x) {
return t.insert_equal(x);
iterator insert(const value_type& __x) {
return _M_t.insert_equal(__x);
}
iterator insert(iterator position, const value_type& x) {
typedef typename rep_type::iterator rep_iterator;
return t.insert_equal((rep_iterator&)position, x);
iterator insert(iterator __position, const value_type& __x) {
typedef typename _Rep_type::iterator _Rep_iterator;
return _M_t.insert_equal((_Rep_iterator&)__position, __x);
}
#ifdef __STL_MEMBER_TEMPLATES
template <class InputIterator>
void insert(InputIterator first, InputIterator last) {
t.insert_equal(first, last);
template <class _InputIterator>
void insert(_InputIterator __first, _InputIterator __last) {
_M_t.insert_equal(__first, __last);
}
#else
void insert(const value_type* first, const value_type* last) {
t.insert_equal(first, last);
void insert(const value_type* __first, const value_type* __last) {
_M_t.insert_equal(__first, __last);
}
void insert(const_iterator first, const_iterator last) {
t.insert_equal(first, last);
void insert(const_iterator __first, const_iterator __last) {
_M_t.insert_equal(__first, __last);
}
#endif /* __STL_MEMBER_TEMPLATES */
void erase(iterator position) {
typedef typename rep_type::iterator rep_iterator;
t.erase((rep_iterator&)position);
void erase(iterator __position) {
typedef typename _Rep_type::iterator _Rep_iterator;
_M_t.erase((_Rep_iterator&)__position);
}
size_type erase(const key_type& x) {
return t.erase(x);
size_type erase(const key_type& __x) {
return _M_t.erase(__x);
}
void erase(iterator first, iterator last) {
typedef typename rep_type::iterator rep_iterator;
t.erase((rep_iterator&)first, (rep_iterator&)last);
void erase(iterator __first, iterator __last) {
typedef typename _Rep_type::iterator _Rep_iterator;
_M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last);
}
void clear() { t.clear(); }
void clear() { _M_t.clear(); }
// multiset operations:
iterator find(const key_type& x) const { return t.find(x); }
size_type count(const key_type& x) const { return t.count(x); }
iterator lower_bound(const key_type& x) const {
return t.lower_bound(x);
iterator find(const key_type& __x) const { return _M_t.find(__x); }
size_type count(const key_type& __x) const { return _M_t.count(__x); }
iterator lower_bound(const key_type& __x) const {
return _M_t.lower_bound(__x);
}
iterator upper_bound(const key_type& x) const {
return t.upper_bound(x);
iterator upper_bound(const key_type& __x) const {
return _M_t.upper_bound(__x);
}
pair<iterator,iterator> equal_range(const key_type& x) const {
return t.equal_range(x);
pair<iterator,iterator> equal_range(const key_type& __x) const {
return _M_t.equal_range(__x);
}
friend bool operator== __STL_NULL_TMPL_ARGS (const multiset&,
const multiset&);
@ -165,30 +188,31 @@ public:
const multiset&);
};
template <class Key, class Compare, class Alloc>
inline bool operator==(const multiset<Key, Compare, Alloc>& x,
const multiset<Key, Compare, Alloc>& y) {
return x.t == y.t;
template <class _Key, class _Compare, class _Alloc>
inline bool operator==(const multiset<_Key,_Compare,_Alloc>& __x,
const multiset<_Key,_Compare,_Alloc>& __y) {
return __x._M_t == __y._M_t;
}
template <class Key, class Compare, class Alloc>
inline bool operator<(const multiset<Key, Compare, Alloc>& x,
const multiset<Key, Compare, Alloc>& y) {
return x.t < y.t;
template <class _Key, class _Compare, class _Alloc>
inline bool operator<(const multiset<_Key,_Compare,_Alloc>& __x,
const multiset<_Key,_Compare,_Alloc>& __y) {
return __x._M_t < __y._M_t;
}
#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
template <class Key, class Compare, class Alloc>
inline void swap(multiset<Key, Compare, Alloc>& x,
multiset<Key, Compare, Alloc>& y) {
x.swap(y);
template <class _Key, class _Compare, class _Alloc>
inline void swap(multiset<_Key,_Compare,_Alloc>& __x,
multiset<_Key,_Compare,_Alloc>& __y) {
__x.swap(__y);
}
#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
#pragma reset woff 1174
#pragma reset woff 1375
#endif
__STL_END_NAMESPACE

View File

@ -34,157 +34,200 @@
__STL_BEGIN_NAMESPACE
template <class InputIterator, class T>
T accumulate(InputIterator first, InputIterator last, T init) {
for ( ; first != last; ++first)
init = init + *first;
return init;
template <class _InputIterator, class _Tp>
_Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
{
for ( ; __first != __last; ++__first)
__init = __init + *__first;
return __init;
}
template <class InputIterator, class T, class BinaryOperation>
T accumulate(InputIterator first, InputIterator last, T init,
BinaryOperation binary_op) {
for ( ; first != last; ++first)
init = binary_op(init, *first);
return init;
template <class _InputIterator, class _Tp, class _BinaryOperation>
_Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init,
_BinaryOperation __binary_op)
{
for ( ; __first != __last; ++__first)
__init = __binary_op(__init, *__first);
return __init;
}
template <class InputIterator1, class InputIterator2, class T>
T inner_product(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, T init) {
for ( ; first1 != last1; ++first1, ++first2)
init = init + (*first1 * *first2);
return init;
template <class _InputIterator1, class _InputIterator2, class _Tp>
_Tp inner_product(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _Tp __init)
{
for ( ; __first1 != __last1; ++__first1, ++__first2)
__init = __init + (*__first1 * *__first2);
return __init;
}
template <class InputIterator1, class InputIterator2, class T,
class BinaryOperation1, class BinaryOperation2>
T inner_product(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, T init, BinaryOperation1 binary_op1,
BinaryOperation2 binary_op2) {
for ( ; first1 != last1; ++first1, ++first2)
init = binary_op1(init, binary_op2(*first1, *first2));
return init;
template <class _InputIterator1, class _InputIterator2, class _Tp,
class _BinaryOperation1, class _BinaryOperation2>
_Tp inner_product(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _Tp __init,
_BinaryOperation1 __binary_op1,
_BinaryOperation2 __binary_op2)
{
for ( ; __first1 != __last1; ++__first1, ++__first2)
__init = __binary_op1(__init, __binary_op2(*__first1, *__first2));
return __init;
}
template <class InputIterator, class OutputIterator, class T>
OutputIterator __partial_sum(InputIterator first, InputIterator last,
OutputIterator result, T*) {
T value = *first;
while (++first != last) {
value = value + *first;
*++result = value;
template <class _InputIterator, class _OutputIterator, class _Tp>
_OutputIterator
__partial_sum(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _Tp*)
{
_Tp __value = *__first;
while (++__first != __last) {
__value = __value + *__first;
*++__result = __value;
}
return ++result;
return ++__result;
}
template <class InputIterator, class OutputIterator>
OutputIterator partial_sum(InputIterator first, InputIterator last,
OutputIterator result) {
if (first == last) return result;
*result = *first;
return __partial_sum(first, last, result, value_type(first));
template <class _InputIterator, class _OutputIterator>
_OutputIterator
partial_sum(_InputIterator __first, _InputIterator __last,
_OutputIterator __result)
{
if (__first == __last) return __result;
*__result = *__first;
return __partial_sum(__first, __last, __result, __VALUE_TYPE(__first));
}
template <class InputIterator, class OutputIterator, class T,
class BinaryOperation>
OutputIterator __partial_sum(InputIterator first, InputIterator last,
OutputIterator result, T*,
BinaryOperation binary_op) {
T value = *first;
while (++first != last) {
value = binary_op(value, *first);
*++result = value;
template <class _InputIterator, class _OutputIterator, class _Tp,
class _BinaryOperation>
_OutputIterator
__partial_sum(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _Tp*, _BinaryOperation __binary_op)
{
_Tp __value = *__first;
while (++__first != __last) {
__value = __binary_op(__value, *__first);
*++__result = __value;
}
return ++result;
return ++__result;
}
template <class InputIterator, class OutputIterator, class BinaryOperation>
OutputIterator partial_sum(InputIterator first, InputIterator last,
OutputIterator result, BinaryOperation binary_op) {
if (first == last) return result;
*result = *first;
return __partial_sum(first, last, result, value_type(first), binary_op);
template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
_OutputIterator
partial_sum(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _BinaryOperation __binary_op)
{
if (__first == __last) return __result;
*__result = *__first;
return __partial_sum(__first, __last, __result, __VALUE_TYPE(__first),
__binary_op);
}
template <class InputIterator, class OutputIterator, class T>
OutputIterator __adjacent_difference(InputIterator first, InputIterator last,
OutputIterator result, T*) {
T value = *first;
while (++first != last) {
T tmp = *first;
*++result = tmp - value;
value = tmp;
template <class _InputIterator, class _OutputIterator, class _Tp>
_OutputIterator
__adjacent_difference(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _Tp*)
{
_Tp __value = *__first;
while (++__first != __last) {
_Tp __tmp = *__first;
*++__result = __tmp - __value;
__value = __tmp;
}
return ++result;
return ++__result;
}
template <class InputIterator, class OutputIterator>
OutputIterator adjacent_difference(InputIterator first, InputIterator last,
OutputIterator result) {
if (first == last) return result;
*result = *first;
return __adjacent_difference(first, last, result, value_type(first));
template <class _InputIterator, class _OutputIterator>
_OutputIterator
adjacent_difference(_InputIterator __first,
_InputIterator __last, _OutputIterator __result)
{
if (__first == __last) return __result;
*__result = *__first;
return __adjacent_difference(__first, __last, __result,
__VALUE_TYPE(__first));
}
template <class InputIterator, class OutputIterator, class T,
class BinaryOperation>
OutputIterator __adjacent_difference(InputIterator first, InputIterator last,
OutputIterator result, T*,
BinaryOperation binary_op) {
T value = *first;
while (++first != last) {
T tmp = *first;
*++result = binary_op(tmp, value);
value = tmp;
template <class _InputIterator, class _OutputIterator, class _Tp,
class _BinaryOperation>
_OutputIterator
__adjacent_difference(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _Tp*,
_BinaryOperation __binary_op) {
_Tp __value = *__first;
while (++__first != __last) {
_Tp __tmp = *__first;
*++__result = __binary_op(__tmp, __value);
__value = __tmp;
}
return ++result;
return ++__result;
}
template <class InputIterator, class OutputIterator, class BinaryOperation>
OutputIterator adjacent_difference(InputIterator first, InputIterator last,
OutputIterator result,
BinaryOperation binary_op) {
if (first == last) return result;
*result = *first;
return __adjacent_difference(first, last, result, value_type(first),
binary_op);
template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
_OutputIterator
adjacent_difference(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _BinaryOperation __binary_op)
{
if (__first == __last) return __result;
*__result = *__first;
return __adjacent_difference(__first, __last, __result,
__VALUE_TYPE(__first),
__binary_op);
}
// Returns x ** n, where n >= 0. Note that "multiplication"
// is required to be associative, but not necessarily commutative.
template <class T, class Integer, class MonoidOperation>
T power(T x, Integer n, MonoidOperation op) {
if (n == 0)
return identity_element(op);
// Returns __x ** __n, where __n >= 0. _Note that "multiplication"
// is required to be associative, but not necessarily commutative.
template <class _Tp, class _Integer, class _MonoidOperation>
_Tp __power(_Tp __x, _Integer __n, _MonoidOperation __opr)
{
if (__n == 0)
return identity_element(__opr);
else {
while ((n & 1) == 0) {
n >>= 1;
x = op(x, x);
while ((__n & 1) == 0) {
__n >>= 1;
__x = __opr(__x, __x);
}
T result = x;
n >>= 1;
while (n != 0) {
x = op(x, x);
if ((n & 1) != 0)
result = op(result, x);
n >>= 1;
_Tp __result = __x;
__n >>= 1;
while (__n != 0) {
__x = __opr(__x, __x);
if ((__n & 1) != 0)
__result = __opr(__result, __x);
__n >>= 1;
}
return result;
return __result;
}
}
template <class T, class Integer>
inline T power(T x, Integer n) {
return power(x, n, multiplies<T>());
template <class _Tp, class _Integer>
inline _Tp __power(_Tp __x, _Integer __n)
{
return __power(__x, __n, multiplies<_Tp>());
}
// Alias for the internal name __power. Note that power is an extension,
// not part of the C++ standard.
template <class ForwardIterator, class T>
void iota(ForwardIterator first, ForwardIterator last, T value) {
while (first != last) *first++ = value++;
template <class _Tp, class _Integer, class _MonoidOperation>
inline _Tp power(_Tp __x, _Integer __n, _MonoidOperation __opr)
{
return __power(__x, __n, __opr);
}
template <class _Tp, class _Integer>
inline _Tp power(_Tp __x, _Integer __n)
{
return __power(__x, __n);
}
// iota is not part of the C++ standard. It is an extension.
template <class _ForwardIterator, class _Tp>
void
iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value)
{
while (__first != __last)
*__first++ = __value++;
}
__STL_END_NAMESPACE

View File

@ -33,35 +33,39 @@
__STL_BEGIN_NAMESPACE
template <class T1, class T2>
template <class _T1, class _T2>
struct pair {
typedef T1 first_type;
typedef T2 second_type;
typedef _T1 first_type;
typedef _T2 second_type;
T1 first;
T2 second;
pair() : first(T1()), second(T2()) {}
pair(const T1& a, const T2& b) : first(a), second(b) {}
_T1 first;
_T2 second;
pair() : first(_T1()), second(_T2()) {}
pair(const _T1& __a, const _T2& __b) : first(__a), second(__b) {}
#ifdef __STL_MEMBER_TEMPLATES
template <class U1, class U2>
pair(const pair<U1, U2>& p) : first(p.first), second(p.second) {}
template <class _U1, class _U2>
pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {}
#endif
};
template <class T1, class T2>
inline bool operator==(const pair<T1, T2>& x, const pair<T1, T2>& y) {
return x.first == y.first && x.second == y.second;
template <class _T1, class _T2>
inline bool operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
{
return __x.first == __y.first && __x.second == __y.second;
}
template <class T1, class T2>
inline bool operator<(const pair<T1, T2>& x, const pair<T1, T2>& y) {
return x.first < y.first || (!(y.first < x.first) && x.second < y.second);
template <class _T1, class _T2>
inline bool operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
{
return __x.first < __y.first ||
(!(__y.first < __x.first) && __x.second < __y.second);
}
template <class T1, class T2>
inline pair<T1, T2> make_pair(const T1& x, const T2& y) {
return pair<T1, T2>(x, y);
template <class _T1, class _T2>
inline pair<_T1, _T2> make_pair(const _T1& __x, const _T2& __y)
{
return pair<_T1, _T2>(__x, __y);
}
__STL_END_NAMESPACE

View File

@ -34,92 +34,160 @@
__STL_BEGIN_NAMESPACE
#ifndef __STL_LIMITED_DEFAULT_TEMPLATES
template <class T, class Sequence = deque<T> >
template <class _Tp, class _Sequence = deque<_Tp> >
#else
template <class T, class Sequence>
template <class _Tp, class _Sequence>
#endif
class queue {
friend bool operator== __STL_NULL_TMPL_ARGS (const queue& x, const queue& y);
friend bool operator< __STL_NULL_TMPL_ARGS (const queue& x, const queue& y);
friend bool operator== __STL_NULL_TMPL_ARGS (const queue&, const queue&);
friend bool operator< __STL_NULL_TMPL_ARGS (const queue&, const queue&);
public:
typedef typename Sequence::value_type value_type;
typedef typename Sequence::size_type size_type;
typedef typename Sequence::reference reference;
typedef typename Sequence::const_reference const_reference;
typedef typename _Sequence::value_type value_type;
typedef typename _Sequence::size_type size_type;
typedef _Sequence container_type;
typedef typename _Sequence::reference reference;
typedef typename _Sequence::const_reference const_reference;
protected:
Sequence c;
_Sequence _M_c;
public:
bool empty() const { return c.empty(); }
size_type size() const { return c.size(); }
reference front() { return c.front(); }
const_reference front() const { return c.front(); }
reference back() { return c.back(); }
const_reference back() const { return c.back(); }
void push(const value_type& x) { c.push_back(x); }
void pop() { c.pop_front(); }
queue() : _M_c() {}
explicit queue(const _Sequence& __c) : _M_c(__c) {}
bool empty() const { return _M_c.empty(); }
size_type size() const { return _M_c.size(); }
reference front() { return _M_c.front(); }
const_reference front() const { return _M_c.front(); }
reference back() { return _M_c.back(); }
const_reference back() const { return _M_c.back(); }
void push(const value_type& __x) { _M_c.push_back(__x); }
void pop() { _M_c.pop_front(); }
};
template <class T, class Sequence>
bool operator==(const queue<T, Sequence>& x, const queue<T, Sequence>& y) {
return x.c == y.c;
template <class _Tp, class _Sequence>
bool
operator==(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
{
return __x._M_c == __y._M_c;
}
template <class T, class Sequence>
bool operator<(const queue<T, Sequence>& x, const queue<T, Sequence>& y) {
return x.c < y.c;
template <class _Tp, class _Sequence>
bool
operator<(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
{
return __x._M_c < __y._M_c;
}
#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
template <class _Tp, class _Sequence>
bool
operator!=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
{
return !(__x == __y);
}
template <class _Tp, class _Sequence>
bool
operator>(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
{
return __y < __x;
}
template <class _Tp, class _Sequence>
bool
operator<=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
{
return !(__y < __x);
}
template <class _Tp, class _Sequence>
bool
operator>=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
{
return !(__x < __y);
}
#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
#ifndef __STL_LIMITED_DEFAULT_TEMPLATES
template <class T, class Sequence = vector<T>,
class Compare = less<typename Sequence::value_type> >
template <class _Tp, class _Sequence = vector<_Tp>,
class _Compare = less<typename _Sequence::value_type> >
#else
template <class T, class Sequence, class Compare>
template <class _Tp, class _Sequence, class _Compare>
#endif
class priority_queue {
public:
typedef typename Sequence::value_type value_type;
typedef typename Sequence::size_type size_type;
typedef typename Sequence::reference reference;
typedef typename Sequence::const_reference const_reference;
typedef typename _Sequence::value_type value_type;
typedef typename _Sequence::size_type size_type;
typedef _Sequence container_type;
typedef typename _Sequence::reference reference;
typedef typename _Sequence::const_reference const_reference;
protected:
Sequence c;
Compare comp;
_Sequence _M_c;
_Compare _M_comp;
public:
priority_queue() : c() {}
explicit priority_queue(const Compare& x) : c(), comp(x) {}
priority_queue() : _M_c() {}
explicit priority_queue(const _Compare& __x) : _M_c(), _M_comp(__x) {}
priority_queue(const _Compare& __x, const _Sequence& __s)
: _M_c(__s), _M_comp(__x)
{ make_heap(_M_c.begin(), _M_c.end(), _M_comp); }
#ifdef __STL_MEMBER_TEMPLATES
template <class InputIterator>
priority_queue(InputIterator first, InputIterator last, const Compare& x)
: c(first, last), comp(x) { make_heap(c.begin(), c.end(), comp); }
template <class InputIterator>
priority_queue(InputIterator first, InputIterator last)
: c(first, last) { make_heap(c.begin(), c.end(), comp); }
#else /* __STL_MEMBER_TEMPLATES */
priority_queue(const value_type* first, const value_type* last,
const Compare& x) : c(first, last), comp(x) {
make_heap(c.begin(), c.end(), comp);
template <class _InputIterator>
priority_queue(_InputIterator __first, _InputIterator __last)
: _M_c(__first, __last) { make_heap(_M_c.begin(), _M_c.end(), _M_comp); }
template <class _InputIterator>
priority_queue(_InputIterator __first,
_InputIterator __last, const _Compare& __x)
: _M_c(__first, __last), _M_comp(__x)
{ make_heap(_M_c.begin(), _M_c.end(), _M_comp); }
template <class _InputIterator>
priority_queue(_InputIterator __first, _InputIterator __last,
const _Compare& __x, const _Sequence& __s)
: _M_c(__s), _M_comp(__x)
{
_M_c.insert(_M_c.end(), __first, __last);
make_heap(_M_c.begin(), _M_c.end(), _M_comp);
}
#else /* __STL_MEMBER_TEMPLATES */
priority_queue(const value_type* __first, const value_type* __last)
: _M_c(__first, __last) { make_heap(_M_c.begin(), _M_c.end(), _M_comp); }
priority_queue(const value_type* __first, const value_type* __last,
const _Compare& __x)
: _M_c(__first, __last), _M_comp(__x)
{ make_heap(_M_c.begin(), _M_c.end(), _M_comp); }
priority_queue(const value_type* __first, const value_type* __last,
const _Compare& __x, const _Sequence& __c)
: _M_c(__c), _M_comp(__x)
{
_M_c.insert(_M_c.end(), __first, __last);
make_heap(_M_c.begin(), _M_c.end(), _M_comp);
}
priority_queue(const value_type* first, const value_type* last)
: c(first, last) { make_heap(c.begin(), c.end(), comp); }
#endif /* __STL_MEMBER_TEMPLATES */
bool empty() const { return c.empty(); }
size_type size() const { return c.size(); }
const_reference top() const { return c.front(); }
void push(const value_type& x) {
bool empty() const { return _M_c.empty(); }
size_type size() const { return _M_c.size(); }
const_reference top() const { return _M_c.front(); }
void push(const value_type& __x) {
__STL_TRY {
c.push_back(x);
push_heap(c.begin(), c.end(), comp);
_M_c.push_back(__x);
push_heap(_M_c.begin(), _M_c.end(), _M_comp);
}
__STL_UNWIND(c.clear());
__STL_UNWIND(_M_c.clear());
}
void pop() {
__STL_TRY {
pop_heap(c.begin(), c.end(), comp);
c.pop_back();
pop_heap(_M_c.begin(), _M_c.end(), _M_comp);
_M_c.pop_back();
}
__STL_UNWIND(c.clear());
__STL_UNWIND(_M_c.clear());
}
};

View File

@ -25,7 +25,7 @@
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
* You should not attempt to use it directly.
*/
#ifndef __SGI_STL_INTERNAL_RAW_STORAGE_ITERATOR_H
@ -33,10 +33,10 @@
__STL_BEGIN_NAMESPACE
template <class ForwardIterator, class T>
template <class _ForwardIterator, class _Tp>
class raw_storage_iterator {
protected:
ForwardIterator iter;
_ForwardIterator _M_iter;
public:
typedef output_iterator_tag iterator_category;
typedef void value_type;
@ -44,38 +44,38 @@ public:
typedef void pointer;
typedef void reference;
explicit raw_storage_iterator(ForwardIterator x) : iter(x) {}
raw_storage_iterator<ForwardIterator, T>& operator*() { return *this; }
raw_storage_iterator<ForwardIterator, T>& operator=(const T& element) {
construct(&*iter, element);
explicit raw_storage_iterator(_ForwardIterator __x) : _M_iter(__x) {}
raw_storage_iterator& operator*() { return *this; }
raw_storage_iterator& operator=(const _Tp& __element) {
construct(&*_M_iter, __element);
return *this;
}
raw_storage_iterator<ForwardIterator, T>& operator++() {
++iter;
raw_storage_iterator<_ForwardIterator, _Tp>& operator++() {
++_M_iter;
return *this;
}
raw_storage_iterator<ForwardIterator, T> operator++(int) {
raw_storage_iterator<ForwardIterator, T> tmp = *this;
++iter;
return tmp;
raw_storage_iterator<_ForwardIterator, _Tp> operator++(int) {
raw_storage_iterator<_ForwardIterator, _Tp> __tmp = *this;
++_M_iter;
return __tmp;
}
};
#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
template <class ForwardIterator, class T>
template <class _ForwardIterator, class _Tp>
inline output_iterator_tag
iterator_category(const raw_storage_iterator<ForwardIterator, T>&)
iterator_category(const raw_storage_iterator<_ForwardIterator, _Tp>&)
{
return output_iterator_tag();
}
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
#endif /* __SGI_STL_INTERNAL_RAW_STORAGE_ITERATOR_H */
__STL_END_NAMESPACE
#endif /* __SGI_STL_INTERNAL_RAW_STORAGE_ITERATOR_H */
// Local Variables:
// mode:C++
// End:

View File

@ -33,24 +33,24 @@
__STL_BEGIN_RELOPS_NAMESPACE
template <class T>
inline bool operator!=(const T& x, const T& y) {
return !(x == y);
template <class _Tp>
inline bool operator!=(const _Tp& __x, const _Tp& __y) {
return !(__x == __y);
}
template <class T>
inline bool operator>(const T& x, const T& y) {
return y < x;
template <class _Tp>
inline bool operator>(const _Tp& __x, const _Tp& __y) {
return __y < __x;
}
template <class T>
inline bool operator<=(const T& x, const T& y) {
return !(y < x);
template <class _Tp>
inline bool operator<=(const _Tp& __x, const _Tp& __y) {
return !(__y < __x);
}
template <class T>
inline bool operator>=(const T& x, const T& y) {
return !(x < y);
template <class _Tp>
inline bool operator>=(const _Tp& __x, const _Tp& __y) {
return !(__x < __y);
}
__STL_END_RELOPS_NAMESPACE

File diff suppressed because it is too large Load Diff

View File

@ -35,158 +35,176 @@ __STL_BEGIN_NAMESPACE
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
#pragma set woff 1174
#pragma set woff 1375
#endif
#ifndef __STL_LIMITED_DEFAULT_TEMPLATES
template <class Key, class Compare = less<Key>, class Alloc = alloc>
template <class _Key, class _Compare = less<_Key>,
class _Alloc = __STL_DEFAULT_ALLOCATOR(_Key) >
#else
template <class Key, class Compare, class Alloc = alloc>
template <class _Key, class _Compare,
class _Alloc = __STL_DEFAULT_ALLOCATOR(_Key) >
#endif
class set {
public:
// typedefs:
typedef Key key_type;
typedef Key value_type;
typedef Compare key_compare;
typedef Compare value_compare;
typedef _Key key_type;
typedef _Key value_type;
typedef _Compare key_compare;
typedef _Compare value_compare;
private:
typedef rb_tree<key_type, value_type,
identity<value_type>, key_compare, Alloc> rep_type;
rep_type t; // red-black tree representing set
typedef _Rb_tree<key_type, value_type,
_Identity<value_type>, key_compare, _Alloc> _Rep_type;
_Rep_type _M_t; // red-black tree representing set
public:
typedef typename rep_type::const_pointer pointer;
typedef typename rep_type::const_pointer const_pointer;
typedef typename rep_type::const_reference reference;
typedef typename rep_type::const_reference const_reference;
typedef typename rep_type::const_iterator iterator;
typedef typename rep_type::const_iterator const_iterator;
typedef typename rep_type::const_reverse_iterator reverse_iterator;
typedef typename rep_type::const_reverse_iterator const_reverse_iterator;
typedef typename rep_type::size_type size_type;
typedef typename rep_type::difference_type difference_type;
typedef typename _Rep_type::const_pointer pointer;
typedef typename _Rep_type::const_pointer const_pointer;
typedef typename _Rep_type::const_reference reference;
typedef typename _Rep_type::const_reference const_reference;
typedef typename _Rep_type::const_iterator iterator;
typedef typename _Rep_type::const_iterator const_iterator;
typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
typedef typename _Rep_type::size_type size_type;
typedef typename _Rep_type::difference_type difference_type;
typedef typename _Rep_type::allocator_type allocator_type;
// allocation/deallocation
set() : t(Compare()) {}
explicit set(const Compare& comp) : t(comp) {}
set() : _M_t(_Compare(), allocator_type()) {}
explicit set(const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) {}
#ifdef __STL_MEMBER_TEMPLATES
template <class InputIterator>
set(InputIterator first, InputIterator last)
: t(Compare()) { t.insert_unique(first, last); }
template <class _InputIterator>
set(_InputIterator __first, _InputIterator __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_unique(__first, __last); }
template <class InputIterator>
set(InputIterator first, InputIterator last, const Compare& comp)
: t(comp) { t.insert_unique(first, last); }
template <class _InputIterator>
set(_InputIterator __first, _InputIterator __last, const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
#else
set(const value_type* first, const value_type* last)
: t(Compare()) { t.insert_unique(first, last); }
set(const value_type* first, const value_type* last, const Compare& comp)
: t(comp) { t.insert_unique(first, last); }
set(const value_type* __first, const value_type* __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_unique(__first, __last); }
set(const_iterator first, const_iterator last)
: t(Compare()) { t.insert_unique(first, last); }
set(const_iterator first, const_iterator last, const Compare& comp)
: t(comp) { t.insert_unique(first, last); }
set(const value_type* __first,
const value_type* __last, const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
set(const_iterator __first, const_iterator __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_unique(__first, __last); }
set(const_iterator __first, const_iterator __last, const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
#endif /* __STL_MEMBER_TEMPLATES */
set(const set<Key, Compare, Alloc>& x) : t(x.t) {}
set<Key, Compare, Alloc>& operator=(const set<Key, Compare, Alloc>& x) {
t = x.t;
set(const set<_Key,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {}
set<_Key,_Compare,_Alloc>& operator=(const set<_Key, _Compare, _Alloc>& __x)
{
_M_t = __x._M_t;
return *this;
}
// accessors:
key_compare key_comp() const { return t.key_comp(); }
value_compare value_comp() const { return t.key_comp(); }
iterator begin() const { return t.begin(); }
iterator end() const { return t.end(); }
reverse_iterator rbegin() const { return t.rbegin(); }
reverse_iterator rend() const { return t.rend(); }
bool empty() const { return t.empty(); }
size_type size() const { return t.size(); }
size_type max_size() const { return t.max_size(); }
void swap(set<Key, Compare, Alloc>& x) { t.swap(x.t); }
key_compare key_comp() const { return _M_t.key_comp(); }
value_compare value_comp() const { return _M_t.key_comp(); }
allocator_type get_allocator() const { return _M_t.get_allocator(); }
iterator begin() const { return _M_t.begin(); }
iterator end() const { return _M_t.end(); }
reverse_iterator rbegin() const { return _M_t.rbegin(); }
reverse_iterator rend() const { return _M_t.rend(); }
bool empty() const { return _M_t.empty(); }
size_type size() const { return _M_t.size(); }
size_type max_size() const { return _M_t.max_size(); }
void swap(set<_Key,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
// insert/erase
typedef pair<iterator, bool> pair_iterator_bool;
pair<iterator,bool> insert(const value_type& x) {
pair<typename rep_type::iterator, bool> p = t.insert_unique(x);
return pair<iterator, bool>(p.first, p.second);
pair<iterator,bool> insert(const value_type& __x) {
pair<typename _Rep_type::iterator, bool> __p = _M_t.insert_unique(__x);
return pair<iterator, bool>(__p.first, __p.second);
}
iterator insert(iterator position, const value_type& x) {
typedef typename rep_type::iterator rep_iterator;
return t.insert_unique((rep_iterator&)position, x);
iterator insert(iterator __position, const value_type& __x) {
typedef typename _Rep_type::iterator _Rep_iterator;
return _M_t.insert_unique((_Rep_iterator&)__position, __x);
}
#ifdef __STL_MEMBER_TEMPLATES
template <class InputIterator>
void insert(InputIterator first, InputIterator last) {
t.insert_unique(first, last);
template <class _InputIterator>
void insert(_InputIterator __first, _InputIterator __last) {
_M_t.insert_unique(__first, __last);
}
#else
void insert(const_iterator first, const_iterator last) {
t.insert_unique(first, last);
void insert(const_iterator __first, const_iterator __last) {
_M_t.insert_unique(__first, __last);
}
void insert(const value_type* first, const value_type* last) {
t.insert_unique(first, last);
void insert(const value_type* __first, const value_type* __last) {
_M_t.insert_unique(__first, __last);
}
#endif /* __STL_MEMBER_TEMPLATES */
void erase(iterator position) {
typedef typename rep_type::iterator rep_iterator;
t.erase((rep_iterator&)position);
void erase(iterator __position) {
typedef typename _Rep_type::iterator _Rep_iterator;
_M_t.erase((_Rep_iterator&)__position);
}
size_type erase(const key_type& x) {
return t.erase(x);
size_type erase(const key_type& __x) {
return _M_t.erase(__x);
}
void erase(iterator first, iterator last) {
typedef typename rep_type::iterator rep_iterator;
t.erase((rep_iterator&)first, (rep_iterator&)last);
void erase(iterator __first, iterator __last) {
typedef typename _Rep_type::iterator _Rep_iterator;
_M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last);
}
void clear() { t.clear(); }
void clear() { _M_t.clear(); }
// set operations:
iterator find(const key_type& x) const { return t.find(x); }
size_type count(const key_type& x) const { return t.count(x); }
iterator lower_bound(const key_type& x) const {
return t.lower_bound(x);
iterator find(const key_type& __x) const { return _M_t.find(__x); }
size_type count(const key_type& __x) const { return _M_t.count(__x); }
iterator lower_bound(const key_type& __x) const {
return _M_t.lower_bound(__x);
}
iterator upper_bound(const key_type& x) const {
return t.upper_bound(x);
iterator upper_bound(const key_type& __x) const {
return _M_t.upper_bound(__x);
}
pair<iterator,iterator> equal_range(const key_type& x) const {
return t.equal_range(x);
pair<iterator,iterator> equal_range(const key_type& __x) const {
return _M_t.equal_range(__x);
}
friend bool operator== __STL_NULL_TMPL_ARGS (const set&, const set&);
friend bool operator< __STL_NULL_TMPL_ARGS (const set&, const set&);
};
template <class Key, class Compare, class Alloc>
inline bool operator==(const set<Key, Compare, Alloc>& x,
const set<Key, Compare, Alloc>& y) {
return x.t == y.t;
template <class _Key, class _Compare, class _Alloc>
inline bool operator==(const set<_Key,_Compare,_Alloc>& __x,
const set<_Key,_Compare,_Alloc>& __y) {
return __x._M_t == __y._M_t;
}
template <class Key, class Compare, class Alloc>
inline bool operator<(const set<Key, Compare, Alloc>& x,
const set<Key, Compare, Alloc>& y) {
return x.t < y.t;
template <class _Key, class _Compare, class _Alloc>
inline bool operator<(const set<_Key,_Compare,_Alloc>& __x,
const set<_Key,_Compare,_Alloc>& __y) {
return __x._M_t < __y._M_t;
}
#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
template <class Key, class Compare, class Alloc>
inline void swap(set<Key, Compare, Alloc>& x,
set<Key, Compare, Alloc>& y) {
x.swap(y);
template <class _Key, class _Compare, class _Alloc>
inline void swap(set<_Key,_Compare,_Alloc>& __x,
set<_Key,_Compare,_Alloc>& __y) {
__x.swap(__y);
}
#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
#pragma reset woff 1174
#pragma reset woff 1375
#endif
__STL_END_NAMESPACE

File diff suppressed because it is too large Load Diff

View File

@ -34,39 +34,74 @@
__STL_BEGIN_NAMESPACE
#ifndef __STL_LIMITED_DEFAULT_TEMPLATES
template <class T, class Sequence = deque<T> >
template <class _Tp, class _Sequence = deque<_Tp> >
#else
template <class T, class Sequence>
template <class _Tp, class _Sequence>
#endif
class stack {
friend bool operator== __STL_NULL_TMPL_ARGS (const stack&, const stack&);
friend bool operator< __STL_NULL_TMPL_ARGS (const stack&, const stack&);
public:
typedef typename Sequence::value_type value_type;
typedef typename Sequence::size_type size_type;
typedef typename Sequence::reference reference;
typedef typename Sequence::const_reference const_reference;
typedef typename _Sequence::value_type value_type;
typedef typename _Sequence::size_type size_type;
typedef _Sequence container_type;
typedef typename _Sequence::reference reference;
typedef typename _Sequence::const_reference const_reference;
protected:
Sequence c;
_Sequence _M_c;
public:
bool empty() const { return c.empty(); }
size_type size() const { return c.size(); }
reference top() { return c.back(); }
const_reference top() const { return c.back(); }
void push(const value_type& x) { c.push_back(x); }
void pop() { c.pop_back(); }
stack() : _M_c() {}
explicit stack(const _Sequence& __s) : _M_c(__s) {}
bool empty() const { return _M_c.empty(); }
size_type size() const { return _M_c.size(); }
reference top() { return _M_c.back(); }
const_reference top() const { return _M_c.back(); }
void push(const value_type& __x) { _M_c.push_back(__x); }
void pop() { _M_c.pop_back(); }
};
template <class T, class Sequence>
bool operator==(const stack<T, Sequence>& x, const stack<T, Sequence>& y) {
return x.c == y.c;
template <class _Tp, class _Seq>
bool operator==(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
{
return __x._M_c == __y._M_c;
}
template <class T, class Sequence>
bool operator<(const stack<T, Sequence>& x, const stack<T, Sequence>& y) {
return x.c < y.c;
template <class _Tp, class _Seq>
bool operator<(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
{
return __x._M_c < __y._M_c;
}
#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
template <class _Tp, class _Seq>
bool operator!=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
{
return !(__x == __y);
}
template <class _Tp, class _Seq>
bool operator>(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
{
return __y < __x;
}
template <class _Tp, class _Seq>
bool operator<=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
{
return !(__y < __x);
}
template <class _Tp, class _Seq>
bool operator>=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
{
return !(__x < __y);
}
#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
__STL_END_NAMESPACE
#endif /* __SGI_STL_INTERNAL_STACK_H */

View File

@ -34,86 +34,119 @@
__STL_BEGIN_NAMESPACE
template <class T>
pair<T*, ptrdiff_t> get_temporary_buffer(ptrdiff_t len, T*) {
if (len > ptrdiff_t(INT_MAX / sizeof(T)))
len = INT_MAX / sizeof(T);
template <class _Tp>
pair<_Tp*, ptrdiff_t>
__get_temporary_buffer(ptrdiff_t __len, _Tp*)
{
if (__len > ptrdiff_t(INT_MAX / sizeof(_Tp)))
__len = INT_MAX / sizeof(_Tp);
while (len > 0) {
T* tmp = (T*) malloc((size_t)len * sizeof(T));
if (tmp != 0)
return pair<T*, ptrdiff_t>(tmp, len);
len /= 2;
while (__len > 0) {
_Tp* __tmp = (_Tp*) malloc((size_t)__len * sizeof(_Tp));
if (__tmp != 0)
return pair<_Tp*, ptrdiff_t>(__tmp, __len);
__len /= 2;
}
return pair<T*, ptrdiff_t>((T*)0, 0);
return pair<_Tp*, ptrdiff_t>((_Tp*)0, 0);
}
template <class T>
void return_temporary_buffer(T* p) {
free(p);
#ifdef __STL_EXPLICIT_FUNCTION_TMPL_ARGS
template <class _Tp>
inline pair<_Tp*, ptrdiff_t> get_temporary_buffer(ptrdiff_t __len) {
return __get_temporary_buffer(__len, (_Tp*) 0);
}
template <class ForwardIterator,
class T
#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
= iterator_traits<ForwardIterator>::value_type
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
>
class temporary_buffer {
#endif /* __STL_EXPLICIT_FUNCTION_TMPL_ARGS */
// This overload is not required by the standard; it is an extension.
// It is supported for backward compatibility with the HP STL, and
// because not all compilers support the language feature (explicit
// function template arguments) that is required for the standard
// version of get_temporary_buffer.
template <class _Tp>
inline pair<_Tp*, ptrdiff_t> get_temporary_buffer(ptrdiff_t __len, _Tp*) {
return __get_temporary_buffer(__len, (_Tp*) 0);
}
template <class _Tp>
void return_temporary_buffer(_Tp* __p) {
free(__p);
}
template <class _ForwardIterator, class _Tp>
class _Temporary_buffer {
private:
ptrdiff_t original_len;
ptrdiff_t len;
T* buffer;
ptrdiff_t _M_original_len;
ptrdiff_t _M_len;
_Tp* _M_buffer;
void allocate_buffer() {
original_len = len;
buffer = 0;
void _M_allocate_buffer() {
_M_original_len = _M_len;
_M_buffer = 0;
if (len > (ptrdiff_t)(INT_MAX / sizeof(T)))
len = INT_MAX / sizeof(T);
if (_M_len > (ptrdiff_t)(INT_MAX / sizeof(_Tp)))
_M_len = INT_MAX / sizeof(_Tp);
while (len > 0) {
buffer = (T*) malloc(len * sizeof(T));
if (buffer)
while (_M_len > 0) {
_M_buffer = (_Tp*) malloc(_M_len * sizeof(_Tp));
if (_M_buffer)
break;
len /= 2;
_M_len /= 2;
}
}
void initialize_buffer(const T&, __true_type) {}
void initialize_buffer(const T& val, __false_type) {
uninitialized_fill_n(buffer, len, val);
void _M_initialize_buffer(const _Tp&, __true_type) {}
void _M_initialize_buffer(const _Tp& val, __false_type) {
uninitialized_fill_n(_M_buffer, _M_len, val);
}
public:
ptrdiff_t size() const { return len; }
ptrdiff_t requested_size() const { return original_len; }
T* begin() { return buffer; }
T* end() { return buffer + len; }
ptrdiff_t size() const { return _M_len; }
ptrdiff_t requested_size() const { return _M_original_len; }
_Tp* begin() { return _M_buffer; }
_Tp* end() { return _M_buffer + _M_len; }
temporary_buffer(ForwardIterator first, ForwardIterator last) {
_Temporary_buffer(_ForwardIterator __first, _ForwardIterator __last) {
typedef typename __type_traits<_Tp>::has_trivial_default_constructor
_Trivial;
__STL_TRY {
len = 0;
distance(first, last, len);
allocate_buffer();
if (len > 0)
initialize_buffer(*first,
typename __type_traits<T>::has_trivial_default_constructor());
_M_len = 0;
distance(__first, __last, _M_len);
_M_allocate_buffer();
if (_M_len > 0)
_M_initialize_buffer(*__first, _Trivial());
}
__STL_UNWIND(free(buffer); buffer = 0; len = 0);
__STL_UNWIND(free(_M_buffer); _M_buffer = 0; _M_len = 0);
}
~temporary_buffer() {
destroy(buffer, buffer + len);
free(buffer);
~_Temporary_buffer() {
destroy(_M_buffer, _M_buffer + _M_len);
free(_M_buffer);
}
private:
temporary_buffer(const temporary_buffer&) {}
void operator=(const temporary_buffer&) {}
// Disable copy constructor and assignment operator.
_Temporary_buffer(const _Temporary_buffer&) {}
void operator=(const _Temporary_buffer&) {}
};
// Class temporary_buffer is not part of the standard. It is an extension.
template <class _ForwardIterator,
class _Tp
#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
= typename iterator_traits<_ForwardIterator>::value_type
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
>
struct temporary_buffer : public _Temporary_buffer<_ForwardIterator, _Tp>
{
temporary_buffer(_ForwardIterator __first, _ForwardIterator __last)
: _Temporary_buffer<_ForwardIterator, _Tp>(__first, __last) {}
~temporary_buffer() {}
};
__STL_END_NAMESPACE
#endif /* __SGI_STL_INTERNAL_TEMPBUF_H */

File diff suppressed because it is too large Load Diff

View File

@ -33,204 +33,241 @@
__STL_BEGIN_NAMESPACE
// uninitialized_copy
// Valid if copy construction is equivalent to assignment, and if the
// destructor is trivial.
template <class InputIterator, class ForwardIterator>
inline ForwardIterator
__uninitialized_copy_aux(InputIterator first, InputIterator last,
ForwardIterator result,
__true_type) {
return copy(first, last, result);
template <class _InputIter, class _ForwardIter>
inline _ForwardIter
__uninitialized_copy_aux(_InputIter __first, _InputIter __last,
_ForwardIter __result,
__true_type)
{
return copy(__first, __last, __result);
}
template <class InputIterator, class ForwardIterator>
ForwardIterator
__uninitialized_copy_aux(InputIterator first, InputIterator last,
ForwardIterator result,
__false_type) {
ForwardIterator cur = result;
template <class _InputIter, class _ForwardIter>
_ForwardIter
__uninitialized_copy_aux(_InputIter __first, _InputIter __last,
_ForwardIter __result,
__false_type)
{
_ForwardIter __cur = __result;
__STL_TRY {
for ( ; first != last; ++first, ++cur)
construct(&*cur, *first);
return cur;
for ( ; __first != __last; ++__first, ++__cur)
construct(&*__cur, *__first);
return __cur;
}
__STL_UNWIND(destroy(result, cur));
__STL_UNWIND(destroy(__result, __cur));
}
template <class InputIterator, class ForwardIterator, class T>
inline ForwardIterator
__uninitialized_copy(InputIterator first, InputIterator last,
ForwardIterator result, T*) {
typedef typename __type_traits<T>::is_POD_type is_POD;
return __uninitialized_copy_aux(first, last, result, is_POD());
template <class _InputIter, class _ForwardIter, class _Tp>
inline _ForwardIter
__uninitialized_copy(_InputIter __first, _InputIter __last,
_ForwardIter __result, _Tp*)
{
typedef typename __type_traits<_Tp>::is_POD_type _Is_POD;
return __uninitialized_copy_aux(__first, __last, __result, _Is_POD());
}
template <class InputIterator, class ForwardIterator>
inline ForwardIterator
uninitialized_copy(InputIterator first, InputIterator last,
ForwardIterator result) {
return __uninitialized_copy(first, last, result, value_type(result));
template <class _InputIter, class _ForwardIter>
inline _ForwardIter
uninitialized_copy(_InputIter __first, _InputIter __last,
_ForwardIter __result)
{
return __uninitialized_copy(__first, __last, __result,
__VALUE_TYPE(__result));
}
inline char* uninitialized_copy(const char* first, const char* last,
char* result) {
memmove(result, first, last - first);
return result + (last - first);
inline char* uninitialized_copy(const char* __first, const char* __last,
char* __result) {
memmove(__result, __first, __last - __first);
return __result + (__last - __first);
}
inline wchar_t* uninitialized_copy(const wchar_t* first, const wchar_t* last,
wchar_t* result) {
memmove(result, first, sizeof(wchar_t) * (last - first));
return result + (last - first);
inline wchar_t*
uninitialized_copy(const wchar_t* __first, const wchar_t* __last,
wchar_t* __result)
{
memmove(__result, __first, sizeof(wchar_t) * (__last - __first));
return __result + (__last - __first);
}
template <class InputIterator, class Size, class ForwardIterator>
pair<InputIterator, ForwardIterator>
__uninitialized_copy_n(InputIterator first, Size count,
ForwardIterator result,
input_iterator_tag) {
ForwardIterator cur = result;
// uninitialized_copy_n (not part of the C++ standard)
template <class _InputIter, class _Size, class _ForwardIter>
pair<_InputIter, _ForwardIter>
__uninitialized_copy_n(_InputIter __first, _Size __count,
_ForwardIter __result,
input_iterator_tag)
{
_ForwardIter __cur = __result;
__STL_TRY {
for ( ; count > 0 ; --count, ++first, ++cur)
construct(&*cur, *first);
return pair<InputIterator, ForwardIterator>(first, cur);
for ( ; __count > 0 ; --__count, ++__first, ++__cur)
construct(&*__cur, *__first);
return pair<_InputIter, _ForwardIter>(__first, __cur);
}
__STL_UNWIND(destroy(result, cur));
__STL_UNWIND(destroy(__result, __cur));
}
template <class RandomAccessIterator, class Size, class ForwardIterator>
inline pair<RandomAccessIterator, ForwardIterator>
__uninitialized_copy_n(RandomAccessIterator first, Size count,
ForwardIterator result,
template <class _RandomAccessIter, class _Size, class _ForwardIter>
inline pair<_RandomAccessIter, _ForwardIter>
__uninitialized_copy_n(_RandomAccessIter __first, _Size __count,
_ForwardIter __result,
random_access_iterator_tag) {
RandomAccessIterator last = first + count;
return make_pair(last, uninitialized_copy(first, last, result));
_RandomAccessIter __last = __first + __count;
return pair<_RandomAccessIter, _ForwardIter>(
__last,
uninitialized_copy(__first, __last, __result));
}
template <class InputIterator, class Size, class ForwardIterator>
inline pair<InputIterator, ForwardIterator>
uninitialized_copy_n(InputIterator first, Size count,
ForwardIterator result) {
return __uninitialized_copy_n(first, count, result,
iterator_category(first));
template <class _InputIter, class _Size, class _ForwardIter>
inline pair<_InputIter, _ForwardIter>
__uninitialized_copy_n(_InputIter __first, _Size __count,
_ForwardIter __result) {
return __uninitialized_copy_n(__first, __count, __result,
__ITERATOR_CATEGORY(__first));
}
template <class _InputIter, class _Size, class _ForwardIter>
inline pair<_InputIter, _ForwardIter>
uninitialized_copy_n(_InputIter __first, _Size __count,
_ForwardIter __result) {
return __uninitialized_copy_n(__first, __count, __result,
__ITERATOR_CATEGORY(__first));
}
// Valid if copy construction is equivalent to assignment, and if the
// destructor is trivial.
template <class ForwardIterator, class T>
// destructor is trivial.
template <class _ForwardIter, class _Tp>
inline void
__uninitialized_fill_aux(ForwardIterator first, ForwardIterator last,
const T& x, __true_type)
__uninitialized_fill_aux(_ForwardIter __first, _ForwardIter __last,
const _Tp& __x, __true_type)
{
fill(first, last, x);
fill(__first, __last, __x);
}
template <class ForwardIterator, class T>
template <class _ForwardIter, class _Tp>
void
__uninitialized_fill_aux(ForwardIterator first, ForwardIterator last,
const T& x, __false_type)
__uninitialized_fill_aux(_ForwardIter __first, _ForwardIter __last,
const _Tp& __x, __false_type)
{
ForwardIterator cur = first;
_ForwardIter __cur = __first;
__STL_TRY {
for ( ; cur != last; ++cur)
construct(&*cur, x);
for ( ; __cur != __last; ++__cur)
construct(&*__cur, __x);
}
__STL_UNWIND(destroy(first, cur));
__STL_UNWIND(destroy(__first, __cur));
}
template <class ForwardIterator, class T, class T1>
inline void __uninitialized_fill(ForwardIterator first, ForwardIterator last,
const T& x, T1*) {
typedef typename __type_traits<T1>::is_POD_type is_POD;
__uninitialized_fill_aux(first, last, x, is_POD());
template <class _ForwardIter, class _Tp, class _Tp1>
inline void __uninitialized_fill(_ForwardIter __first,
_ForwardIter __last, const _Tp& __x, _Tp1*)
{
typedef typename __type_traits<_Tp1>::is_POD_type _Is_POD;
__uninitialized_fill_aux(__first, __last, __x, _Is_POD());
}
template <class ForwardIterator, class T>
inline void uninitialized_fill(ForwardIterator first, ForwardIterator last,
const T& x) {
__uninitialized_fill(first, last, x, value_type(first));
template <class _ForwardIter, class _Tp>
inline void uninitialized_fill(_ForwardIter __first,
_ForwardIter __last,
const _Tp& __x)
{
__uninitialized_fill(__first, __last, __x, __VALUE_TYPE(__first));
}
// Valid if copy construction is equivalent to assignment, and if the
// destructor is trivial.
template <class ForwardIterator, class Size, class T>
inline ForwardIterator
__uninitialized_fill_n_aux(ForwardIterator first, Size n,
const T& x, __true_type) {
return fill_n(first, n, x);
template <class _ForwardIter, class _Size, class _Tp>
inline _ForwardIter
__uninitialized_fill_n_aux(_ForwardIter __first, _Size __n,
const _Tp& __x, __true_type)
{
return fill_n(__first, __n, __x);
}
template <class ForwardIterator, class Size, class T>
ForwardIterator
__uninitialized_fill_n_aux(ForwardIterator first, Size n,
const T& x, __false_type) {
ForwardIterator cur = first;
template <class _ForwardIter, class _Size, class _Tp>
_ForwardIter
__uninitialized_fill_n_aux(_ForwardIter __first, _Size __n,
const _Tp& __x, __false_type)
{
_ForwardIter __cur = __first;
__STL_TRY {
for ( ; n > 0; --n, ++cur)
construct(&*cur, x);
return cur;
for ( ; __n > 0; --__n, ++__cur)
construct(&*__cur, __x);
return __cur;
}
__STL_UNWIND(destroy(first, cur));
__STL_UNWIND(destroy(__first, __cur));
}
template <class ForwardIterator, class Size, class T, class T1>
inline ForwardIterator __uninitialized_fill_n(ForwardIterator first, Size n,
const T& x, T1*) {
typedef typename __type_traits<T1>::is_POD_type is_POD;
return __uninitialized_fill_n_aux(first, n, x, is_POD());
template <class _ForwardIter, class _Size, class _Tp, class _Tp1>
inline _ForwardIter
__uninitialized_fill_n(_ForwardIter __first, _Size __n, const _Tp& __x, _Tp1*)
{
typedef typename __type_traits<_Tp1>::is_POD_type _Is_POD;
return __uninitialized_fill_n_aux(__first, __n, __x, _Is_POD());
}
template <class ForwardIterator, class Size, class T>
inline ForwardIterator uninitialized_fill_n(ForwardIterator first, Size n,
const T& x) {
return __uninitialized_fill_n(first, n, x, value_type(first));
template <class _ForwardIter, class _Size, class _Tp>
inline _ForwardIter
uninitialized_fill_n(_ForwardIter __first, _Size __n, const _Tp& __x)
{
return __uninitialized_fill_n(__first, __n, __x, __VALUE_TYPE(__first));
}
// Extensions: __uninitialized_copy_copy, __uninitialized_copy_fill,
// __uninitialized_fill_copy.
// __uninitialized_copy_copy
// Copies [first1, last1) into [result, result + (last1 - first1)), and
// copies [first2, last2) into
// [result, result + (last1 - first1) + (last2 - first2)).
template <class InputIterator1, class InputIterator2, class ForwardIterator>
inline ForwardIterator
__uninitialized_copy_copy(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
ForwardIterator result) {
ForwardIterator mid = uninitialized_copy(first1, last1, result);
template <class _InputIter1, class _InputIter2, class _ForwardIter>
inline _ForwardIter
__uninitialized_copy_copy(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2,
_ForwardIter __result)
{
_ForwardIter __mid = uninitialized_copy(__first1, __last1, __result);
__STL_TRY {
return uninitialized_copy(first2, last2, mid);
return uninitialized_copy(__first2, __last2, __mid);
}
__STL_UNWIND(destroy(result, mid));
__STL_UNWIND(destroy(__result, __mid));
}
// __uninitialized_fill_copy
// Fills [result, mid) with x, and copies [first, last) into
// [mid, mid + (last - first)).
template <class ForwardIterator, class T, class InputIterator>
inline ForwardIterator
__uninitialized_fill_copy(ForwardIterator result, ForwardIterator mid,
const T& x,
InputIterator first, InputIterator last) {
uninitialized_fill(result, mid, x);
template <class _ForwardIter, class _Tp, class _InputIter>
inline _ForwardIter
__uninitialized_fill_copy(_ForwardIter __result, _ForwardIter __mid,
const _Tp& __x,
_InputIter __first, _InputIter __last)
{
uninitialized_fill(__result, __mid, __x);
__STL_TRY {
return uninitialized_copy(first, last, mid);
return uninitialized_copy(__first, __last, __mid);
}
__STL_UNWIND(destroy(result, mid));
__STL_UNWIND(destroy(__result, __mid));
}
// __uninitialized_copy_fill
// Copies [first1, last1) into [first2, first2 + (last1 - first1)), and
// fills [first2 + (last1 - first1), last2) with x.
template <class InputIterator, class ForwardIterator, class T>
template <class _InputIter, class _ForwardIter, class _Tp>
inline void
__uninitialized_copy_fill(InputIterator first1, InputIterator last1,
ForwardIterator first2, ForwardIterator last2,
const T& x) {
ForwardIterator mid2 = uninitialized_copy(first1, last1, first2);
__uninitialized_copy_fill(_InputIter __first1, _InputIter __last1,
_ForwardIter __first2, _ForwardIter __last2,
const _Tp& __x)
{
_ForwardIter __mid2 = uninitialized_copy(__first1, __last1, __first2);
__STL_TRY {
uninitialized_fill(mid2, last2, x);
uninitialized_fill(__mid2, __last2, __x);
}
__STL_UNWIND(destroy(first2, mid2));
__STL_UNWIND(destroy(__first2, __mid2));
}
__STL_END_NAMESPACE

File diff suppressed because it is too large Load Diff

View File

@ -30,15 +30,18 @@
#ifndef __SGI_STL_PAIR_H
#include <pair.h>
#endif
#include <limits.h>
#include <stddef.h>
#include <stdlib.h>
#include <limits.h> /* XXX should use <climits> */
#include <stddef.h> /* XXX should use <cstddef> */
#include <stdlib.h> /* XXX should use <cstdlib> */
#ifndef __TYPE_TRAITS_H
#include <type_traits.h>
#endif
#ifndef __SGI_STL_INTERNAL_CONSTRUCT_H
#include <stl_construct.h>
#endif
#ifndef __SGI_STL_INTERNAL_UNINITIALIZED_H
#include <stl_uninitialized.h>
#endif
#ifndef __SGI_STL_INTERNAL_TEMPBUF_H
#include <stl_tempbuf.h>
#endif

View File

@ -40,13 +40,14 @@ attain their correct values by one of these means:
EXAMPLE:
//Copy an array of elements which have non-trivial copy constructors
template <class T> void copy(T* source,T* destination,int n,__false_type);
template <class T> void copy(T* source, T* destination, int n, __false_type);
//Copy an array of elements which have trivial copy constructors. Use memcpy.
template <class T> void copy(T* source,T* destination,int n,__true_type);
template <class T> void copy(T* source, T* destination, int n, __true_type);
//Copy an array of any type by using the most efficient copy mechanism
template <class T> inline void copy(T* source,T* destination,int n) {
copy(source,destination,n,typename __type_traits<T>::has_trivial_copy_constructor());
copy(source, destination, n,
typename __type_traits<T>::has_trivial_copy_constructor());
}
*/
@ -57,7 +58,7 @@ struct __true_type {
struct __false_type {
};
template <class type>
template <class _Tp>
struct __type_traits {
typedef __true_type this_dummy_member_must_be_first;
/* Do not remove this member. It informs a compiler which
@ -90,6 +91,18 @@ struct __type_traits {
// have built-in __types_traits support, and essential for compilers
// that don't.
#ifndef __STL_NO_BOOL
__STL_TEMPLATE_NULL struct __type_traits<bool> {
typedef __true_type has_trivial_default_constructor;
typedef __true_type has_trivial_copy_constructor;
typedef __true_type has_trivial_assignment_operator;
typedef __true_type has_trivial_destructor;
typedef __true_type is_POD_type;
};
#endif /* __STL_NO_BOOL */
__STL_TEMPLATE_NULL struct __type_traits<char> {
typedef __true_type has_trivial_default_constructor;
typedef __true_type has_trivial_copy_constructor;
@ -114,6 +127,18 @@ __STL_TEMPLATE_NULL struct __type_traits<unsigned char> {
typedef __true_type is_POD_type;
};
#ifdef __STL_HAS_WCHAR_T
__STL_TEMPLATE_NULL struct __type_traits<wchar_t> {
typedef __true_type has_trivial_default_constructor;
typedef __true_type has_trivial_copy_constructor;
typedef __true_type has_trivial_assignment_operator;
typedef __true_type has_trivial_destructor;
typedef __true_type is_POD_type;
};
#endif /* __STL_HAS_WCHAR_T */
__STL_TEMPLATE_NULL struct __type_traits<short> {
typedef __true_type has_trivial_default_constructor;
typedef __true_type has_trivial_copy_constructor;
@ -162,6 +187,26 @@ __STL_TEMPLATE_NULL struct __type_traits<unsigned long> {
typedef __true_type is_POD_type;
};
#ifdef __STL_LONG_LONG
__STL_TEMPLATE_NULL struct __type_traits<long long> {
typedef __true_type has_trivial_default_constructor;
typedef __true_type has_trivial_copy_constructor;
typedef __true_type has_trivial_assignment_operator;
typedef __true_type has_trivial_destructor;
typedef __true_type is_POD_type;
};
__STL_TEMPLATE_NULL struct __type_traits<unsigned long long> {
typedef __true_type has_trivial_default_constructor;
typedef __true_type has_trivial_copy_constructor;
typedef __true_type has_trivial_assignment_operator;
typedef __true_type has_trivial_destructor;
typedef __true_type is_POD_type;
};
#endif /* __STL_LONG_LONG */
__STL_TEMPLATE_NULL struct __type_traits<float> {
typedef __true_type has_trivial_default_constructor;
typedef __true_type has_trivial_copy_constructor;
@ -188,8 +233,8 @@ __STL_TEMPLATE_NULL struct __type_traits<long double> {
#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
template <class T>
struct __type_traits<T*> {
template <class _Tp>
struct __type_traits<_Tp*> {
typedef __true_type has_trivial_default_constructor;
typedef __true_type has_trivial_copy_constructor;
typedef __true_type has_trivial_assignment_operator;
@ -199,7 +244,7 @@ struct __type_traits<T*> {
#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
struct __type_traits<char*> {
__STL_TEMPLATE_NULL struct __type_traits<char*> {
typedef __true_type has_trivial_default_constructor;
typedef __true_type has_trivial_copy_constructor;
typedef __true_type has_trivial_assignment_operator;
@ -207,7 +252,7 @@ struct __type_traits<char*> {
typedef __true_type is_POD_type;
};
struct __type_traits<signed char*> {
__STL_TEMPLATE_NULL struct __type_traits<signed char*> {
typedef __true_type has_trivial_default_constructor;
typedef __true_type has_trivial_copy_constructor;
typedef __true_type has_trivial_assignment_operator;
@ -215,7 +260,31 @@ struct __type_traits<signed char*> {
typedef __true_type is_POD_type;
};
struct __type_traits<unsigned char*> {
__STL_TEMPLATE_NULL struct __type_traits<unsigned char*> {
typedef __true_type has_trivial_default_constructor;
typedef __true_type has_trivial_copy_constructor;
typedef __true_type has_trivial_assignment_operator;
typedef __true_type has_trivial_destructor;
typedef __true_type is_POD_type;
};
__STL_TEMPLATE_NULL struct __type_traits<const char*> {
typedef __true_type has_trivial_default_constructor;
typedef __true_type has_trivial_copy_constructor;
typedef __true_type has_trivial_assignment_operator;
typedef __true_type has_trivial_destructor;
typedef __true_type is_POD_type;
};
__STL_TEMPLATE_NULL struct __type_traits<const signed char*> {
typedef __true_type has_trivial_default_constructor;
typedef __true_type has_trivial_copy_constructor;
typedef __true_type has_trivial_assignment_operator;
typedef __true_type has_trivial_destructor;
typedef __true_type is_POD_type;
};
__STL_TEMPLATE_NULL struct __type_traits<const unsigned char*> {
typedef __true_type has_trivial_default_constructor;
typedef __true_type has_trivial_copy_constructor;
typedef __true_type has_trivial_assignment_operator;
@ -226,6 +295,77 @@ struct __type_traits<unsigned char*> {
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
// The following could be written in terms of numeric_limits.
// We're doing it separately to reduce the number of dependencies.
template <class _Tp> struct _Is_integer {
typedef __false_type _Integral;
};
#ifndef __STL_NO_BOOL
__STL_TEMPLATE_NULL struct _Is_integer<bool> {
typedef __true_type _Integral;
};
#endif /* __STL_NO_BOOL */
__STL_TEMPLATE_NULL struct _Is_integer<char> {
typedef __true_type _Integral;
};
__STL_TEMPLATE_NULL struct _Is_integer<signed char> {
typedef __true_type _Integral;
};
__STL_TEMPLATE_NULL struct _Is_integer<unsigned char> {
typedef __true_type _Integral;
};
#ifdef __STL_HAS_WCHAR_T
__STL_TEMPLATE_NULL struct _Is_integer<wchar_t> {
typedef __true_type _Integral;
};
#endif /* __STL_HAS_WCHAR_T */
__STL_TEMPLATE_NULL struct _Is_integer<short> {
typedef __true_type _Integral;
};
__STL_TEMPLATE_NULL struct _Is_integer<unsigned short> {
typedef __true_type _Integral;
};
__STL_TEMPLATE_NULL struct _Is_integer<int> {
typedef __true_type _Integral;
};
__STL_TEMPLATE_NULL struct _Is_integer<unsigned int> {
typedef __true_type _Integral;
};
__STL_TEMPLATE_NULL struct _Is_integer<long> {
typedef __true_type _Integral;
};
__STL_TEMPLATE_NULL struct _Is_integer<unsigned long> {
typedef __true_type _Integral;
};
#ifdef __STL_LONG_LONG
__STL_TEMPLATE_NULL struct _Is_integer<long long> {
typedef __true_type _Integral;
};
__STL_TEMPLATE_NULL struct _Is_integer<unsigned long long> {
typedef __true_type _Integral;
};
#endif /* __STL_LONG_LONG */
#endif /* __TYPE_TRAITS_H */
// Local Variables: