mirror of
https://github.com/Kitware/CMake.git
synced 2025-12-30 18:29:37 -06:00
Merge branch 'upstream-KWSys' into update-kwsys
# By KWSys Upstream * upstream-KWSys: KWSys 2020-05-27 (a3263389)
This commit is contained in:
@@ -146,7 +146,6 @@ if(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
|
||||
set(KWSYS_USE_SystemTools 1)
|
||||
set(KWSYS_USE_CommandLineArguments 1)
|
||||
set(KWSYS_USE_Terminal 1)
|
||||
set(KWSYS_USE_IOStream 1)
|
||||
set(KWSYS_USE_FStream 1)
|
||||
set(KWSYS_USE_String 1)
|
||||
set(KWSYS_USE_SystemInformation 1)
|
||||
@@ -360,67 +359,12 @@ endif()
|
||||
# capabilities and parent project's request. Enforce 0/1 as only
|
||||
# possible values for configuration into Configure.hxx.
|
||||
|
||||
# Check existence and uniqueness of long long and __int64.
|
||||
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_LONG_LONG
|
||||
"Checking whether C++ compiler has 'long long'" DIRECT)
|
||||
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS___INT64
|
||||
"Checking whether C++ compiler has '__int64'" DIRECT)
|
||||
if(KWSYS_CXX_HAS___INT64)
|
||||
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_SAME_LONG_AND___INT64
|
||||
"Checking whether long and __int64 are the same type" DIRECT)
|
||||
if(KWSYS_CXX_HAS_LONG_LONG)
|
||||
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_SAME_LONG_LONG_AND___INT64
|
||||
"Checking whether long long and __int64 are the same type" DIRECT)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Enable the "long long" type if it is available. It is standard in
|
||||
# C99 and C++03 but not in earlier standards.
|
||||
if(KWSYS_CXX_HAS_LONG_LONG)
|
||||
set(KWSYS_USE_LONG_LONG 1)
|
||||
else()
|
||||
set(KWSYS_USE_LONG_LONG 0)
|
||||
endif()
|
||||
|
||||
# Enable the "__int64" type if it is available and unique. It is not
|
||||
# standard.
|
||||
set(KWSYS_USE___INT64 0)
|
||||
if(KWSYS_CXX_HAS___INT64)
|
||||
if(NOT KWSYS_CXX_SAME_LONG_AND___INT64)
|
||||
if(NOT KWSYS_CXX_SAME_LONG_LONG_AND___INT64)
|
||||
set(KWSYS_USE___INT64 1)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(KWSYS_USE_Encoding)
|
||||
# Look for type size helper macros.
|
||||
KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_WSTRING
|
||||
"Checking whether wstring is available" DIRECT)
|
||||
endif()
|
||||
|
||||
if(KWSYS_USE_IOStream)
|
||||
# Determine whether iostreams support long long.
|
||||
if(KWSYS_CXX_HAS_LONG_LONG)
|
||||
KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAS_ISTREAM_LONG_LONG
|
||||
"Checking if istream supports long long" DIRECT)
|
||||
KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAS_OSTREAM_LONG_LONG
|
||||
"Checking if ostream supports long long" DIRECT)
|
||||
else()
|
||||
set(KWSYS_IOS_HAS_ISTREAM_LONG_LONG 0)
|
||||
set(KWSYS_IOS_HAS_OSTREAM_LONG_LONG 0)
|
||||
endif()
|
||||
if(KWSYS_CXX_HAS___INT64)
|
||||
KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAS_ISTREAM___INT64
|
||||
"Checking if istream supports __int64" DIRECT)
|
||||
KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAS_OSTREAM___INT64
|
||||
"Checking if ostream supports __int64" DIRECT)
|
||||
else()
|
||||
set(KWSYS_IOS_HAS_ISTREAM___INT64 0)
|
||||
set(KWSYS_IOS_HAS_OSTREAM___INT64 0)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(KWSYS_NAMESPACE MATCHES "^kwsys$")
|
||||
set(KWSYS_NAME_IS_KWSYS 1)
|
||||
else()
|
||||
@@ -569,24 +513,6 @@ if(KWSYS_USE_SystemInformation)
|
||||
set_property(SOURCE SystemInformation.cxx APPEND PROPERTY
|
||||
COMPILE_DEFINITIONS KWSYS_CXX_HAS_RLIMIT64=1)
|
||||
endif()
|
||||
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_ATOL
|
||||
"Checking whether CXX compiler has atol" DIRECT)
|
||||
if(KWSYS_CXX_HAS_ATOL)
|
||||
set_property(SOURCE SystemInformation.cxx APPEND PROPERTY
|
||||
COMPILE_DEFINITIONS KWSYS_CXX_HAS_ATOL=1)
|
||||
endif()
|
||||
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_ATOLL
|
||||
"Checking whether CXX compiler has atoll" DIRECT)
|
||||
if(KWSYS_CXX_HAS_ATOLL)
|
||||
set_property(SOURCE SystemInformation.cxx APPEND PROPERTY
|
||||
COMPILE_DEFINITIONS KWSYS_CXX_HAS_ATOLL=1)
|
||||
endif()
|
||||
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS__ATOI64
|
||||
"Checking whether CXX compiler has _atoi64" DIRECT)
|
||||
if(KWSYS_CXX_HAS__ATOI64)
|
||||
set_property(SOURCE SystemInformation.cxx APPEND PROPERTY
|
||||
COMPILE_DEFINITIONS KWSYS_CXX_HAS__ATOI64=1)
|
||||
endif()
|
||||
if(UNIX)
|
||||
include(CheckIncludeFileCXX)
|
||||
# check for simple stack trace
|
||||
@@ -650,36 +576,6 @@ if(KWSYS_USE_SystemInformation)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
if(BORLAND)
|
||||
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_BORLAND_ASM
|
||||
"Checking whether Borland CXX compiler supports assembler instructions" DIRECT)
|
||||
if(KWSYS_CXX_HAS_BORLAND_ASM)
|
||||
set_property(SOURCE SystemInformation.cxx APPEND PROPERTY
|
||||
COMPILE_DEFINITIONS KWSYS_CXX_HAS_BORLAND_ASM=1)
|
||||
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_BORLAND_ASM_CPUID
|
||||
"Checking whether Borland CXX compiler supports CPUID assembler instruction" DIRECT)
|
||||
if(KWSYS_CXX_HAS_BORLAND_ASM_CPUID)
|
||||
set_property(SOURCE SystemInformation.cxx APPEND PROPERTY
|
||||
COMPILE_DEFINITIONS KWSYS_CXX_HAS_BORLAND_ASM_CPUID=1)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
if(KWSYS_USE___INT64)
|
||||
set_property(SOURCE SystemInformation.cxx testSystemInformation.cxx APPEND PROPERTY
|
||||
COMPILE_DEFINITIONS KWSYS_USE___INT64=1)
|
||||
endif()
|
||||
if(KWSYS_USE_LONG_LONG)
|
||||
set_property(SOURCE SystemInformation.cxx testSystemInformation.cxx APPEND PROPERTY
|
||||
COMPILE_DEFINITIONS KWSYS_USE_LONG_LONG=1)
|
||||
endif()
|
||||
if(KWSYS_IOS_HAS_OSTREAM_LONG_LONG)
|
||||
set_property(SOURCE SystemInformation.cxx testSystemInformation.cxx APPEND PROPERTY
|
||||
COMPILE_DEFINITIONS KWSYS_IOS_HAS_OSTREAM_LONG_LONG=1)
|
||||
endif()
|
||||
if(KWSYS_IOS_HAS_OSTREAM___INT64)
|
||||
set_property(SOURCE SystemInformation.cxx testSystemInformation.cxx APPEND PROPERTY
|
||||
COMPILE_DEFINITIONS KWSYS_IOS_HAS_OSTREAM___INT64=1)
|
||||
endif()
|
||||
if(KWSYS_BUILD_SHARED)
|
||||
set_property(SOURCE SystemInformation.cxx APPEND PROPERTY
|
||||
COMPILE_DEFINITIONS KWSYS_BUILD_SHARED=1)
|
||||
@@ -731,16 +627,10 @@ set(KWSYS_CLASSES)
|
||||
set(KWSYS_H_FILES Configure SharedForward)
|
||||
set(KWSYS_HXX_FILES Configure String)
|
||||
|
||||
if(NOT CMake_SOURCE_DIR)
|
||||
set(KWSYS_HXX_FILES ${KWSYS_HXX_FILES}
|
||||
hashtable hash_fun hash_map hash_set
|
||||
)
|
||||
endif()
|
||||
|
||||
# Add selected C++ classes.
|
||||
set(cppclasses
|
||||
Directory DynamicLoader Encoding Glob RegularExpression SystemTools
|
||||
CommandLineArguments IOStream FStream SystemInformation ConsoleBuf
|
||||
CommandLineArguments FStream SystemInformation ConsoleBuf
|
||||
)
|
||||
foreach(cpp ${cppclasses})
|
||||
if(KWSYS_USE_${cpp})
|
||||
@@ -1071,11 +961,6 @@ if(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
|
||||
endforeach()
|
||||
|
||||
# C++ tests
|
||||
if(NOT WATCOM AND NOT CMake_SOURCE_DIR)
|
||||
set(KWSYS_CXX_TESTS
|
||||
testHashSTL.cxx
|
||||
)
|
||||
endif()
|
||||
set(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS}
|
||||
testConfigure.cxx
|
||||
testSystemTools.cxx
|
||||
|
||||
@@ -13,9 +13,6 @@
|
||||
|
||||
/* Disable some warnings inside kwsys source files. */
|
||||
#if defined(KWSYS_NAMESPACE)
|
||||
# if defined(__BORLANDC__)
|
||||
# pragma warn - 8027 /* function not inlined. */
|
||||
# endif
|
||||
# if defined(__INTEL_COMPILER)
|
||||
# pragma warning(disable : 1572) /* floating-point equality test */
|
||||
# endif
|
||||
@@ -68,11 +65,6 @@
|
||||
# pragma warning(disable : 4710) /* function not inlined */
|
||||
# pragma warning(disable : 4786) /* identifier truncated in debug info */
|
||||
# endif
|
||||
# if defined(__BORLANDC__) && !defined(__cplusplus)
|
||||
/* Code has no effect; raised by winnt.h in C (not C++) when ignoring an
|
||||
unused parameter using "(param)" syntax (i.e. no cast to void). */
|
||||
# pragma warn - 8019
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* MSVC 6.0 in release mode will warn about code it produces with its
|
||||
|
||||
@@ -92,26 +92,12 @@ void Directory::Clear()
|
||||
# include <sys/stat.h>
|
||||
# include <sys/types.h>
|
||||
|
||||
// Wide function names can vary depending on compiler:
|
||||
# ifdef __BORLANDC__
|
||||
# define _wfindfirst_func __wfindfirst
|
||||
# define _wfindnext_func __wfindnext
|
||||
# else
|
||||
# define _wfindfirst_func _wfindfirst
|
||||
# define _wfindnext_func _wfindnext
|
||||
# endif
|
||||
|
||||
namespace KWSYS_NAMESPACE {
|
||||
|
||||
bool Directory::Load(const std::string& name, std::string* errorMessage)
|
||||
{
|
||||
this->Clear();
|
||||
# if (defined(_MSC_VER) && _MSC_VER < 1300) || defined(__BORLANDC__)
|
||||
// Older Visual C++ and Embarcadero compilers.
|
||||
long srchHandle;
|
||||
# else // Newer Visual C++
|
||||
intptr_t srchHandle;
|
||||
# endif
|
||||
char* buf;
|
||||
size_t n = name.size();
|
||||
if (name.back() == '/' || name.back() == '\\') {
|
||||
@@ -130,8 +116,8 @@ bool Directory::Load(const std::string& name, std::string* errorMessage)
|
||||
struct _wfinddata_t data; // data of current file
|
||||
|
||||
// Now put them into the file array
|
||||
srchHandle = _wfindfirst_func(
|
||||
(wchar_t*)Encoding::ToWindowsExtendedPath(buf).c_str(), &data);
|
||||
srchHandle =
|
||||
_wfindfirst((wchar_t*)Encoding::ToWindowsExtendedPath(buf).c_str(), &data);
|
||||
delete[] buf;
|
||||
|
||||
if (srchHandle == -1) {
|
||||
@@ -141,7 +127,7 @@ bool Directory::Load(const std::string& name, std::string* errorMessage)
|
||||
// Loop through names
|
||||
do {
|
||||
this->Internal->Files.push_back(Encoding::ToNarrow(data.name));
|
||||
} while (_wfindnext_func(srchHandle, &data) != -1);
|
||||
} while (_wfindnext(srchHandle, &data) != -1);
|
||||
this->Internal->Path = name;
|
||||
return _findclose(srchHandle) != -1;
|
||||
}
|
||||
@@ -149,12 +135,7 @@ bool Directory::Load(const std::string& name, std::string* errorMessage)
|
||||
unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name,
|
||||
std::string* errorMessage)
|
||||
{
|
||||
# if (defined(_MSC_VER) && _MSC_VER < 1300) || defined(__BORLANDC__)
|
||||
// Older Visual C++ and Embarcadero compilers.
|
||||
long srchHandle;
|
||||
# else // Newer Visual C++
|
||||
intptr_t srchHandle;
|
||||
# endif
|
||||
char* buf;
|
||||
size_t n = name.size();
|
||||
if (name.back() == '/') {
|
||||
@@ -167,8 +148,7 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name,
|
||||
struct _wfinddata_t data; // data of current file
|
||||
|
||||
// Now put them into the file array
|
||||
srchHandle =
|
||||
_wfindfirst_func((wchar_t*)Encoding::ToWide(buf).c_str(), &data);
|
||||
srchHandle = _wfindfirst((wchar_t*)Encoding::ToWide(buf).c_str(), &data);
|
||||
delete[] buf;
|
||||
|
||||
if (srchHandle == -1) {
|
||||
@@ -179,7 +159,7 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name,
|
||||
unsigned long count = 0;
|
||||
do {
|
||||
count++;
|
||||
} while (_wfindnext_func(srchHandle, &data) != -1);
|
||||
} while (_wfindnext(srchHandle, &data) != -1);
|
||||
_findclose(srchHandle);
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -246,17 +246,6 @@ DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
|
||||
// should have a tool to help get the symbol with the desired
|
||||
// calling convention. Currently we assume cdecl.
|
||||
//
|
||||
// Borland:
|
||||
// __cdecl = "_func" (default)
|
||||
// __fastcall = "@_func"
|
||||
// __stdcall = "func"
|
||||
//
|
||||
// Watcom:
|
||||
// __cdecl = "_func"
|
||||
// __fastcall = "@_func@X"
|
||||
// __stdcall = "_func@X"
|
||||
// __watcall = "func_" (default)
|
||||
//
|
||||
// MSVC:
|
||||
// __cdecl = "func" (default)
|
||||
// __fastcall = "@_func@X"
|
||||
@@ -265,20 +254,9 @@ DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
|
||||
// Note that the "@X" part of the name above is the total size (in
|
||||
// bytes) of the arguments on the stack.
|
||||
void* result;
|
||||
# if defined(__BORLANDC__) || defined(__WATCOMC__)
|
||||
// Need to prepend symbols with '_'
|
||||
std::string ssym = '_' + sym;
|
||||
const char* rsym = ssym.c_str();
|
||||
# else
|
||||
const char* rsym = sym.c_str();
|
||||
# endif
|
||||
result = (void*)GetProcAddress(lib, rsym);
|
||||
// Hack to cast pointer-to-data to pointer-to-function.
|
||||
# ifdef __WATCOMC__
|
||||
return *(DynamicLoader::SymbolPointer*)(&result);
|
||||
# else
|
||||
return *reinterpret_cast<DynamicLoader::SymbolPointer*>(&result);
|
||||
# endif
|
||||
}
|
||||
|
||||
# define DYNLOAD_ERROR_BUFFER_SIZE 1024
|
||||
|
||||
@@ -1,255 +0,0 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
|
||||
#include "kwsysPrivate.h"
|
||||
#include KWSYS_HEADER(Configure.hxx)
|
||||
|
||||
// Include the streams library.
|
||||
#include <iostream>
|
||||
#include KWSYS_HEADER(IOStream.hxx)
|
||||
|
||||
// Work-around CMake dependency scanning limitation. This must
|
||||
// duplicate the above list of headers.
|
||||
#if 0
|
||||
# include "Configure.hxx.in"
|
||||
# include "IOStream.hxx.in"
|
||||
#endif
|
||||
|
||||
// Implement the rest of this file only if it is needed.
|
||||
#if KWSYS_IOS_NEED_OPERATORS_LL
|
||||
|
||||
# include <stdio.h> // sscanf, sprintf
|
||||
# include <string.h> // memchr
|
||||
|
||||
# if defined(_MAX_INT_DIG)
|
||||
# define KWSYS_IOS_INT64_MAX_DIG _MAX_INT_DIG
|
||||
# else
|
||||
# define KWSYS_IOS_INT64_MAX_DIG 32
|
||||
# endif
|
||||
|
||||
namespace KWSYS_NAMESPACE {
|
||||
|
||||
// Scan an input stream for an integer value.
|
||||
static int IOStreamScanStream(std::istream& is, char* buffer)
|
||||
{
|
||||
// Prepare to write to buffer.
|
||||
char* out = buffer;
|
||||
char* end = buffer + KWSYS_IOS_INT64_MAX_DIG - 1;
|
||||
|
||||
// Look for leading sign.
|
||||
if (is.peek() == '+') {
|
||||
*out++ = '+';
|
||||
is.ignore();
|
||||
} else if (is.peek() == '-') {
|
||||
*out++ = '-';
|
||||
is.ignore();
|
||||
}
|
||||
|
||||
// Determine the base. If not specified in the stream, try to
|
||||
// detect it from the input. A leading 0x means hex, and a leading
|
||||
// 0 alone means octal.
|
||||
int base = 0;
|
||||
int flags = is.flags() & std::ios_base::basefield;
|
||||
if (flags == std::ios_base::oct) {
|
||||
base = 8;
|
||||
} else if (flags == std::ios_base::dec) {
|
||||
base = 10;
|
||||
} else if (flags == std::ios_base::hex) {
|
||||
base = 16;
|
||||
}
|
||||
bool foundDigit = false;
|
||||
bool foundNonZero = false;
|
||||
if (is.peek() == '0') {
|
||||
foundDigit = true;
|
||||
is.ignore();
|
||||
if ((is.peek() == 'x' || is.peek() == 'X') && (base == 0 || base == 16)) {
|
||||
base = 16;
|
||||
foundDigit = false;
|
||||
is.ignore();
|
||||
} else if (base == 0) {
|
||||
base = 8;
|
||||
}
|
||||
}
|
||||
|
||||
// Determine the range of digits allowed for this number.
|
||||
const char* digits = "0123456789abcdefABCDEF";
|
||||
int maxDigitIndex = 10;
|
||||
if (base == 8) {
|
||||
maxDigitIndex = 8;
|
||||
} else if (base == 16) {
|
||||
maxDigitIndex = 10 + 6 + 6;
|
||||
}
|
||||
|
||||
// Scan until an invalid digit is found.
|
||||
for (; is.peek() != EOF; is.ignore()) {
|
||||
if (memchr(digits, *out = (char)is.peek(), maxDigitIndex) != 0) {
|
||||
if ((foundNonZero || *out != '0') && out < end) {
|
||||
++out;
|
||||
foundNonZero = true;
|
||||
}
|
||||
foundDigit = true;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Correct the buffer contents for degenerate cases.
|
||||
if (foundDigit && !foundNonZero) {
|
||||
*out++ = '0';
|
||||
} else if (!foundDigit) {
|
||||
out = buffer;
|
||||
}
|
||||
|
||||
// Terminate the string in the buffer.
|
||||
*out = '\0';
|
||||
|
||||
return base;
|
||||
}
|
||||
|
||||
// Read an integer value from an input stream.
|
||||
template <class T>
|
||||
std::istream& IOStreamScanTemplate(std::istream& is, T& value, char type)
|
||||
{
|
||||
int state = std::ios_base::goodbit;
|
||||
|
||||
// Skip leading whitespace.
|
||||
std::istream::sentry okay(is);
|
||||
|
||||
if (okay) {
|
||||
try {
|
||||
// Copy the string to a buffer and construct the format string.
|
||||
char buffer[KWSYS_IOS_INT64_MAX_DIG];
|
||||
# if defined(_MSC_VER)
|
||||
char format[] = "%I64_";
|
||||
const int typeIndex = 4;
|
||||
# else
|
||||
char format[] = "%ll_";
|
||||
const int typeIndex = 3;
|
||||
# endif
|
||||
switch (IOStreamScanStream(is, buffer)) {
|
||||
case 8:
|
||||
format[typeIndex] = 'o';
|
||||
break;
|
||||
case 0: // Default to decimal if not told otherwise.
|
||||
case 10:
|
||||
format[typeIndex] = type;
|
||||
break;
|
||||
case 16:
|
||||
format[typeIndex] = 'x';
|
||||
break;
|
||||
};
|
||||
|
||||
// Use sscanf to parse the number from the buffer.
|
||||
T result;
|
||||
int success = (sscanf(buffer, format, &result) == 1) ? 1 : 0;
|
||||
|
||||
// Set flags for resulting state.
|
||||
if (is.peek() == EOF) {
|
||||
state |= std::ios_base::eofbit;
|
||||
}
|
||||
if (!success) {
|
||||
state |= std::ios_base::failbit;
|
||||
} else {
|
||||
value = result;
|
||||
}
|
||||
} catch (...) {
|
||||
state |= std::ios_base::badbit;
|
||||
}
|
||||
}
|
||||
|
||||
is.setstate(std::ios_base::iostate(state));
|
||||
return is;
|
||||
}
|
||||
|
||||
// Print an integer value to an output stream.
|
||||
template <class T>
|
||||
std::ostream& IOStreamPrintTemplate(std::ostream& os, T value, char type)
|
||||
{
|
||||
std::ostream::sentry okay(os);
|
||||
if (okay) {
|
||||
try {
|
||||
// Construct the format string.
|
||||
char format[8];
|
||||
char* f = format;
|
||||
*f++ = '%';
|
||||
if (os.flags() & std::ios_base::showpos) {
|
||||
*f++ = '+';
|
||||
}
|
||||
if (os.flags() & std::ios_base::showbase) {
|
||||
*f++ = '#';
|
||||
}
|
||||
# if defined(_MSC_VER)
|
||||
*f++ = 'I';
|
||||
*f++ = '6';
|
||||
*f++ = '4';
|
||||
# else
|
||||
*f++ = 'l';
|
||||
*f++ = 'l';
|
||||
# endif
|
||||
long bflags = os.flags() & std::ios_base::basefield;
|
||||
if (bflags == std::ios_base::oct) {
|
||||
*f++ = 'o';
|
||||
} else if (bflags != std::ios_base::hex) {
|
||||
*f++ = type;
|
||||
} else if (os.flags() & std::ios_base::uppercase) {
|
||||
*f++ = 'X';
|
||||
} else {
|
||||
*f++ = 'x';
|
||||
}
|
||||
*f = '\0';
|
||||
|
||||
// Use sprintf to print to a buffer and then write the
|
||||
// buffer to the stream.
|
||||
char buffer[2 * KWSYS_IOS_INT64_MAX_DIG];
|
||||
sprintf(buffer, format, value);
|
||||
os << buffer;
|
||||
} catch (...) {
|
||||
os.clear(os.rdstate() | std::ios_base::badbit);
|
||||
}
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
# if !KWSYS_IOS_HAS_ISTREAM_LONG_LONG
|
||||
// Implement input stream operator for IOStreamSLL.
|
||||
std::istream& IOStreamScan(std::istream& is, IOStreamSLL& value)
|
||||
{
|
||||
return IOStreamScanTemplate(is, value, 'd');
|
||||
}
|
||||
|
||||
// Implement input stream operator for IOStreamULL.
|
||||
std::istream& IOStreamScan(std::istream& is, IOStreamULL& value)
|
||||
{
|
||||
return IOStreamScanTemplate(is, value, 'u');
|
||||
}
|
||||
# endif
|
||||
|
||||
# if !KWSYS_IOS_HAS_OSTREAM_LONG_LONG
|
||||
// Implement output stream operator for IOStreamSLL.
|
||||
std::ostream& IOStreamPrint(std::ostream& os, IOStreamSLL value)
|
||||
{
|
||||
return IOStreamPrintTemplate(os, value, 'd');
|
||||
}
|
||||
|
||||
// Implement output stream operator for IOStreamULL.
|
||||
std::ostream& IOStreamPrint(std::ostream& os, IOStreamULL value)
|
||||
{
|
||||
return IOStreamPrintTemplate(os, value, 'u');
|
||||
}
|
||||
# endif
|
||||
|
||||
} // namespace KWSYS_NAMESPACE
|
||||
|
||||
#else
|
||||
|
||||
namespace KWSYS_NAMESPACE {
|
||||
|
||||
// Create one public symbol in this object file to avoid warnings from
|
||||
// archivers.
|
||||
void IOStreamSymbolToAvoidWarning();
|
||||
void IOStreamSymbolToAvoidWarning()
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace KWSYS_NAMESPACE
|
||||
|
||||
#endif // KWSYS_IOS_NEED_OPERATORS_LL
|
||||
@@ -1,126 +0,0 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
|
||||
#ifndef @KWSYS_NAMESPACE@_IOStream_hxx
|
||||
#define @KWSYS_NAMESPACE@_IOStream_hxx
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
/* Define these macros temporarily to keep the code readable. */
|
||||
#if !defined(KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
|
||||
# define kwsysEXPORT @KWSYS_NAMESPACE@_EXPORT
|
||||
#endif
|
||||
|
||||
/* Whether istream supports long long. */
|
||||
#define @KWSYS_NAMESPACE@_IOS_HAS_ISTREAM_LONG_LONG \
|
||||
@KWSYS_IOS_HAS_ISTREAM_LONG_LONG@
|
||||
|
||||
/* Whether ostream supports long long. */
|
||||
#define @KWSYS_NAMESPACE@_IOS_HAS_OSTREAM_LONG_LONG \
|
||||
@KWSYS_IOS_HAS_OSTREAM_LONG_LONG@
|
||||
|
||||
/* Determine whether we need to define the streaming operators for
|
||||
long long or __int64. */
|
||||
#if @KWSYS_USE_LONG_LONG@
|
||||
# if !@KWSYS_NAMESPACE@_IOS_HAS_ISTREAM_LONG_LONG || \
|
||||
!@KWSYS_NAMESPACE@_IOS_HAS_OSTREAM_LONG_LONG
|
||||
# define @KWSYS_NAMESPACE@_IOS_NEED_OPERATORS_LL 1
|
||||
namespace @KWSYS_NAMESPACE@ {
|
||||
typedef long long IOStreamSLL;
|
||||
typedef unsigned long long IOStreamULL;
|
||||
}
|
||||
# endif
|
||||
#elif defined(_MSC_VER) && _MSC_VER < 1300
|
||||
# define @KWSYS_NAMESPACE@_IOS_NEED_OPERATORS_LL 1
|
||||
namespace @KWSYS_NAMESPACE@ {
|
||||
typedef __int64 IOStreamSLL;
|
||||
typedef unsigned __int64 IOStreamULL;
|
||||
}
|
||||
#endif
|
||||
#if !defined(@KWSYS_NAMESPACE@_IOS_NEED_OPERATORS_LL)
|
||||
# define @KWSYS_NAMESPACE@_IOS_NEED_OPERATORS_LL 0
|
||||
#endif
|
||||
|
||||
#if @KWSYS_NAMESPACE@_IOS_NEED_OPERATORS_LL
|
||||
# if !@KWSYS_NAMESPACE@_IOS_HAS_ISTREAM_LONG_LONG
|
||||
|
||||
/* Input stream operator implementation functions. */
|
||||
namespace @KWSYS_NAMESPACE@ {
|
||||
kwsysEXPORT std::istream& IOStreamScan(std::istream&, IOStreamSLL&);
|
||||
kwsysEXPORT std::istream& IOStreamScan(std::istream&, IOStreamULL&);
|
||||
}
|
||||
|
||||
/* Provide input stream operator for long long. */
|
||||
# if !defined(@KWSYS_NAMESPACE@_IOS_NO_ISTREAM_LONG_LONG) && \
|
||||
!defined(KWSYS_IOS_ISTREAM_LONG_LONG_DEFINED)
|
||||
# define KWSYS_IOS_ISTREAM_LONG_LONG_DEFINED
|
||||
# define @KWSYS_NAMESPACE@_IOS_ISTREAM_LONG_LONG_DEFINED
|
||||
inline std::istream& operator>>(std::istream& is,
|
||||
@KWSYS_NAMESPACE@::IOStreamSLL& value)
|
||||
{
|
||||
return @KWSYS_NAMESPACE@::IOStreamScan(is, value);
|
||||
}
|
||||
# endif
|
||||
|
||||
/* Provide input stream operator for unsigned long long. */
|
||||
# if !defined(@KWSYS_NAMESPACE@_IOS_NO_ISTREAM_UNSIGNED_LONG_LONG) && \
|
||||
!defined(KWSYS_IOS_ISTREAM_UNSIGNED_LONG_LONG_DEFINED)
|
||||
# define KWSYS_IOS_ISTREAM_UNSIGNED_LONG_LONG_DEFINED
|
||||
# define @KWSYS_NAMESPACE@_IOS_ISTREAM_UNSIGNED_LONG_LONG_DEFINED
|
||||
inline std::istream& operator>>(std::istream& is,
|
||||
@KWSYS_NAMESPACE@::IOStreamULL& value)
|
||||
{
|
||||
return @KWSYS_NAMESPACE@::IOStreamScan(is, value);
|
||||
}
|
||||
# endif
|
||||
# endif /* !@KWSYS_NAMESPACE@_IOS_HAS_ISTREAM_LONG_LONG */
|
||||
|
||||
# if !@KWSYS_NAMESPACE@_IOS_HAS_OSTREAM_LONG_LONG
|
||||
|
||||
/* Output stream operator implementation functions. */
|
||||
namespace @KWSYS_NAMESPACE@ {
|
||||
kwsysEXPORT std::ostream& IOStreamPrint(std::ostream&, IOStreamSLL);
|
||||
kwsysEXPORT std::ostream& IOStreamPrint(std::ostream&, IOStreamULL);
|
||||
}
|
||||
|
||||
/* Provide output stream operator for long long. */
|
||||
# if !defined(@KWSYS_NAMESPACE@_IOS_NO_OSTREAM_LONG_LONG) && \
|
||||
!defined(KWSYS_IOS_OSTREAM_LONG_LONG_DEFINED)
|
||||
# define KWSYS_IOS_OSTREAM_LONG_LONG_DEFINED
|
||||
# define @KWSYS_NAMESPACE@_IOS_OSTREAM_LONG_LONG_DEFINED
|
||||
inline std::ostream& operator<<(std::ostream& os,
|
||||
@KWSYS_NAMESPACE@::IOStreamSLL value)
|
||||
{
|
||||
return @KWSYS_NAMESPACE@::IOStreamPrint(os, value);
|
||||
}
|
||||
# endif
|
||||
|
||||
/* Provide output stream operator for unsigned long long. */
|
||||
# if !defined(@KWSYS_NAMESPACE@_IOS_NO_OSTREAM_UNSIGNED_LONG_LONG) && \
|
||||
!defined(KWSYS_IOS_OSTREAM_UNSIGNED_LONG_LONG_DEFINED)
|
||||
# define KWSYS_IOS_OSTREAM_UNSIGNED_LONG_LONG_DEFINED
|
||||
# define @KWSYS_NAMESPACE@_IOS_OSTREAM_UNSIGNED_LONG_LONG_DEFINED
|
||||
inline std::ostream& operator<<(std::ostream& os,
|
||||
@KWSYS_NAMESPACE@::IOStreamULL value)
|
||||
{
|
||||
return @KWSYS_NAMESPACE@::IOStreamPrint(os, value);
|
||||
}
|
||||
# endif
|
||||
# endif /* !@KWSYS_NAMESPACE@_IOS_HAS_OSTREAM_LONG_LONG */
|
||||
#endif /* @KWSYS_NAMESPACE@_IOS_NEED_OPERATORS_LL */
|
||||
|
||||
/* Undefine temporary macros. */
|
||||
#if !defined(KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
|
||||
# undef kwsysEXPORT
|
||||
#endif
|
||||
|
||||
/* If building a C++ file in kwsys itself, give the source file
|
||||
access to the macros without a configured namespace. */
|
||||
#if defined(KWSYS_NAMESPACE)
|
||||
# define KWSYS_IOS_HAS_ISTREAM_LONG_LONG \
|
||||
@KWSYS_NAMESPACE@_IOS_HAS_ISTREAM_LONG_LONG
|
||||
# define KWSYS_IOS_HAS_OSTREAM_LONG_LONG \
|
||||
@KWSYS_NAMESPACE@_IOS_HAS_OSTREAM_LONG_LONG
|
||||
# define KWSYS_IOS_NEED_OPERATORS_LL @KWSYS_NAMESPACE@_IOS_NEED_OPERATORS_LL
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -31,9 +31,6 @@ a UNIX-style select system call.
|
||||
#include <io.h> /* _unlink */
|
||||
#include <stdio.h> /* sprintf */
|
||||
#include <string.h> /* strlen, strdup */
|
||||
#ifdef __WATCOMC__
|
||||
# define _unlink unlink
|
||||
#endif
|
||||
|
||||
#ifndef _MAX_FNAME
|
||||
# define _MAX_FNAME 4096
|
||||
@@ -48,11 +45,6 @@ a UNIX-style select system call.
|
||||
# pragma warning(disable : 4706)
|
||||
#endif
|
||||
|
||||
#if defined(__BORLANDC__)
|
||||
# pragma warn - 8004 /* assigned a value that is never used */
|
||||
# pragma warn - 8060 /* Assignment inside if() condition. */
|
||||
#endif
|
||||
|
||||
/* There are pipes for the process pipeline's stdout and stderr. */
|
||||
#define KWSYSPE_PIPE_COUNT 2
|
||||
#define KWSYSPE_PIPE_STDOUT 0
|
||||
|
||||
@@ -26,12 +26,6 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
/* Disable useless Borland warnings. KWSys tries not to force things
|
||||
on its includers, but there is no choice here. */
|
||||
#if defined(__BORLANDC__)
|
||||
# pragma warn - 8027 /* function not inlined. */
|
||||
#endif
|
||||
|
||||
namespace @KWSYS_NAMESPACE@ {
|
||||
|
||||
// Forward declaration
|
||||
|
||||
@@ -66,12 +66,6 @@
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# if defined(__BORLANDC__) && !defined(__cplusplus)
|
||||
/* Code has no effect; raised by winnt.h in C (not C++) when ignoring an
|
||||
unused parameter using "(param)" syntax (i.e. no cast to void). */
|
||||
# pragma warn - 8019
|
||||
# endif
|
||||
|
||||
/* Full path to the directory in which this executable is built. Do
|
||||
not include a trailing slash. */
|
||||
# if !defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_DIR_BUILD)
|
||||
|
||||
@@ -52,14 +52,6 @@ public:
|
||||
}
|
||||
}; // End Class: String
|
||||
|
||||
#if defined(__WATCOMC__)
|
||||
inline bool operator<(String const& l, String const& r)
|
||||
{
|
||||
return (static_cast<std::string const&>(l) <
|
||||
static_cast<std::string const&>(r));
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace @KWSYS_NAMESPACE@
|
||||
|
||||
#endif
|
||||
|
||||
@@ -169,34 +169,6 @@ typedef struct rlimit ResourceLimitType;
|
||||
#include <cstring>
|
||||
#include <memory.h>
|
||||
|
||||
#if defined(KWSYS_USE_LONG_LONG)
|
||||
# if defined(KWSYS_IOS_HAS_OSTREAM_LONG_LONG)
|
||||
# define iostreamLongLong(x) (x)
|
||||
# else
|
||||
# define iostreamLongLong(x) ((long)(x))
|
||||
# endif
|
||||
#elif defined(KWSYS_USE___INT64)
|
||||
# if defined(KWSYS_IOS_HAS_OSTREAM___INT64)
|
||||
# define iostreamLongLong(x) (x)
|
||||
# else
|
||||
# define iostreamLongLong(x) ((long)(x))
|
||||
# endif
|
||||
#else
|
||||
# error "No Long Long"
|
||||
#endif
|
||||
|
||||
#if defined(KWSYS_CXX_HAS_ATOLL)
|
||||
# define atoLongLong atoll
|
||||
#else
|
||||
# if defined(KWSYS_CXX_HAS__ATOI64)
|
||||
# define atoLongLong _atoi64
|
||||
# elif defined(KWSYS_CXX_HAS_ATOL)
|
||||
# define atoLongLong atol
|
||||
# else
|
||||
# define atoLongLong atoi
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1300) && !defined(_WIN64) && \
|
||||
!defined(__clang__)
|
||||
# define USE_ASM_INSTRUCTIONS 1
|
||||
@@ -212,8 +184,7 @@ typedef struct rlimit ResourceLimitType;
|
||||
# define USE_CPUID_INTRINSICS 0
|
||||
#endif
|
||||
|
||||
#if USE_ASM_INSTRUCTIONS || USE_CPUID_INTRINSICS || \
|
||||
defined(KWSYS_CXX_HAS_BORLAND_ASM_CPUID)
|
||||
#if USE_ASM_INSTRUCTIONS || USE_CPUID_INTRINSICS
|
||||
# define USE_CPUID 1
|
||||
#else
|
||||
# define USE_CPUID 0
|
||||
@@ -273,21 +244,6 @@ static bool call_cpuid(int select, int result[4])
|
||||
}
|
||||
|
||||
memcpy(result, tmp, sizeof(tmp));
|
||||
# elif defined(KWSYS_CXX_HAS_BORLAND_ASM_CPUID)
|
||||
unsigned int a, b, c, d;
|
||||
__asm {
|
||||
mov EAX, select;
|
||||
cpuid
|
||||
mov a, EAX;
|
||||
mov b, EBX;
|
||||
mov c, ECX;
|
||||
mov d, EDX;
|
||||
}
|
||||
|
||||
result[0] = a;
|
||||
result[1] = b;
|
||||
result[2] = c;
|
||||
result[3] = d;
|
||||
# endif
|
||||
|
||||
// The cpuid instruction succeeded.
|
||||
@@ -313,7 +269,6 @@ using DELAY_FUNC = void (*)(unsigned int);
|
||||
class SystemInformationImplementation
|
||||
{
|
||||
public:
|
||||
using LongLong = SystemInformation::LongLong;
|
||||
SystemInformationImplementation();
|
||||
~SystemInformationImplementation() = default;
|
||||
|
||||
@@ -353,16 +308,16 @@ public:
|
||||
size_t GetTotalPhysicalMemory() const;
|
||||
size_t GetAvailablePhysicalMemory() const;
|
||||
|
||||
LongLong GetProcessId();
|
||||
long long GetProcessId();
|
||||
|
||||
// Retrieve memory information in KiB.
|
||||
LongLong GetHostMemoryTotal();
|
||||
LongLong GetHostMemoryAvailable(const char* hostLimitEnvVarName);
|
||||
LongLong GetHostMemoryUsed();
|
||||
long long GetHostMemoryTotal();
|
||||
long long GetHostMemoryAvailable(const char* hostLimitEnvVarName);
|
||||
long long GetHostMemoryUsed();
|
||||
|
||||
LongLong GetProcMemoryAvailable(const char* hostLimitEnvVarName,
|
||||
const char* procLimitEnvVarName);
|
||||
LongLong GetProcMemoryUsed();
|
||||
long long GetProcMemoryAvailable(const char* hostLimitEnvVarName,
|
||||
const char* procLimitEnvVarName);
|
||||
long long GetProcMemoryUsed();
|
||||
|
||||
double GetLoadAverage();
|
||||
|
||||
@@ -521,7 +476,8 @@ protected:
|
||||
void CPUCountWindows(); // For windows
|
||||
unsigned char GetAPICId(); // For windows
|
||||
bool IsSMTSupported() const;
|
||||
static LongLong GetCyclesDifference(DELAY_FUNC, unsigned int); // For windows
|
||||
static long long GetCyclesDifference(DELAY_FUNC,
|
||||
unsigned int); // For windows
|
||||
|
||||
// For Linux and Cygwin, /proc/cpuinfo formats are slightly different
|
||||
bool RetreiveInformationFromCpuInfoFile();
|
||||
@@ -812,42 +768,41 @@ std::string SystemInformation::GetMemoryDescription(
|
||||
const char* hostLimitEnvVarName, const char* procLimitEnvVarName)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "Host Total: " << iostreamLongLong(this->GetHostMemoryTotal())
|
||||
oss << "Host Total: " << this->GetHostMemoryTotal()
|
||||
<< " KiB, Host Available: "
|
||||
<< iostreamLongLong(this->GetHostMemoryAvailable(hostLimitEnvVarName))
|
||||
<< this->GetHostMemoryAvailable(hostLimitEnvVarName)
|
||||
<< " KiB, Process Available: "
|
||||
<< iostreamLongLong(this->GetProcMemoryAvailable(hostLimitEnvVarName,
|
||||
procLimitEnvVarName))
|
||||
<< this->GetProcMemoryAvailable(hostLimitEnvVarName, procLimitEnvVarName)
|
||||
<< " KiB";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
// host memory info in units of KiB.
|
||||
SystemInformation::LongLong SystemInformation::GetHostMemoryTotal()
|
||||
long long SystemInformation::GetHostMemoryTotal()
|
||||
{
|
||||
return this->Implementation->GetHostMemoryTotal();
|
||||
}
|
||||
|
||||
SystemInformation::LongLong SystemInformation::GetHostMemoryAvailable(
|
||||
long long SystemInformation::GetHostMemoryAvailable(
|
||||
const char* hostLimitEnvVarName)
|
||||
{
|
||||
return this->Implementation->GetHostMemoryAvailable(hostLimitEnvVarName);
|
||||
}
|
||||
|
||||
SystemInformation::LongLong SystemInformation::GetHostMemoryUsed()
|
||||
long long SystemInformation::GetHostMemoryUsed()
|
||||
{
|
||||
return this->Implementation->GetHostMemoryUsed();
|
||||
}
|
||||
|
||||
// process memory info in units of KiB.
|
||||
SystemInformation::LongLong SystemInformation::GetProcMemoryAvailable(
|
||||
long long SystemInformation::GetProcMemoryAvailable(
|
||||
const char* hostLimitEnvVarName, const char* procLimitEnvVarName)
|
||||
{
|
||||
return this->Implementation->GetProcMemoryAvailable(hostLimitEnvVarName,
|
||||
procLimitEnvVarName);
|
||||
}
|
||||
|
||||
SystemInformation::LongLong SystemInformation::GetProcMemoryUsed()
|
||||
long long SystemInformation::GetProcMemoryUsed()
|
||||
{
|
||||
return this->Implementation->GetProcMemoryUsed();
|
||||
}
|
||||
@@ -857,7 +812,7 @@ double SystemInformation::GetLoadAverage()
|
||||
return this->Implementation->GetLoadAverage();
|
||||
}
|
||||
|
||||
SystemInformation::LongLong SystemInformation::GetProcessId()
|
||||
long long SystemInformation::GetProcessId()
|
||||
{
|
||||
return this->Implementation->GetProcessId();
|
||||
}
|
||||
@@ -3628,8 +3583,7 @@ bool SystemInformationImplementation::QueryProcessor()
|
||||
/**
|
||||
Get total system RAM in units of KiB.
|
||||
*/
|
||||
SystemInformation::LongLong
|
||||
SystemInformationImplementation::GetHostMemoryTotal()
|
||||
long long SystemInformationImplementation::GetHostMemoryTotal()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
# if defined(_MSC_VER) && _MSC_VER < 1300
|
||||
@@ -3644,7 +3598,7 @@ SystemInformationImplementation::GetHostMemoryTotal()
|
||||
return statex.ullTotalPhys / 1024;
|
||||
# endif
|
||||
#elif defined(__linux)
|
||||
SystemInformation::LongLong memTotal = 0;
|
||||
long long memTotal = 0;
|
||||
int ierr = GetFieldFromFile("/proc/meminfo", "MemTotal:", memTotal);
|
||||
if (ierr) {
|
||||
return -1;
|
||||
@@ -3667,11 +3621,10 @@ SystemInformationImplementation::GetHostMemoryTotal()
|
||||
Get total system RAM in units of KiB. This may differ from the
|
||||
host total if a host-wide resource limit is applied.
|
||||
*/
|
||||
SystemInformation::LongLong
|
||||
SystemInformationImplementation::GetHostMemoryAvailable(
|
||||
long long SystemInformationImplementation::GetHostMemoryAvailable(
|
||||
const char* hostLimitEnvVarName)
|
||||
{
|
||||
SystemInformation::LongLong memTotal = this->GetHostMemoryTotal();
|
||||
long long memTotal = this->GetHostMemoryTotal();
|
||||
|
||||
// the following mechanism is provided for systems that
|
||||
// apply resource limits across groups of processes.
|
||||
@@ -3682,8 +3635,7 @@ SystemInformationImplementation::GetHostMemoryAvailable(
|
||||
if (hostLimitEnvVarName) {
|
||||
const char* hostLimitEnvVarValue = getenv(hostLimitEnvVarName);
|
||||
if (hostLimitEnvVarValue) {
|
||||
SystemInformation::LongLong hostLimit =
|
||||
atoLongLong(hostLimitEnvVarValue);
|
||||
long long hostLimit = std::atoll(hostLimitEnvVarValue);
|
||||
if (hostLimit > 0) {
|
||||
memTotal = min(hostLimit, memTotal);
|
||||
}
|
||||
@@ -3697,20 +3649,17 @@ SystemInformationImplementation::GetHostMemoryAvailable(
|
||||
Get total system RAM in units of KiB. This may differ from the
|
||||
host total if a per-process resource limit is applied.
|
||||
*/
|
||||
SystemInformation::LongLong
|
||||
SystemInformationImplementation::GetProcMemoryAvailable(
|
||||
long long SystemInformationImplementation::GetProcMemoryAvailable(
|
||||
const char* hostLimitEnvVarName, const char* procLimitEnvVarName)
|
||||
{
|
||||
SystemInformation::LongLong memAvail =
|
||||
this->GetHostMemoryAvailable(hostLimitEnvVarName);
|
||||
long long memAvail = this->GetHostMemoryAvailable(hostLimitEnvVarName);
|
||||
|
||||
// the following mechanism is provide for systems where rlimits
|
||||
// are not employed. Units are in KiB.
|
||||
if (procLimitEnvVarName) {
|
||||
const char* procLimitEnvVarValue = getenv(procLimitEnvVarName);
|
||||
if (procLimitEnvVarValue) {
|
||||
SystemInformation::LongLong procLimit =
|
||||
atoLongLong(procLimitEnvVarValue);
|
||||
long long procLimit = std::atoll(procLimitEnvVarValue);
|
||||
if (procLimit > 0) {
|
||||
memAvail = min(procLimit, memAvail);
|
||||
}
|
||||
@@ -3722,28 +3671,24 @@ SystemInformationImplementation::GetProcMemoryAvailable(
|
||||
ResourceLimitType rlim;
|
||||
ierr = GetResourceLimit(RLIMIT_DATA, &rlim);
|
||||
if ((ierr == 0) && (rlim.rlim_cur != RLIM_INFINITY)) {
|
||||
memAvail =
|
||||
min((SystemInformation::LongLong)rlim.rlim_cur / 1024, memAvail);
|
||||
memAvail = min((long long)rlim.rlim_cur / 1024, memAvail);
|
||||
}
|
||||
|
||||
ierr = GetResourceLimit(RLIMIT_AS, &rlim);
|
||||
if ((ierr == 0) && (rlim.rlim_cur != RLIM_INFINITY)) {
|
||||
memAvail =
|
||||
min((SystemInformation::LongLong)rlim.rlim_cur / 1024, memAvail);
|
||||
memAvail = min((long long)rlim.rlim_cur / 1024, memAvail);
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
struct rlimit rlim;
|
||||
int ierr;
|
||||
ierr = getrlimit(RLIMIT_DATA, &rlim);
|
||||
if ((ierr == 0) && (rlim.rlim_cur != RLIM_INFINITY)) {
|
||||
memAvail =
|
||||
min((SystemInformation::LongLong)rlim.rlim_cur / 1024, memAvail);
|
||||
memAvail = min((long long)rlim.rlim_cur / 1024, memAvail);
|
||||
}
|
||||
|
||||
ierr = getrlimit(RLIMIT_RSS, &rlim);
|
||||
if ((ierr == 0) && (rlim.rlim_cur != RLIM_INFINITY)) {
|
||||
memAvail =
|
||||
min((SystemInformation::LongLong)rlim.rlim_cur / 1024, memAvail);
|
||||
memAvail = min((long long)rlim.rlim_cur / 1024, memAvail);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -3753,8 +3698,7 @@ SystemInformationImplementation::GetProcMemoryAvailable(
|
||||
/**
|
||||
Get RAM used by all processes in the host, in units of KiB.
|
||||
*/
|
||||
SystemInformation::LongLong
|
||||
SystemInformationImplementation::GetHostMemoryUsed()
|
||||
long long SystemInformationImplementation::GetHostMemoryUsed()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
# if defined(_MSC_VER) && _MSC_VER < 1300
|
||||
@@ -3771,39 +3715,38 @@ SystemInformationImplementation::GetHostMemoryUsed()
|
||||
#elif defined(__linux)
|
||||
// First try to use MemAvailable, but it only works on newer kernels
|
||||
const char* names2[3] = { "MemTotal:", "MemAvailable:", nullptr };
|
||||
SystemInformation::LongLong values2[2] = { SystemInformation::LongLong(0) };
|
||||
long long values2[2] = { 0 };
|
||||
int ierr = GetFieldsFromFile("/proc/meminfo", names2, values2);
|
||||
if (ierr) {
|
||||
const char* names4[5] = { "MemTotal:", "MemFree:", "Buffers:", "Cached:",
|
||||
nullptr };
|
||||
SystemInformation::LongLong values4[4] = { SystemInformation::LongLong(
|
||||
0) };
|
||||
long long values4[4] = { 0 };
|
||||
ierr = GetFieldsFromFile("/proc/meminfo", names4, values4);
|
||||
if (ierr) {
|
||||
return ierr;
|
||||
}
|
||||
SystemInformation::LongLong& memTotal = values4[0];
|
||||
SystemInformation::LongLong& memFree = values4[1];
|
||||
SystemInformation::LongLong& memBuffers = values4[2];
|
||||
SystemInformation::LongLong& memCached = values4[3];
|
||||
long long& memTotal = values4[0];
|
||||
long long& memFree = values4[1];
|
||||
long long& memBuffers = values4[2];
|
||||
long long& memCached = values4[3];
|
||||
return memTotal - memFree - memBuffers - memCached;
|
||||
}
|
||||
SystemInformation::LongLong& memTotal = values2[0];
|
||||
SystemInformation::LongLong& memAvail = values2[1];
|
||||
long long& memTotal = values2[0];
|
||||
long long& memAvail = values2[1];
|
||||
return memTotal - memAvail;
|
||||
#elif defined(__APPLE__)
|
||||
SystemInformation::LongLong psz = getpagesize();
|
||||
long long psz = getpagesize();
|
||||
if (psz < 1) {
|
||||
return -1;
|
||||
}
|
||||
const char* names[3] = { "Pages wired down:", "Pages active:", nullptr };
|
||||
SystemInformation::LongLong values[2] = { SystemInformation::LongLong(0) };
|
||||
long long values[2] = { 0 };
|
||||
int ierr = GetFieldsFromCommand("vm_stat", names, values);
|
||||
if (ierr) {
|
||||
return -1;
|
||||
}
|
||||
SystemInformation::LongLong& vmWired = values[0];
|
||||
SystemInformation::LongLong& vmActive = values[1];
|
||||
long long& vmWired = values[0];
|
||||
long long& vmActive = values[1];
|
||||
return ((vmActive + vmWired) * psz) / 1024;
|
||||
#else
|
||||
return 0;
|
||||
@@ -3814,8 +3757,7 @@ SystemInformationImplementation::GetHostMemoryUsed()
|
||||
Get system RAM used by the process associated with the given
|
||||
process id in units of KiB.
|
||||
*/
|
||||
SystemInformation::LongLong
|
||||
SystemInformationImplementation::GetProcMemoryUsed()
|
||||
long long SystemInformationImplementation::GetProcMemoryUsed()
|
||||
{
|
||||
#if defined(_WIN32) && defined(KWSYS_SYS_HAS_PSAPI)
|
||||
long pid = GetCurrentProcessId();
|
||||
@@ -3832,14 +3774,14 @@ SystemInformationImplementation::GetProcMemoryUsed()
|
||||
}
|
||||
return pmc.WorkingSetSize / 1024;
|
||||
#elif defined(__linux)
|
||||
SystemInformation::LongLong memUsed = 0;
|
||||
long long memUsed = 0;
|
||||
int ierr = GetFieldFromFile("/proc/self/status", "VmRSS:", memUsed);
|
||||
if (ierr) {
|
||||
return -1;
|
||||
}
|
||||
return memUsed;
|
||||
#elif defined(__APPLE__)
|
||||
SystemInformation::LongLong memUsed = 0;
|
||||
long long memUsed = 0;
|
||||
pid_t pid = getpid();
|
||||
std::ostringstream oss;
|
||||
oss << "ps -o rss= -p " << pid;
|
||||
@@ -3903,7 +3845,7 @@ double SystemInformationImplementation::GetLoadAverage()
|
||||
/**
|
||||
Get the process id of the running process.
|
||||
*/
|
||||
SystemInformation::LongLong SystemInformationImplementation::GetProcessId()
|
||||
long long SystemInformationImplementation::GetProcessId()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
return GetCurrentProcessId();
|
||||
@@ -4316,9 +4258,8 @@ size_t SystemInformationImplementation::GetAvailablePhysicalMemory() const
|
||||
}
|
||||
|
||||
/** Get Cycle differences */
|
||||
SystemInformation::LongLong
|
||||
SystemInformationImplementation::GetCyclesDifference(DELAY_FUNC DelayFunction,
|
||||
unsigned int uiParameter)
|
||||
long long SystemInformationImplementation::GetCyclesDifference(
|
||||
DELAY_FUNC DelayFunction, unsigned int uiParameter)
|
||||
{
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
|
||||
unsigned __int64 stamp1, stamp2;
|
||||
@@ -4449,12 +4390,12 @@ void SystemInformationImplementation::CPUCountWindows()
|
||||
DWORD Length = 0;
|
||||
DWORD rc = pGetLogicalProcessorInformation(nullptr, &Length);
|
||||
assert(FALSE == rc);
|
||||
(void)rc; // Silence unused variable warning in Borland C++ 5.81
|
||||
(void)rc; // Silence unused variable warning
|
||||
assert(GetLastError() == ERROR_INSUFFICIENT_BUFFER);
|
||||
ProcInfo.resize(Length / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION));
|
||||
rc = pGetLogicalProcessorInformation(&ProcInfo[0], &Length);
|
||||
assert(rc != FALSE);
|
||||
(void)rc; // Silence unused variable warning in Borland C++ 5.81
|
||||
(void)rc; // Silence unused variable warning
|
||||
}
|
||||
|
||||
typedef std::vector<SYSTEM_LOGICAL_PROCESSOR_INFORMATION>::iterator
|
||||
|
||||
@@ -15,13 +15,6 @@ class SystemInformationImplementation;
|
||||
|
||||
class @KWSYS_NAMESPACE@_EXPORT SystemInformation
|
||||
{
|
||||
#if @KWSYS_USE_LONG_LONG@
|
||||
typedef long long LongLong;
|
||||
#elif @KWSYS_USE___INT64@
|
||||
typedef __int64 LongLong;
|
||||
#else
|
||||
# error "No Long Long"
|
||||
#endif
|
||||
friend class SystemInformationImplementation;
|
||||
SystemInformationImplementation* Implementation;
|
||||
|
||||
@@ -104,7 +97,7 @@ public:
|
||||
bool DoesCPUSupportCPUID();
|
||||
|
||||
// Retrieve id of the current running process
|
||||
LongLong GetProcessId();
|
||||
long long GetProcessId();
|
||||
|
||||
// Retrieve memory information in MiB.
|
||||
size_t GetTotalVirtualMemory();
|
||||
@@ -120,7 +113,7 @@ public:
|
||||
|
||||
// Retrieve amount of physical memory installed on the system in KiB
|
||||
// units.
|
||||
LongLong GetHostMemoryTotal();
|
||||
long long GetHostMemoryTotal();
|
||||
|
||||
// Get total system RAM in units of KiB available colectivley to all
|
||||
// processes in a process group. An example of a process group
|
||||
@@ -128,7 +121,7 @@ public:
|
||||
// parallel. The amount of memory reported may differ from the host
|
||||
// total if a host wide resource limit is applied. Such reource limits
|
||||
// are reported to us via an application specified environment variable.
|
||||
LongLong GetHostMemoryAvailable(const char* hostLimitEnvVarName = nullptr);
|
||||
long long GetHostMemoryAvailable(const char* hostLimitEnvVarName = nullptr);
|
||||
|
||||
// Get total system RAM in units of KiB available to this process.
|
||||
// This may differ from the host available if a per-process resource
|
||||
@@ -136,14 +129,14 @@ public:
|
||||
// system via rlimit API. Resource limits that are not imposed via
|
||||
// rlimit API may be reported to us via an application specified
|
||||
// environment variable.
|
||||
LongLong GetProcMemoryAvailable(const char* hostLimitEnvVarName = nullptr,
|
||||
const char* procLimitEnvVarName = nullptr);
|
||||
long long GetProcMemoryAvailable(const char* hostLimitEnvVarName = nullptr,
|
||||
const char* procLimitEnvVarName = nullptr);
|
||||
|
||||
// Get the system RAM used by all processes on the host, in units of KiB.
|
||||
LongLong GetHostMemoryUsed();
|
||||
long long GetHostMemoryUsed();
|
||||
|
||||
// Get system RAM used by this process id in units of KiB.
|
||||
LongLong GetProcMemoryUsed();
|
||||
long long GetProcMemoryUsed();
|
||||
|
||||
// Return the load average of the machine or -0.0 if it cannot
|
||||
// be determined.
|
||||
|
||||
@@ -6,9 +6,7 @@
|
||||
# define _XOPEN_SOURCE_EXTENDED
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) && \
|
||||
(defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || \
|
||||
defined(__MINGW32__))
|
||||
#if defined(_WIN32) && (defined(_MSC_VER) || defined(__MINGW32__))
|
||||
# define KWSYS_WINDOWS_DIRS
|
||||
#else
|
||||
# if defined(__SUNPRO_CC)
|
||||
@@ -65,7 +63,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# define umask _umask // Note this is still umask on Borland
|
||||
# define umask _umask
|
||||
#endif
|
||||
|
||||
// support for realpath call
|
||||
@@ -154,9 +152,7 @@ public:
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) && \
|
||||
(defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || \
|
||||
defined(__MINGW32__))
|
||||
#if defined(_WIN32) && (defined(_MSC_VER) || defined(__MINGW32__))
|
||||
# include <direct.h>
|
||||
# include <io.h>
|
||||
# define _unlink unlink
|
||||
@@ -170,13 +166,6 @@ public:
|
||||
#else
|
||||
# define KWSYS_SYSTEMTOOLS_MAXPATH 16384
|
||||
#endif
|
||||
#if defined(__WATCOMC__)
|
||||
# include <direct.h>
|
||||
# define _mkdir mkdir
|
||||
# define _rmdir rmdir
|
||||
# define _getcwd getcwd
|
||||
# define _chdir chdir
|
||||
#endif
|
||||
|
||||
#if defined(__BEOS__) && !defined(__ZETA__)
|
||||
# include <be/kernel/OS.h>
|
||||
@@ -259,11 +248,7 @@ inline const char* Getcwd(char* buf, unsigned int len)
|
||||
}
|
||||
inline int Chdir(const std::string& dir)
|
||||
{
|
||||
# if defined(__BORLANDC__)
|
||||
return chdir(dir.c_str());
|
||||
# else
|
||||
return _wchdir(KWSYS_NAMESPACE::Encoding::ToWide(dir).c_str());
|
||||
# endif
|
||||
}
|
||||
inline void Realpath(const std::string& path, std::string& resolved_path,
|
||||
std::string* errorMessage = 0)
|
||||
@@ -937,15 +922,9 @@ bool SystemTools::MakeDirectory(const std::string& path, const mode_t* mode)
|
||||
}
|
||||
topdir = dir;
|
||||
if (Mkdir(topdir, mode) != 0) {
|
||||
// There is a bug in the Borland Run time library which makes MKDIR
|
||||
// return EACCES when it should return EEXISTS
|
||||
// if it is some other error besides directory exists
|
||||
// then return false
|
||||
if ((errno != EEXIST)
|
||||
#ifdef __BORLANDC__
|
||||
&& (errno != EACCES)
|
||||
#endif
|
||||
) {
|
||||
if (errno != EEXIST) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1448,11 +1427,7 @@ int SystemTools::Stat(const std::string& path, SystemTools::Stat_t* buf)
|
||||
// long paths, but _wstat64 rejects paths with '?' in them, thinking
|
||||
// they are wildcards.
|
||||
std::wstring const& wpath = Encoding::ToWide(path);
|
||||
# if defined(__BORLANDC__)
|
||||
return _wstati64(wpath.c_str(), buf);
|
||||
# else
|
||||
return _wstat64(wpath.c_str(), buf);
|
||||
# endif
|
||||
#else
|
||||
return stat(path.c_str(), buf);
|
||||
#endif
|
||||
|
||||
@@ -67,7 +67,7 @@ static SystemToolsManager SystemToolsManagerInstance;
|
||||
// combined using the | operator.
|
||||
typedef int TestFilePermissions;
|
||||
#if defined(_WIN32) && !defined(__CYGWIN__)
|
||||
// On Windows (VC and Borland), no system header defines these constants...
|
||||
// On Windows (VC), no system header defines these constants...
|
||||
static const TestFilePermissions TEST_FILE_OK = 0;
|
||||
static const TestFilePermissions TEST_FILE_READ = 4;
|
||||
static const TestFilePermissions TEST_FILE_WRITE = 2;
|
||||
@@ -317,11 +317,7 @@ public:
|
||||
* Cross platform wrapper for stat struct
|
||||
*/
|
||||
#if defined(_WIN32) && !defined(__CYGWIN__)
|
||||
# if defined(__BORLANDC__)
|
||||
typedef struct stati64 Stat_t;
|
||||
# else
|
||||
typedef struct _stat64 Stat_t;
|
||||
# endif
|
||||
#else
|
||||
typedef struct stat Stat_t;
|
||||
#endif
|
||||
@@ -555,7 +551,7 @@ public:
|
||||
static FILE* Fopen(const std::string& file, const char* mode);
|
||||
|
||||
/**
|
||||
* Visual C++ does not define mode_t (note that Borland does, however).
|
||||
* Visual C++ does not define mode_t.
|
||||
*/
|
||||
#if defined(_MSC_VER)
|
||||
typedef unsigned short mode_t;
|
||||
|
||||
@@ -1,166 +0,0 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
|
||||
/*
|
||||
* Copyright (c) 1996
|
||||
* Silicon Graphics Computer Systems, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Silicon Graphics makes no
|
||||
* representations about the suitability of this software for any
|
||||
* purpose. It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 1994
|
||||
* Hewlett-Packard Company
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Hewlett-Packard Company makes no
|
||||
* representations about the suitability of this software for any
|
||||
* purpose. It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*/
|
||||
#ifndef @KWSYS_NAMESPACE@_hash_fun_hxx
|
||||
#define @KWSYS_NAMESPACE@_hash_fun_hxx
|
||||
|
||||
#include <@KWSYS_NAMESPACE@/Configure.hxx>
|
||||
|
||||
#include <stddef.h> // size_t
|
||||
#include <string>
|
||||
|
||||
namespace @KWSYS_NAMESPACE@ {
|
||||
|
||||
template <class _Key>
|
||||
struct hash
|
||||
{
|
||||
};
|
||||
|
||||
inline size_t _stl_hash_string(const char* __s)
|
||||
{
|
||||
unsigned long __h = 0;
|
||||
for (; *__s; ++__s)
|
||||
__h = 5 * __h + *__s;
|
||||
|
||||
return size_t(__h);
|
||||
}
|
||||
|
||||
template <>
|
||||
struct hash<char*>
|
||||
{
|
||||
size_t operator()(const char* __s) const { return _stl_hash_string(__s); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<const char*>
|
||||
{
|
||||
size_t operator()(const char* __s) const { return _stl_hash_string(__s); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<std::string>
|
||||
{
|
||||
size_t operator()(const std::string& __s) const
|
||||
{
|
||||
return _stl_hash_string(__s.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
#if !defined(__BORLANDC__)
|
||||
template <>
|
||||
struct hash<const std::string>
|
||||
{
|
||||
size_t operator()(const std::string& __s) const
|
||||
{
|
||||
return _stl_hash_string(__s.c_str());
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
template <>
|
||||
struct hash<char>
|
||||
{
|
||||
size_t operator()(char __x) const { return __x; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<unsigned char>
|
||||
{
|
||||
size_t operator()(unsigned char __x) const { return __x; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<signed char>
|
||||
{
|
||||
size_t operator()(unsigned char __x) const { return __x; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<short>
|
||||
{
|
||||
size_t operator()(short __x) const { return __x; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<unsigned short>
|
||||
{
|
||||
size_t operator()(unsigned short __x) const { return __x; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<int>
|
||||
{
|
||||
size_t operator()(int __x) const { return __x; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<unsigned int>
|
||||
{
|
||||
size_t operator()(unsigned int __x) const { return __x; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<long>
|
||||
{
|
||||
size_t operator()(long __x) const { return __x; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<unsigned long>
|
||||
{
|
||||
size_t operator()(unsigned long __x) const { return __x; }
|
||||
};
|
||||
|
||||
// use long long or __int64
|
||||
#if @KWSYS_USE_LONG_LONG@
|
||||
template <>
|
||||
struct hash<long long>
|
||||
{
|
||||
size_t operator()(long long __x) const { return __x; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<unsigned long long>
|
||||
{
|
||||
size_t operator()(unsigned long long __x) const { return __x; }
|
||||
};
|
||||
#elif @KWSYS_USE___INT64@
|
||||
template <>
|
||||
struct hash<__int64>
|
||||
{
|
||||
size_t operator()(__int64 __x) const { return __x; }
|
||||
};
|
||||
template <>
|
||||
struct hash<unsigned __int64>
|
||||
{
|
||||
size_t operator()(unsigned __int64 __x) const { return __x; }
|
||||
};
|
||||
#endif // use long long or __int64
|
||||
|
||||
} // namespace @KWSYS_NAMESPACE@
|
||||
|
||||
#endif
|
||||
@@ -1,423 +0,0 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
|
||||
/*
|
||||
* Copyright (c) 1996
|
||||
* Silicon Graphics Computer Systems, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Silicon Graphics makes no
|
||||
* representations about the suitability of this software for any
|
||||
* purpose. It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 1994
|
||||
* Hewlett-Packard Company
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Hewlett-Packard Company makes no
|
||||
* representations about the suitability of this software for any
|
||||
* purpose. It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*/
|
||||
#ifndef @KWSYS_NAMESPACE@_hash_map_hxx
|
||||
#define @KWSYS_NAMESPACE@_hash_map_hxx
|
||||
|
||||
#include <@KWSYS_NAMESPACE@/hashtable.hxx>
|
||||
|
||||
#include <@KWSYS_NAMESPACE@/hash_fun.hxx>
|
||||
|
||||
#include <functional> // equal_to
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable : 4284)
|
||||
# pragma warning(disable : 4786)
|
||||
#endif
|
||||
|
||||
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
|
||||
# pragma set woff 1174
|
||||
# pragma set woff 1375
|
||||
#endif
|
||||
|
||||
namespace @KWSYS_NAMESPACE@ {
|
||||
|
||||
// select1st is an extension: it is not part of the standard.
|
||||
template <class T1, class T2>
|
||||
struct hash_select1st
|
||||
{
|
||||
const T1& operator()(const std::pair<T1, T2>& __x) const
|
||||
{
|
||||
return __x.first;
|
||||
}
|
||||
};
|
||||
|
||||
// Forward declaration of equality operator; needed for friend declaration.
|
||||
|
||||
template <class _Key, class _Tp, class _HashFcn = hash<_Key>,
|
||||
class _EqualKey = std::equal_to<_Key>,
|
||||
class _Alloc = std::allocator<char> >
|
||||
class hash_map;
|
||||
|
||||
template <class _Key, class _Tp, class _HashFn, class _EqKey, class _Alloc>
|
||||
bool operator==(const hash_map<_Key, _Tp, _HashFn, _EqKey, _Alloc>&,
|
||||
const hash_map<_Key, _Tp, _HashFn, _EqKey, _Alloc>&);
|
||||
|
||||
template <class _Key, class _Tp, class _HashFcn, class _EqualKey, class _Alloc>
|
||||
class hash_map
|
||||
{
|
||||
private:
|
||||
typedef hashtable<std::pair<const _Key, _Tp>, _Key, _HashFcn,
|
||||
hash_select1st<const _Key, _Tp>, _EqualKey, _Alloc>
|
||||
_Ht;
|
||||
_Ht _M_ht;
|
||||
|
||||
public:
|
||||
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::iterator iterator;
|
||||
typedef typename _Ht::const_iterator const_iterator;
|
||||
|
||||
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_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)
|
||||
{
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public:
|
||||
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==<>(const hash_map&, const hash_map&);
|
||||
|
||||
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:
|
||||
std::pair<iterator, bool> insert(const value_type& __obj)
|
||||
{
|
||||
return _M_ht.insert_unique(__obj);
|
||||
}
|
||||
template <class _InputIterator>
|
||||
void insert(_InputIterator __f, _InputIterator __l)
|
||||
{
|
||||
_M_ht.insert_unique(__f, __l);
|
||||
}
|
||||
std::pair<iterator, bool> insert_noresize(const value_type& __obj)
|
||||
{
|
||||
return _M_ht.insert_unique_noresize(__obj);
|
||||
}
|
||||
|
||||
iterator find(const key_type& __key) { return _M_ht.find(__key); }
|
||||
const_iterator find(const key_type& __key) const
|
||||
{
|
||||
return _M_ht.find(__key);
|
||||
}
|
||||
|
||||
_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 _M_ht.count(__key); }
|
||||
|
||||
std::pair<iterator, iterator> equal_range(const key_type& __key)
|
||||
{
|
||||
return _M_ht.equal_range(__key);
|
||||
}
|
||||
std::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 _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(); }
|
||||
|
||||
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 _Tp, class _HashFcn, class _EqlKey, class _Alloc>
|
||||
bool operator==(const hash_map<_Key, _Tp, _HashFcn, _EqlKey, _Alloc>& __hm1,
|
||||
const hash_map<_Key, _Tp, _HashFcn, _EqlKey, _Alloc>& __hm2)
|
||||
{
|
||||
return __hm1._M_ht == __hm2._M_ht;
|
||||
}
|
||||
|
||||
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 == __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);
|
||||
}
|
||||
|
||||
// Forward declaration of equality operator; needed for friend declaration.
|
||||
|
||||
template <class _Key, class _Tp, class _HashFcn = hash<_Key>,
|
||||
class _EqualKey = std::equal_to<_Key>,
|
||||
class _Alloc = std::allocator<char> >
|
||||
class hash_multimap;
|
||||
|
||||
template <class _Key, class _Tp, class _HF, class _EqKey, class _Alloc>
|
||||
bool operator==(const hash_multimap<_Key, _Tp, _HF, _EqKey, _Alloc>& __hm1,
|
||||
const hash_multimap<_Key, _Tp, _HF, _EqKey, _Alloc>& __hm2);
|
||||
|
||||
template <class _Key, class _Tp, class _HashFcn, class _EqualKey, class _Alloc>
|
||||
class hash_multimap
|
||||
{
|
||||
private:
|
||||
typedef hashtable<std::pair<const _Key, _Tp>, _Key, _HashFcn,
|
||||
hash_select1st<const _Key, _Tp>, _EqualKey, _Alloc>
|
||||
_Ht;
|
||||
_Ht _M_ht;
|
||||
|
||||
public:
|
||||
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::iterator iterator;
|
||||
typedef typename _Ht::const_iterator const_iterator;
|
||||
|
||||
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()
|
||||
: _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)
|
||||
{
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public:
|
||||
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==<>(const hash_multimap&, const hash_multimap&);
|
||||
|
||||
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 _M_ht.insert_equal(__obj);
|
||||
}
|
||||
template <class _InputIterator>
|
||||
void insert(_InputIterator __f, _InputIterator __l)
|
||||
{
|
||||
_M_ht.insert_equal(__f, __l);
|
||||
}
|
||||
iterator insert_noresize(const value_type& __obj)
|
||||
{
|
||||
return _M_ht.insert_equal_noresize(__obj);
|
||||
}
|
||||
|
||||
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 _M_ht.count(__key); }
|
||||
|
||||
std::pair<iterator, iterator> equal_range(const key_type& __key)
|
||||
{
|
||||
return _M_ht.equal_range(__key);
|
||||
}
|
||||
std::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 _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) { _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 _Tp, class _HF, class _EqKey, class _Alloc>
|
||||
bool operator==(const hash_multimap<_Key, _Tp, _HF, _EqKey, _Alloc>& __hm1,
|
||||
const hash_multimap<_Key, _Tp, _HF, _EqKey, _Alloc>& __hm2)
|
||||
{
|
||||
return __hm1._M_ht == __hm2._M_ht;
|
||||
}
|
||||
|
||||
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 == __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);
|
||||
}
|
||||
|
||||
} // namespace @KWSYS_NAMESPACE@
|
||||
|
||||
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
|
||||
# pragma reset woff 1174
|
||||
# pragma reset woff 1375
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,392 +0,0 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
|
||||
/*
|
||||
* Copyright (c) 1996
|
||||
* Silicon Graphics Computer Systems, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Silicon Graphics makes no
|
||||
* representations about the suitability of this software for any
|
||||
* purpose. It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 1994
|
||||
* Hewlett-Packard Company
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Hewlett-Packard Company makes no
|
||||
* representations about the suitability of this software for any
|
||||
* purpose. It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*/
|
||||
#ifndef @KWSYS_NAMESPACE@_hash_set_hxx
|
||||
#define @KWSYS_NAMESPACE@_hash_set_hxx
|
||||
|
||||
#include <@KWSYS_NAMESPACE@/hashtable.hxx>
|
||||
|
||||
#include <@KWSYS_NAMESPACE@/hash_fun.hxx>
|
||||
|
||||
#include <functional> // equal_to
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable : 4284)
|
||||
# pragma warning(disable : 4786)
|
||||
#endif
|
||||
|
||||
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
|
||||
# pragma set woff 1174
|
||||
# pragma set woff 1375
|
||||
#endif
|
||||
|
||||
namespace @KWSYS_NAMESPACE@ {
|
||||
|
||||
// identity is an extension: it is not part of the standard.
|
||||
template <class _Tp>
|
||||
struct _Identity
|
||||
{
|
||||
const _Tp& operator()(const _Tp& __x) const { return __x; }
|
||||
};
|
||||
|
||||
// Forward declaration of equality operator; needed for friend declaration.
|
||||
|
||||
template <class _Value, class _HashFcn = hash<_Value>,
|
||||
class _EqualKey = std::equal_to<_Value>,
|
||||
class _Alloc = std::allocator<char> >
|
||||
class hash_set;
|
||||
|
||||
template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
|
||||
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>
|
||||
class hash_set
|
||||
{
|
||||
private:
|
||||
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::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::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()
|
||||
: _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)
|
||||
{
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public:
|
||||
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==<>(const hash_set&, const hash_set&);
|
||||
|
||||
iterator begin() const { return _M_ht.begin(); }
|
||||
iterator end() const { return _M_ht.end(); }
|
||||
|
||||
public:
|
||||
std::pair<iterator, bool> insert(const value_type& __obj)
|
||||
{
|
||||
typedef typename _Ht::iterator _Ht_iterator;
|
||||
std::pair<_Ht_iterator, bool> __p = _M_ht.insert_unique(__obj);
|
||||
return std::pair<iterator, bool>(__p.first, __p.second);
|
||||
}
|
||||
template <class _InputIterator>
|
||||
void insert(_InputIterator __f, _InputIterator __l)
|
||||
{
|
||||
_M_ht.insert_unique(__f, __l);
|
||||
}
|
||||
std::pair<iterator, bool> insert_noresize(const value_type& __obj)
|
||||
{
|
||||
typedef typename _Ht::iterator _Ht_iterator;
|
||||
std::pair<_Ht_iterator, bool> __p = _M_ht.insert_unique_noresize(__obj);
|
||||
return std::pair<iterator, bool>(__p.first, __p.second);
|
||||
}
|
||||
|
||||
iterator find(const key_type& __key) const { return _M_ht.find(__key); }
|
||||
|
||||
size_type count(const key_type& __key) const { return _M_ht.count(__key); }
|
||||
|
||||
std::pair<iterator, iterator> equal_range(const key_type& __key) const
|
||||
{
|
||||
return _M_ht.equal_range(__key);
|
||||
}
|
||||
|
||||
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) { _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>
|
||||
bool operator==(const hash_set<_Value, _HashFcn, _EqualKey, _Alloc>& __hs1,
|
||||
const hash_set<_Value, _HashFcn, _EqualKey, _Alloc>& __hs2)
|
||||
{
|
||||
return __hs1._M_ht == __hs2._M_ht;
|
||||
}
|
||||
|
||||
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 == __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);
|
||||
}
|
||||
|
||||
template <class _Value, class _HashFcn = hash<_Value>,
|
||||
class _EqualKey = std::equal_to<_Value>,
|
||||
class _Alloc = std::allocator<char> >
|
||||
class hash_multiset;
|
||||
|
||||
template <class _Val, class _HashFcn, class _EqualKey, class _Alloc>
|
||||
bool operator==(const hash_multiset<_Val, _HashFcn, _EqualKey, _Alloc>& __hs1,
|
||||
const hash_multiset<_Val, _HashFcn, _EqualKey, _Alloc>& __hs2);
|
||||
|
||||
template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
|
||||
class hash_multiset
|
||||
{
|
||||
private:
|
||||
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::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::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()
|
||||
: _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)
|
||||
{
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public:
|
||||
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==<>(const hash_multiset&, const hash_multiset&);
|
||||
|
||||
iterator begin() const { return _M_ht.begin(); }
|
||||
iterator end() const { return _M_ht.end(); }
|
||||
|
||||
public:
|
||||
iterator insert(const value_type& __obj)
|
||||
{
|
||||
return _M_ht.insert_equal(__obj);
|
||||
}
|
||||
template <class _InputIterator>
|
||||
void insert(_InputIterator __f, _InputIterator __l)
|
||||
{
|
||||
_M_ht.insert_equal(__f, __l);
|
||||
}
|
||||
iterator insert_noresize(const value_type& __obj)
|
||||
{
|
||||
return _M_ht.insert_equal_noresize(__obj);
|
||||
}
|
||||
|
||||
iterator find(const key_type& __key) const { return _M_ht.find(__key); }
|
||||
|
||||
size_type count(const key_type& __key) const { return _M_ht.count(__key); }
|
||||
|
||||
std::pair<iterator, iterator> equal_range(const key_type& __key) const
|
||||
{
|
||||
return _M_ht.equal_range(__key);
|
||||
}
|
||||
|
||||
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) { _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>
|
||||
bool operator==(const hash_multiset<_Val, _HashFcn, _EqualKey, _Alloc>& __hs1,
|
||||
const hash_multiset<_Val, _HashFcn, _EqualKey, _Alloc>& __hs2)
|
||||
{
|
||||
return __hs1._M_ht == __hs2._M_ht;
|
||||
}
|
||||
|
||||
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 == __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);
|
||||
}
|
||||
|
||||
} // namespace @KWSYS_NAMESPACE@
|
||||
|
||||
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
|
||||
# pragma reset woff 1174
|
||||
# pragma reset woff 1375
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,995 +0,0 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
|
||||
/*
|
||||
* Copyright (c) 1996
|
||||
* Silicon Graphics Computer Systems, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Silicon Graphics makes no
|
||||
* representations about the suitability of this software for any
|
||||
* purpose. It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 1994
|
||||
* Hewlett-Packard Company
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Hewlett-Packard Company makes no
|
||||
* representations about the suitability of this software for any
|
||||
* purpose. It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*/
|
||||
#ifdef __BORLANDC__
|
||||
# pragma warn - 8027 /* 'for' not inlined. */
|
||||
# pragma warn - 8026 /* 'exception' not inlined. */
|
||||
#endif
|
||||
|
||||
#ifndef @KWSYS_NAMESPACE@_hashtable_hxx
|
||||
# define @KWSYS_NAMESPACE@_hashtable_hxx
|
||||
|
||||
# include <@KWSYS_NAMESPACE@/Configure.hxx>
|
||||
|
||||
# include <algorithm> // lower_bound
|
||||
# include <iterator> // iterator_traits
|
||||
# include <memory> // allocator
|
||||
# include <stddef.h> // size_t
|
||||
# include <utility> // pair
|
||||
# include <vector> // vector
|
||||
|
||||
# if defined(_MSC_VER)
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable : 4284)
|
||||
# pragma warning(disable : 4786)
|
||||
# pragma warning(disable : 4512) /* no assignment operator for class */
|
||||
# endif
|
||||
# if defined(__sgi) && !defined(__GNUC__)
|
||||
# pragma set woff 3970 /* pointer to int conversion */ 3321 3968
|
||||
# endif
|
||||
|
||||
// In C++11, clang will warn about using dynamic exception specifications
|
||||
// as they are deprecated. But as this class is trying to faithfully
|
||||
// mimic unordered_set and unordered_map, we want to keep the 'throw()'
|
||||
// decorations below. So we suppress the warning.
|
||||
# if defined(__clang__) && defined(__has_warning)
|
||||
# if __has_warning("-Wdeprecated")
|
||||
# pragma clang diagnostic push
|
||||
# pragma clang diagnostic ignored "-Wdeprecated"
|
||||
# endif
|
||||
# endif
|
||||
|
||||
namespace @KWSYS_NAMESPACE@ {
|
||||
|
||||
template <class _Val>
|
||||
struct _Hashtable_node
|
||||
{
|
||||
_Hashtable_node* _M_next;
|
||||
_Val _M_val;
|
||||
void public_method_to_quiet_warning_about_all_methods_private();
|
||||
|
||||
private:
|
||||
void operator=(_Hashtable_node<_Val> const&) = delete;
|
||||
};
|
||||
|
||||
template <class _Val, class _Key, class _HashFcn, class _ExtractKey,
|
||||
class _EqualKey, class _Alloc = std::allocator<char> >
|
||||
class hashtable;
|
||||
|
||||
template <class _Val, class _Key, class _HashFcn, class _ExtractKey,
|
||||
class _EqualKey, class _Alloc>
|
||||
struct _Hashtable_iterator;
|
||||
|
||||
template <class _Val, class _Key, class _HashFcn, class _ExtractKey,
|
||||
class _EqualKey, class _Alloc>
|
||||
struct _Hashtable_const_iterator;
|
||||
|
||||
template <class _Val, class _Key, class _HashFcn, class _ExtractKey,
|
||||
class _EqualKey, class _Alloc>
|
||||
struct _Hashtable_iterator
|
||||
{
|
||||
typedef hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc>
|
||||
_Hashtable;
|
||||
typedef _Hashtable_iterator<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey,
|
||||
_Alloc>
|
||||
iterator;
|
||||
typedef _Hashtable_const_iterator<_Val, _Key, _HashFcn, _ExtractKey,
|
||||
_EqualKey, _Alloc>
|
||||
const_iterator;
|
||||
typedef _Hashtable_node<_Val> _Node;
|
||||
|
||||
typedef std::forward_iterator_tag iterator_category;
|
||||
typedef _Val value_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef size_t size_type;
|
||||
typedef _Val& reference;
|
||||
typedef _Val* pointer;
|
||||
|
||||
_Node* _M_cur;
|
||||
_Hashtable* _M_ht;
|
||||
|
||||
_Hashtable_iterator(_Node* __n, _Hashtable* __tab)
|
||||
: _M_cur(__n)
|
||||
, _M_ht(__tab)
|
||||
{
|
||||
}
|
||||
_Hashtable_iterator() {}
|
||||
reference operator*() const { return _M_cur->_M_val; }
|
||||
pointer operator->() const { return &(operator*()); }
|
||||
iterator& operator++();
|
||||
iterator operator++(int);
|
||||
bool operator==(const iterator& __it) const { return _M_cur == __it._M_cur; }
|
||||
bool operator!=(const iterator& __it) const { return _M_cur != __it._M_cur; }
|
||||
};
|
||||
|
||||
template <class _Val, class _Key, class _HashFcn, class _ExtractKey,
|
||||
class _EqualKey, class _Alloc>
|
||||
struct _Hashtable_const_iterator
|
||||
{
|
||||
typedef hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc>
|
||||
_Hashtable;
|
||||
typedef _Hashtable_iterator<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey,
|
||||
_Alloc>
|
||||
iterator;
|
||||
typedef _Hashtable_const_iterator<_Val, _Key, _HashFcn, _ExtractKey,
|
||||
_EqualKey, _Alloc>
|
||||
const_iterator;
|
||||
typedef _Hashtable_node<_Val> _Node;
|
||||
|
||||
typedef std::forward_iterator_tag iterator_category;
|
||||
typedef _Val value_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef size_t size_type;
|
||||
typedef const _Val& reference;
|
||||
typedef const _Val* pointer;
|
||||
|
||||
const _Node* _M_cur;
|
||||
const _Hashtable* _M_ht;
|
||||
|
||||
_Hashtable_const_iterator(const _Node* __n, const _Hashtable* __tab)
|
||||
: _M_cur(__n)
|
||||
, _M_ht(__tab)
|
||||
{
|
||||
}
|
||||
_Hashtable_const_iterator() {}
|
||||
_Hashtable_const_iterator(const iterator& __it)
|
||||
: _M_cur(__it._M_cur)
|
||||
, _M_ht(__it._M_ht)
|
||||
{
|
||||
}
|
||||
reference operator*() const { return _M_cur->_M_val; }
|
||||
pointer operator->() const { return &(operator*()); }
|
||||
const_iterator& operator++();
|
||||
const_iterator operator++(int);
|
||||
bool operator==(const const_iterator& __it) const
|
||||
{
|
||||
return _M_cur == __it._M_cur;
|
||||
}
|
||||
bool operator!=(const const_iterator& __it) const
|
||||
{
|
||||
return _M_cur != __it._M_cur;
|
||||
}
|
||||
};
|
||||
|
||||
// Note: assumes long is at least 32 bits.
|
||||
enum
|
||||
{
|
||||
_stl_num_primes = 31
|
||||
};
|
||||
|
||||
// create a function with a static local to that function that returns
|
||||
// the static
|
||||
static inline const unsigned long* get_stl_prime_list()
|
||||
{
|
||||
|
||||
static const unsigned long _stl_prime_list[_stl_num_primes] = {
|
||||
5ul, 11ul, 23ul, 53ul, 97ul,
|
||||
193ul, 389ul, 769ul, 1543ul, 3079ul,
|
||||
6151ul, 12289ul, 24593ul, 49157ul, 98317ul,
|
||||
196613ul, 393241ul, 786433ul, 1572869ul, 3145739ul,
|
||||
6291469ul, 12582917ul, 25165843ul, 50331653ul, 100663319ul,
|
||||
201326611ul, 402653189ul, 805306457ul, 1610612741ul, 3221225473ul,
|
||||
4294967291ul
|
||||
};
|
||||
|
||||
return &_stl_prime_list[0];
|
||||
}
|
||||
|
||||
static inline size_t _stl_next_prime(size_t __n)
|
||||
{
|
||||
const unsigned long* __first = get_stl_prime_list();
|
||||
const unsigned long* __last = get_stl_prime_list() + (int)_stl_num_primes;
|
||||
const unsigned long* pos = std::lower_bound(__first, __last, __n);
|
||||
return pos == __last ? *(__last - 1) : *pos;
|
||||
}
|
||||
|
||||
// Forward declaration of operator==.
|
||||
|
||||
template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
|
||||
class hashtable;
|
||||
|
||||
template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
|
||||
bool operator==(const hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>& __ht1,
|
||||
const hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>& __ht2);
|
||||
|
||||
// Hashtables handle allocators a bit differently than other containers
|
||||
// do. If we're using standard-conforming allocators, then a hashtable
|
||||
// unconditionally has a member variable to hold its allocator, even if
|
||||
// it so happens that all instances of the allocator type are identical.
|
||||
// This is because, for hashtables, this extra storage is negligible.
|
||||
// Additionally, a base class wouldn't serve any other purposes; it
|
||||
// wouldn't, for example, simplify the exception-handling code.
|
||||
|
||||
template <class _Val, class _Key, class _HashFcn, class _ExtractKey,
|
||||
class _EqualKey, class _Alloc>
|
||||
class hashtable
|
||||
{
|
||||
public:
|
||||
typedef _Key key_type;
|
||||
typedef _Val value_type;
|
||||
typedef _HashFcn hasher;
|
||||
typedef _EqualKey key_equal;
|
||||
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef value_type* pointer;
|
||||
typedef const value_type* const_pointer;
|
||||
typedef value_type& reference;
|
||||
typedef const value_type& const_reference;
|
||||
|
||||
hasher hash_funct() const { return _M_hash; }
|
||||
key_equal key_eq() const { return _M_equals; }
|
||||
|
||||
private:
|
||||
typedef _Hashtable_node<_Val> _Node;
|
||||
|
||||
public:
|
||||
typedef typename _Alloc::template rebind<_Val>::other allocator_type;
|
||||
allocator_type get_allocator() const { return _M_node_allocator; }
|
||||
|
||||
private:
|
||||
typedef
|
||||
typename _Alloc::template rebind<_Node>::other _M_node_allocator_type;
|
||||
typedef
|
||||
typename _Alloc::template rebind<_Node*>::other _M_node_ptr_allocator_type;
|
||||
typedef std::vector<_Node*, _M_node_ptr_allocator_type> _M_buckets_type;
|
||||
|
||||
private:
|
||||
_M_node_allocator_type _M_node_allocator;
|
||||
hasher _M_hash;
|
||||
key_equal _M_equals;
|
||||
_ExtractKey _M_get_key;
|
||||
_M_buckets_type _M_buckets;
|
||||
size_type _M_num_elements;
|
||||
|
||||
_Node* _M_get_node() { return _M_node_allocator.allocate(1); }
|
||||
void _M_put_node(_Node* __p) { _M_node_allocator.deallocate(__p, 1); }
|
||||
|
||||
public:
|
||||
typedef _Hashtable_iterator<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey,
|
||||
_Alloc>
|
||||
iterator;
|
||||
typedef _Hashtable_const_iterator<_Val, _Key, _HashFcn, _ExtractKey,
|
||||
_EqualKey, _Alloc>
|
||||
const_iterator;
|
||||
|
||||
friend struct _Hashtable_iterator<_Val, _Key, _HashFcn, _ExtractKey,
|
||||
_EqualKey, _Alloc>;
|
||||
friend struct _Hashtable_const_iterator<_Val, _Key, _HashFcn, _ExtractKey,
|
||||
_EqualKey, _Alloc>;
|
||||
|
||||
public:
|
||||
hashtable(size_type __n, const _HashFcn& __hf, const _EqualKey& __eql,
|
||||
const _ExtractKey& __ext,
|
||||
const allocator_type& __a = allocator_type())
|
||||
: _M_node_allocator(__a)
|
||||
, _M_hash(__hf)
|
||||
, _M_equals(__eql)
|
||||
, _M_get_key(__ext)
|
||||
, _M_buckets(__a)
|
||||
, _M_num_elements(0)
|
||||
{
|
||||
_M_initialize_buckets(__n);
|
||||
}
|
||||
|
||||
hashtable(size_type __n, const _HashFcn& __hf, const _EqualKey& __eql,
|
||||
const allocator_type& __a = allocator_type())
|
||||
: _M_node_allocator(__a)
|
||||
, _M_hash(__hf)
|
||||
, _M_equals(__eql)
|
||||
, _M_get_key(_ExtractKey())
|
||||
, _M_buckets(__a)
|
||||
, _M_num_elements(0)
|
||||
{
|
||||
_M_initialize_buckets(__n);
|
||||
}
|
||||
|
||||
hashtable(const hashtable& __ht)
|
||||
: _M_node_allocator(__ht.get_allocator())
|
||||
, _M_hash(__ht._M_hash)
|
||||
, _M_equals(__ht._M_equals)
|
||||
, _M_get_key(__ht._M_get_key)
|
||||
, _M_buckets(__ht.get_allocator())
|
||||
, _M_num_elements(0)
|
||||
{
|
||||
_M_copy_from(__ht);
|
||||
}
|
||||
|
||||
hashtable& operator=(const hashtable& __ht)
|
||||
{
|
||||
if (&__ht != this) {
|
||||
clear();
|
||||
_M_hash = __ht._M_hash;
|
||||
_M_equals = __ht._M_equals;
|
||||
_M_get_key = __ht._M_get_key;
|
||||
_M_copy_from(__ht);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
~hashtable() { clear(); }
|
||||
|
||||
size_type size() const { return _M_num_elements; }
|
||||
size_type max_size() const { return size_type(-1); }
|
||||
bool empty() const { return size() == 0; }
|
||||
|
||||
void swap(hashtable& __ht)
|
||||
{
|
||||
std::swap(_M_hash, __ht._M_hash);
|
||||
std::swap(_M_equals, __ht._M_equals);
|
||||
std::swap(_M_get_key, __ht._M_get_key);
|
||||
_M_buckets.swap(__ht._M_buckets);
|
||||
std::swap(_M_num_elements, __ht._M_num_elements);
|
||||
}
|
||||
|
||||
iterator begin()
|
||||
{
|
||||
for (size_type __n = 0; __n < _M_buckets.size(); ++__n)
|
||||
if (_M_buckets[__n])
|
||||
return iterator(_M_buckets[__n], this);
|
||||
return end();
|
||||
}
|
||||
|
||||
iterator end() { return iterator(nullptr, this); }
|
||||
|
||||
const_iterator begin() const
|
||||
{
|
||||
for (size_type __n = 0; __n < _M_buckets.size(); ++__n)
|
||||
if (_M_buckets[__n])
|
||||
return const_iterator(_M_buckets[__n], this);
|
||||
return end();
|
||||
}
|
||||
|
||||
const_iterator end() const { return const_iterator(nullptr, this); }
|
||||
|
||||
friend bool operator==<>(const hashtable&, const hashtable&);
|
||||
|
||||
public:
|
||||
size_type bucket_count() const { return _M_buckets.size(); }
|
||||
|
||||
size_type max_bucket_count() const
|
||||
{
|
||||
return get_stl_prime_list()[(int)_stl_num_primes - 1];
|
||||
}
|
||||
|
||||
size_type elems_in_bucket(size_type __bucket) const
|
||||
{
|
||||
size_type __result = 0;
|
||||
for (_Node* __cur = _M_buckets[__bucket]; __cur; __cur = __cur->_M_next)
|
||||
__result += 1;
|
||||
return __result;
|
||||
}
|
||||
|
||||
std::pair<iterator, bool> insert_unique(const value_type& __obj)
|
||||
{
|
||||
resize(_M_num_elements + 1);
|
||||
return insert_unique_noresize(__obj);
|
||||
}
|
||||
|
||||
iterator insert_equal(const value_type& __obj)
|
||||
{
|
||||
resize(_M_num_elements + 1);
|
||||
return insert_equal_noresize(__obj);
|
||||
}
|
||||
|
||||
std::pair<iterator, bool> insert_unique_noresize(const value_type& __obj);
|
||||
iterator insert_equal_noresize(const value_type& __obj);
|
||||
|
||||
template <class _InputIterator>
|
||||
void insert_unique(_InputIterator __f, _InputIterator __l)
|
||||
{
|
||||
insert_unique(
|
||||
__f, __l,
|
||||
typename std::iterator_traits<_InputIterator>::iterator_category());
|
||||
}
|
||||
|
||||
template <class _InputIterator>
|
||||
void insert_equal(_InputIterator __f, _InputIterator __l)
|
||||
{
|
||||
insert_equal(
|
||||
__f, __l,
|
||||
typename std::iterator_traits<_InputIterator>::iterator_category());
|
||||
}
|
||||
|
||||
template <class _InputIterator>
|
||||
void insert_unique(_InputIterator __f, _InputIterator __l,
|
||||
std::input_iterator_tag)
|
||||
{
|
||||
for (; __f != __l; ++__f)
|
||||
insert_unique(*__f);
|
||||
}
|
||||
|
||||
template <class _InputIterator>
|
||||
void insert_equal(_InputIterator __f, _InputIterator __l,
|
||||
std::input_iterator_tag)
|
||||
{
|
||||
for (; __f != __l; ++__f)
|
||||
insert_equal(*__f);
|
||||
}
|
||||
|
||||
template <class _ForwardIterator>
|
||||
void insert_unique(_ForwardIterator __f, _ForwardIterator __l,
|
||||
std::forward_iterator_tag)
|
||||
{
|
||||
size_type __n = 0;
|
||||
std::distance(__f, __l, __n);
|
||||
resize(_M_num_elements + __n);
|
||||
for (; __n > 0; --__n, ++__f)
|
||||
insert_unique_noresize(*__f);
|
||||
}
|
||||
|
||||
template <class _ForwardIterator>
|
||||
void insert_equal(_ForwardIterator __f, _ForwardIterator __l,
|
||||
std::forward_iterator_tag)
|
||||
{
|
||||
size_type __n = 0;
|
||||
std::distance(__f, __l, __n);
|
||||
resize(_M_num_elements + __n);
|
||||
for (; __n > 0; --__n, ++__f)
|
||||
insert_equal_noresize(*__f);
|
||||
}
|
||||
|
||||
reference find_or_insert(const value_type& __obj);
|
||||
|
||||
iterator find(const key_type& __key)
|
||||
{
|
||||
size_type __n = _M_bkt_num_key(__key);
|
||||
_Node* __first;
|
||||
for (__first = _M_buckets[__n];
|
||||
__first && !_M_equals(_M_get_key(__first->_M_val), __key);
|
||||
__first = __first->_M_next) {
|
||||
}
|
||||
return iterator(__first, this);
|
||||
}
|
||||
|
||||
const_iterator find(const key_type& __key) const
|
||||
{
|
||||
size_type __n = _M_bkt_num_key(__key);
|
||||
const _Node* __first;
|
||||
for (__first = _M_buckets[__n];
|
||||
__first && !_M_equals(_M_get_key(__first->_M_val), __key);
|
||||
__first = __first->_M_next) {
|
||||
}
|
||||
return const_iterator(__first, this);
|
||||
}
|
||||
|
||||
size_type count(const key_type& __key) const
|
||||
{
|
||||
const size_type __n = _M_bkt_num_key(__key);
|
||||
size_type __result = 0;
|
||||
|
||||
for (const _Node* __cur = _M_buckets[__n]; __cur; __cur = __cur->_M_next)
|
||||
if (_M_equals(_M_get_key(__cur->_M_val), __key))
|
||||
++__result;
|
||||
return __result;
|
||||
}
|
||||
|
||||
std::pair<iterator, iterator> equal_range(const key_type& __key);
|
||||
|
||||
std::pair<const_iterator, const_iterator> equal_range(
|
||||
const key_type& __key) const;
|
||||
|
||||
size_type erase(const key_type& __key);
|
||||
void erase(const iterator& __it);
|
||||
void erase(iterator __first, iterator __last);
|
||||
|
||||
void erase(const const_iterator& __it);
|
||||
void erase(const_iterator __first, const_iterator __last);
|
||||
|
||||
void resize(size_type __num_elements_hint);
|
||||
void clear();
|
||||
|
||||
private:
|
||||
size_type _M_next_size(size_type __n) const { return _stl_next_prime(__n); }
|
||||
|
||||
void _M_initialize_buckets(size_type __n)
|
||||
{
|
||||
const size_type __n_buckets = _M_next_size(__n);
|
||||
_M_buckets.reserve(__n_buckets);
|
||||
_M_buckets.insert(_M_buckets.end(), __n_buckets, (_Node*)nullptr);
|
||||
_M_num_elements = 0;
|
||||
}
|
||||
|
||||
size_type _M_bkt_num_key(const key_type& __key) const
|
||||
{
|
||||
return _M_bkt_num_key(__key, _M_buckets.size());
|
||||
}
|
||||
|
||||
size_type _M_bkt_num(const value_type& __obj) const
|
||||
{
|
||||
return _M_bkt_num_key(_M_get_key(__obj));
|
||||
}
|
||||
|
||||
size_type _M_bkt_num_key(const key_type& __key, size_t __n) const
|
||||
{
|
||||
return _M_hash(__key) % __n;
|
||||
}
|
||||
|
||||
size_type _M_bkt_num(const value_type& __obj, size_t __n) const
|
||||
{
|
||||
return _M_bkt_num_key(_M_get_key(__obj), __n);
|
||||
}
|
||||
|
||||
void construct(_Val* p, const _Val& v) { new (p) _Val(v); }
|
||||
void destroy(_Val* p)
|
||||
{
|
||||
(void)p;
|
||||
p->~_Val();
|
||||
}
|
||||
|
||||
_Node* _M_new_node(const value_type& __obj)
|
||||
{
|
||||
_Node* __n = _M_get_node();
|
||||
__n->_M_next = nullptr;
|
||||
try {
|
||||
construct(&__n->_M_val, __obj);
|
||||
return __n;
|
||||
} catch (...) {
|
||||
_M_put_node(__n);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
void _M_delete_node(_Node* __n)
|
||||
{
|
||||
destroy(&__n->_M_val);
|
||||
_M_put_node(__n);
|
||||
}
|
||||
|
||||
void _M_erase_bucket(const size_type __n, _Node* __first, _Node* __last);
|
||||
void _M_erase_bucket(const size_type __n, _Node* __last);
|
||||
|
||||
void _M_copy_from(const hashtable& __ht);
|
||||
};
|
||||
|
||||
template <class _Val, class _Key, class _HF, class _ExK, class _EqK,
|
||||
class _All>
|
||||
_Hashtable_iterator<_Val, _Key, _HF, _ExK, _EqK, _All>&
|
||||
_Hashtable_iterator<_Val, _Key, _HF, _ExK, _EqK, _All>::operator++()
|
||||
{
|
||||
const _Node* __old = _M_cur;
|
||||
_M_cur = _M_cur->_M_next;
|
||||
if (!_M_cur) {
|
||||
size_type __bucket = _M_ht->_M_bkt_num(__old->_M_val);
|
||||
while (!_M_cur && ++__bucket < _M_ht->_M_buckets.size())
|
||||
_M_cur = _M_ht->_M_buckets[__bucket];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class _Val, class _Key, class _HF, class _ExK, class _EqK,
|
||||
class _All>
|
||||
inline _Hashtable_iterator<_Val, _Key, _HF, _ExK, _EqK, _All>
|
||||
_Hashtable_iterator<_Val, _Key, _HF, _ExK, _EqK, _All>::operator++(int)
|
||||
{
|
||||
iterator __tmp = *this;
|
||||
++*this;
|
||||
return __tmp;
|
||||
}
|
||||
|
||||
template <class _Val, class _Key, class _HF, class _ExK, class _EqK,
|
||||
class _All>
|
||||
_Hashtable_const_iterator<_Val, _Key, _HF, _ExK, _EqK, _All>&
|
||||
_Hashtable_const_iterator<_Val, _Key, _HF, _ExK, _EqK, _All>::operator++()
|
||||
{
|
||||
const _Node* __old = _M_cur;
|
||||
_M_cur = _M_cur->_M_next;
|
||||
if (!_M_cur) {
|
||||
size_type __bucket = _M_ht->_M_bkt_num(__old->_M_val);
|
||||
while (!_M_cur && ++__bucket < _M_ht->_M_buckets.size())
|
||||
_M_cur = _M_ht->_M_buckets[__bucket];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class _Val, class _Key, class _HF, class _ExK, class _EqK,
|
||||
class _All>
|
||||
inline _Hashtable_const_iterator<_Val, _Key, _HF, _ExK, _EqK, _All>
|
||||
_Hashtable_const_iterator<_Val, _Key, _HF, _ExK, _EqK, _All>::operator++(int)
|
||||
{
|
||||
const_iterator __tmp = *this;
|
||||
++*this;
|
||||
return __tmp;
|
||||
}
|
||||
|
||||
template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
|
||||
bool operator==(const hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>& __ht1,
|
||||
const hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>& __ht2)
|
||||
{
|
||||
typedef typename hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::_Node _Node;
|
||||
if (__ht1._M_buckets.size() != __ht2._M_buckets.size())
|
||||
return false;
|
||||
for (int __n = 0; __n < __ht1._M_buckets.size(); ++__n) {
|
||||
_Node* __cur1 = __ht1._M_buckets[__n];
|
||||
_Node* __cur2 = __ht2._M_buckets[__n];
|
||||
for (; __cur1 && __cur2 && __cur1->_M_val == __cur2->_M_val;
|
||||
__cur1 = __cur1->_M_next, __cur2 = __cur2->_M_next) {
|
||||
}
|
||||
if (__cur1 || __cur2)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
|
||||
inline bool operator!=(const hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>& __ht1,
|
||||
const hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>& __ht2)
|
||||
{
|
||||
return !(__ht1 == __ht2);
|
||||
}
|
||||
|
||||
template <class _Val, class _Key, class _HF, class _Extract, class _EqKey,
|
||||
class _All>
|
||||
inline void swap(hashtable<_Val, _Key, _HF, _Extract, _EqKey, _All>& __ht1,
|
||||
hashtable<_Val, _Key, _HF, _Extract, _EqKey, _All>& __ht2)
|
||||
{
|
||||
__ht1.swap(__ht2);
|
||||
}
|
||||
|
||||
template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
|
||||
std::pair<typename hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::iterator, bool>
|
||||
hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::insert_unique_noresize(
|
||||
const value_type& __obj)
|
||||
{
|
||||
const size_type __n = _M_bkt_num(__obj);
|
||||
_Node* __first = _M_buckets[__n];
|
||||
|
||||
for (_Node* __cur = __first; __cur; __cur = __cur->_M_next)
|
||||
if (_M_equals(_M_get_key(__cur->_M_val), _M_get_key(__obj)))
|
||||
return std::pair<iterator, bool>(iterator(__cur, this), false);
|
||||
|
||||
_Node* __tmp = _M_new_node(__obj);
|
||||
__tmp->_M_next = __first;
|
||||
_M_buckets[__n] = __tmp;
|
||||
++_M_num_elements;
|
||||
return std::pair<iterator, bool>(iterator(__tmp, this), true);
|
||||
}
|
||||
|
||||
template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
|
||||
typename hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::iterator
|
||||
hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::insert_equal_noresize(
|
||||
const value_type& __obj)
|
||||
{
|
||||
const size_type __n = _M_bkt_num(__obj);
|
||||
_Node* __first = _M_buckets[__n];
|
||||
|
||||
for (_Node* __cur = __first; __cur; __cur = __cur->_M_next)
|
||||
if (_M_equals(_M_get_key(__cur->_M_val), _M_get_key(__obj))) {
|
||||
_Node* __tmp = _M_new_node(__obj);
|
||||
__tmp->_M_next = __cur->_M_next;
|
||||
__cur->_M_next = __tmp;
|
||||
++_M_num_elements;
|
||||
return iterator(__tmp, this);
|
||||
}
|
||||
|
||||
_Node* __tmp = _M_new_node(__obj);
|
||||
__tmp->_M_next = __first;
|
||||
_M_buckets[__n] = __tmp;
|
||||
++_M_num_elements;
|
||||
return iterator(__tmp, this);
|
||||
}
|
||||
|
||||
template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
|
||||
typename hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::reference
|
||||
hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::find_or_insert(
|
||||
const value_type& __obj)
|
||||
{
|
||||
resize(_M_num_elements + 1);
|
||||
|
||||
size_type __n = _M_bkt_num(__obj);
|
||||
_Node* __first = _M_buckets[__n];
|
||||
|
||||
for (_Node* __cur = __first; __cur; __cur = __cur->_M_next)
|
||||
if (_M_equals(_M_get_key(__cur->_M_val), _M_get_key(__obj)))
|
||||
return __cur->_M_val;
|
||||
|
||||
_Node* __tmp = _M_new_node(__obj);
|
||||
__tmp->_M_next = __first;
|
||||
_M_buckets[__n] = __tmp;
|
||||
++_M_num_elements;
|
||||
return __tmp->_M_val;
|
||||
}
|
||||
|
||||
template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
|
||||
std::pair<typename hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::iterator,
|
||||
typename hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::iterator>
|
||||
hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::equal_range(const key_type& __key)
|
||||
{
|
||||
typedef std::pair<iterator, iterator> _Pii;
|
||||
const size_type __n = _M_bkt_num_key(__key);
|
||||
|
||||
for (_Node* __first = _M_buckets[__n]; __first; __first = __first->_M_next)
|
||||
if (_M_equals(_M_get_key(__first->_M_val), __key)) {
|
||||
for (_Node* __cur = __first->_M_next; __cur; __cur = __cur->_M_next)
|
||||
if (!_M_equals(_M_get_key(__cur->_M_val), __key))
|
||||
return _Pii(iterator(__first, this), iterator(__cur, this));
|
||||
for (size_type __m = __n + 1; __m < _M_buckets.size(); ++__m)
|
||||
if (_M_buckets[__m])
|
||||
return _Pii(iterator(__first, this),
|
||||
iterator(_M_buckets[__m], this));
|
||||
return _Pii(iterator(__first, this), end());
|
||||
}
|
||||
return _Pii(end(), end());
|
||||
}
|
||||
|
||||
template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
|
||||
std::pair<typename hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::const_iterator,
|
||||
typename hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::const_iterator>
|
||||
hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::equal_range(
|
||||
const key_type& __key) const
|
||||
{
|
||||
typedef std::pair<const_iterator, const_iterator> _Pii;
|
||||
const size_type __n = _M_bkt_num_key(__key);
|
||||
|
||||
for (const _Node* __first = _M_buckets[__n]; __first;
|
||||
__first = __first->_M_next) {
|
||||
if (_M_equals(_M_get_key(__first->_M_val), __key)) {
|
||||
for (const _Node* __cur = __first->_M_next; __cur;
|
||||
__cur = __cur->_M_next)
|
||||
if (!_M_equals(_M_get_key(__cur->_M_val), __key))
|
||||
return _Pii(const_iterator(__first, this),
|
||||
const_iterator(__cur, this));
|
||||
for (size_type __m = __n + 1; __m < _M_buckets.size(); ++__m)
|
||||
if (_M_buckets[__m])
|
||||
return _Pii(const_iterator(__first, this),
|
||||
const_iterator(_M_buckets[__m], this));
|
||||
return _Pii(const_iterator(__first, this), end());
|
||||
}
|
||||
}
|
||||
return _Pii(end(), end());
|
||||
}
|
||||
|
||||
template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
|
||||
typename hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::size_type
|
||||
hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::erase(const key_type& __key)
|
||||
{
|
||||
const size_type __n = _M_bkt_num_key(__key);
|
||||
_Node* __first = _M_buckets[__n];
|
||||
size_type __erased = 0;
|
||||
|
||||
if (__first) {
|
||||
_Node* __cur = __first;
|
||||
_Node* __next = __cur->_M_next;
|
||||
while (__next) {
|
||||
if (_M_equals(_M_get_key(__next->_M_val), __key)) {
|
||||
__cur->_M_next = __next->_M_next;
|
||||
_M_delete_node(__next);
|
||||
__next = __cur->_M_next;
|
||||
++__erased;
|
||||
--_M_num_elements;
|
||||
} else {
|
||||
__cur = __next;
|
||||
__next = __cur->_M_next;
|
||||
}
|
||||
}
|
||||
if (_M_equals(_M_get_key(__first->_M_val), __key)) {
|
||||
_M_buckets[__n] = __first->_M_next;
|
||||
_M_delete_node(__first);
|
||||
++__erased;
|
||||
--_M_num_elements;
|
||||
}
|
||||
}
|
||||
return __erased;
|
||||
}
|
||||
|
||||
template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
|
||||
void hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::erase(const iterator& __it)
|
||||
{
|
||||
_Node* __p = __it._M_cur;
|
||||
if (__p) {
|
||||
const size_type __n = _M_bkt_num(__p->_M_val);
|
||||
_Node* __cur = _M_buckets[__n];
|
||||
|
||||
if (__cur == __p) {
|
||||
_M_buckets[__n] = __cur->_M_next;
|
||||
_M_delete_node(__cur);
|
||||
--_M_num_elements;
|
||||
} else {
|
||||
_Node* __next = __cur->_M_next;
|
||||
while (__next) {
|
||||
if (__next == __p) {
|
||||
__cur->_M_next = __next->_M_next;
|
||||
_M_delete_node(__next);
|
||||
--_M_num_elements;
|
||||
break;
|
||||
} else {
|
||||
__cur = __next;
|
||||
__next = __cur->_M_next;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
|
||||
void hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::erase(iterator __first,
|
||||
iterator __last)
|
||||
{
|
||||
size_type __f_bucket =
|
||||
__first._M_cur ? _M_bkt_num(__first._M_cur->_M_val) : _M_buckets.size();
|
||||
size_type __l_bucket =
|
||||
__last._M_cur ? _M_bkt_num(__last._M_cur->_M_val) : _M_buckets.size();
|
||||
|
||||
if (__first._M_cur == __last._M_cur)
|
||||
return;
|
||||
else if (__f_bucket == __l_bucket)
|
||||
_M_erase_bucket(__f_bucket, __first._M_cur, __last._M_cur);
|
||||
else {
|
||||
_M_erase_bucket(__f_bucket, __first._M_cur, nullptr);
|
||||
for (size_type __n = __f_bucket + 1; __n < __l_bucket; ++__n)
|
||||
_M_erase_bucket(__n, nullptr);
|
||||
if (__l_bucket != _M_buckets.size())
|
||||
_M_erase_bucket(__l_bucket, __last._M_cur);
|
||||
}
|
||||
}
|
||||
|
||||
template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
|
||||
inline void hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::erase(
|
||||
const_iterator __first, const_iterator __last)
|
||||
{
|
||||
erase(iterator(const_cast<_Node*>(__first._M_cur),
|
||||
const_cast<hashtable*>(__first._M_ht)),
|
||||
iterator(const_cast<_Node*>(__last._M_cur),
|
||||
const_cast<hashtable*>(__last._M_ht)));
|
||||
}
|
||||
|
||||
template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
|
||||
inline void hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::erase(
|
||||
const const_iterator& __it)
|
||||
{
|
||||
erase(iterator(const_cast<_Node*>(__it._M_cur),
|
||||
const_cast<hashtable*>(__it._M_ht)));
|
||||
}
|
||||
|
||||
template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
|
||||
void hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::resize(
|
||||
size_type __num_elements_hint)
|
||||
{
|
||||
const size_type __old_n = _M_buckets.size();
|
||||
if (__num_elements_hint > __old_n) {
|
||||
const size_type __n = _M_next_size(__num_elements_hint);
|
||||
if (__n > __old_n) {
|
||||
_M_buckets_type __tmp(__n, (_Node*)(nullptr),
|
||||
_M_buckets.get_allocator());
|
||||
try {
|
||||
for (size_type __bucket = 0; __bucket < __old_n; ++__bucket) {
|
||||
_Node* __first = _M_buckets[__bucket];
|
||||
while (__first) {
|
||||
size_type __new_bucket = _M_bkt_num(__first->_M_val, __n);
|
||||
_M_buckets[__bucket] = __first->_M_next;
|
||||
__first->_M_next = __tmp[__new_bucket];
|
||||
__tmp[__new_bucket] = __first;
|
||||
__first = _M_buckets[__bucket];
|
||||
}
|
||||
}
|
||||
_M_buckets.swap(__tmp);
|
||||
} catch (...) {
|
||||
for (size_type __bucket = 0; __bucket < __tmp.size(); ++__bucket) {
|
||||
while (__tmp[__bucket]) {
|
||||
_Node* __next = __tmp[__bucket]->_M_next;
|
||||
_M_delete_node(__tmp[__bucket]);
|
||||
__tmp[__bucket] = __next;
|
||||
}
|
||||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
|
||||
void hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::_M_erase_bucket(
|
||||
const size_type __n, _Node* __first, _Node* __last)
|
||||
{
|
||||
_Node* __cur = _M_buckets[__n];
|
||||
if (__cur == __first)
|
||||
_M_erase_bucket(__n, __last);
|
||||
else {
|
||||
_Node* __next;
|
||||
for (__next = __cur->_M_next; __next != __first;
|
||||
__cur = __next, __next = __cur->_M_next)
|
||||
;
|
||||
while (__next != __last) {
|
||||
__cur->_M_next = __next->_M_next;
|
||||
_M_delete_node(__next);
|
||||
__next = __cur->_M_next;
|
||||
--_M_num_elements;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
|
||||
void hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::_M_erase_bucket(
|
||||
const size_type __n, _Node* __last)
|
||||
{
|
||||
_Node* __cur = _M_buckets[__n];
|
||||
while (__cur != __last) {
|
||||
_Node* __next = __cur->_M_next;
|
||||
_M_delete_node(__cur);
|
||||
__cur = __next;
|
||||
_M_buckets[__n] = __cur;
|
||||
--_M_num_elements;
|
||||
}
|
||||
}
|
||||
|
||||
template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
|
||||
void hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::clear()
|
||||
{
|
||||
for (size_type __i = 0; __i < _M_buckets.size(); ++__i) {
|
||||
_Node* __cur = _M_buckets[__i];
|
||||
while (__cur != nullptr) {
|
||||
_Node* __next = __cur->_M_next;
|
||||
_M_delete_node(__cur);
|
||||
__cur = __next;
|
||||
}
|
||||
_M_buckets[__i] = nullptr;
|
||||
}
|
||||
_M_num_elements = 0;
|
||||
}
|
||||
|
||||
template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
|
||||
void hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::_M_copy_from(
|
||||
const hashtable& __ht)
|
||||
{
|
||||
_M_buckets.clear();
|
||||
_M_buckets.reserve(__ht._M_buckets.size());
|
||||
_M_buckets.insert(_M_buckets.end(), __ht._M_buckets.size(), (_Node*)nullptr);
|
||||
try {
|
||||
for (size_type __i = 0; __i < __ht._M_buckets.size(); ++__i) {
|
||||
const _Node* __cur = __ht._M_buckets[__i];
|
||||
if (__cur) {
|
||||
_Node* __copy = _M_new_node(__cur->_M_val);
|
||||
_M_buckets[__i] = __copy;
|
||||
|
||||
for (_Node* __next = __cur->_M_next; __next;
|
||||
__cur = __next, __next = __cur->_M_next) {
|
||||
__copy->_M_next = _M_new_node(__next->_M_val);
|
||||
__copy = __copy->_M_next;
|
||||
}
|
||||
}
|
||||
}
|
||||
_M_num_elements = __ht._M_num_elements;
|
||||
} catch (...) {
|
||||
clear();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace @KWSYS_NAMESPACE@
|
||||
|
||||
// Undo warning suppression.
|
||||
# if defined(__clang__) && defined(__has_warning)
|
||||
# if __has_warning("-Wdeprecated")
|
||||
# pragma clang diagnostic pop
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# if defined(_MSC_VER)
|
||||
# pragma warning(pop)
|
||||
# endif
|
||||
|
||||
#endif
|
||||
@@ -69,40 +69,3 @@ int KWSYS_PLATFORM_TEST_C_MAIN()
|
||||
return clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TEST_KWSYS_C_TYPE_MACROS
|
||||
char* info_macros =
|
||||
# if defined(__SIZEOF_SHORT__)
|
||||
"INFO:macro[__SIZEOF_SHORT__]\n"
|
||||
# endif
|
||||
# if defined(__SIZEOF_INT__)
|
||||
"INFO:macro[__SIZEOF_INT__]\n"
|
||||
# endif
|
||||
# if defined(__SIZEOF_LONG__)
|
||||
"INFO:macro[__SIZEOF_LONG__]\n"
|
||||
# endif
|
||||
# if defined(__SIZEOF_LONG_LONG__)
|
||||
"INFO:macro[__SIZEOF_LONG_LONG__]\n"
|
||||
# endif
|
||||
# if defined(__SHORT_MAX__)
|
||||
"INFO:macro[__SHORT_MAX__]\n"
|
||||
# endif
|
||||
# if defined(__INT_MAX__)
|
||||
"INFO:macro[__INT_MAX__]\n"
|
||||
# endif
|
||||
# if defined(__LONG_MAX__)
|
||||
"INFO:macro[__LONG_MAX__]\n"
|
||||
# endif
|
||||
# if defined(__LONG_LONG_MAX__)
|
||||
"INFO:macro[__LONG_LONG_MAX__]\n"
|
||||
# endif
|
||||
"";
|
||||
|
||||
int KWSYS_PLATFORM_TEST_C_MAIN_ARGS(argc, argv)
|
||||
{
|
||||
int require = 0;
|
||||
require += info_macros[argc];
|
||||
(void)argv;
|
||||
return require;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,36 +1,5 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
|
||||
#ifdef TEST_KWSYS_CXX_HAS_CSTDIO
|
||||
# include <cstdio>
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TEST_KWSYS_CXX_HAS_LONG_LONG
|
||||
long long f(long long n)
|
||||
{
|
||||
return n;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
long long n = 0;
|
||||
return static_cast<int>(f(n));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TEST_KWSYS_CXX_HAS___INT64
|
||||
__int64 f(__int64 n)
|
||||
{
|
||||
return n;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
__int64 n = 0;
|
||||
return static_cast<int>(f(n));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TEST_KWSYS_CXX_STAT_HAS_ST_MTIM
|
||||
# include <sys/types.h>
|
||||
@@ -60,82 +29,6 @@ int main()
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TEST_KWSYS_CXX_SAME_LONG_AND___INT64
|
||||
void function(long**)
|
||||
{
|
||||
}
|
||||
int main()
|
||||
{
|
||||
__int64** p = 0;
|
||||
function(p);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TEST_KWSYS_CXX_SAME_LONG_LONG_AND___INT64
|
||||
void function(long long**)
|
||||
{
|
||||
}
|
||||
int main()
|
||||
{
|
||||
__int64** p = 0;
|
||||
function(p);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TEST_KWSYS_IOS_HAS_ISTREAM_LONG_LONG
|
||||
# include <iostream>
|
||||
int test_istream(std::istream& is, long long& x)
|
||||
{
|
||||
return (is >> x) ? 1 : 0;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
long long x = 0;
|
||||
return test_istream(std::cin, x);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TEST_KWSYS_IOS_HAS_OSTREAM_LONG_LONG
|
||||
# include <iostream>
|
||||
int test_ostream(std::ostream& os, long long x)
|
||||
{
|
||||
return (os << x) ? 1 : 0;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
long long x = 0;
|
||||
return test_ostream(std::cout, x);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TEST_KWSYS_IOS_HAS_ISTREAM___INT64
|
||||
# include <iostream>
|
||||
int test_istream(std::istream& is, __int64& x)
|
||||
{
|
||||
return (is >> x) ? 1 : 0;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
__int64 x = 0;
|
||||
return test_istream(std::cin, x);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TEST_KWSYS_IOS_HAS_OSTREAM___INT64
|
||||
# include <iostream>
|
||||
int test_ostream(std::ostream& os, __int64 x)
|
||||
{
|
||||
return (os << x) ? 1 : 0;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
__int64 x = 0;
|
||||
return test_ostream(std::cout, x);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TEST_KWSYS_CXX_HAS_SETENV
|
||||
# include <stdlib.h>
|
||||
int main()
|
||||
@@ -184,33 +77,6 @@ int main()
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TEST_KWSYS_CXX_HAS_ATOLL
|
||||
# include <stdlib.h>
|
||||
int main()
|
||||
{
|
||||
const char* str = "1024";
|
||||
return static_cast<int>(atoll(str));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TEST_KWSYS_CXX_HAS_ATOL
|
||||
# include <stdlib.h>
|
||||
int main()
|
||||
{
|
||||
const char* str = "1024";
|
||||
return static_cast<int>(atol(str));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TEST_KWSYS_CXX_HAS__ATOI64
|
||||
# include <stdlib.h>
|
||||
int main()
|
||||
{
|
||||
const char* str = "1024";
|
||||
return static_cast<int>(_atoi64(str));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TEST_KWSYS_CXX_HAS_UTIMES
|
||||
# include <sys/time.h>
|
||||
int main()
|
||||
@@ -288,33 +154,6 @@ int main()
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TEST_KWSYS_CXX_HAS_BORLAND_ASM
|
||||
int main()
|
||||
{
|
||||
int a = 1;
|
||||
__asm {
|
||||
xor EBX, EBX;
|
||||
mov a, EBX;
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TEST_KWSYS_CXX_HAS_BORLAND_ASM_CPUID
|
||||
int main()
|
||||
{
|
||||
int a = 0;
|
||||
__asm {
|
||||
xor EAX, EAX;
|
||||
cpuid;
|
||||
mov a, EAX;
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TEST_KWSYS_STL_HAS_WSTRING
|
||||
# include <string>
|
||||
void f(std::wstring*)
|
||||
|
||||
@@ -8,9 +8,6 @@
|
||||
|
||||
#include KWSYS_HEADER(FStream.hxx)
|
||||
#include <cstring>
|
||||
#ifdef __BORLANDC__
|
||||
# include <mem.h> /* memcmp */
|
||||
#endif
|
||||
|
||||
// Work-around CMake dependency scanning limitation. This must
|
||||
// duplicate the above list of headers.
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
|
||||
#include "kwsysPrivate.h"
|
||||
#include KWSYS_HEADER(hash_map.hxx)
|
||||
#include KWSYS_HEADER(hash_set.hxx)
|
||||
|
||||
// Work-around CMake dependency scanning limitation. This must
|
||||
// duplicate the above list of headers.
|
||||
#if 0
|
||||
# include "hash_map.hxx.in"
|
||||
# include "hash_set.hxx.in"
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# pragma warning(disable : 4786)
|
||||
#endif
|
||||
|
||||
#if defined(__sgi) && !defined(__GNUC__)
|
||||
# pragma set woff 1468 /* inline function cannot be explicitly instantiated \
|
||||
*/
|
||||
#endif
|
||||
|
||||
template class kwsys::hash_map<const char*, int>;
|
||||
template class kwsys::hash_set<int>;
|
||||
|
||||
static bool test_hash_map()
|
||||
{
|
||||
using mtype = kwsys::hash_map<const char*, int>;
|
||||
mtype m;
|
||||
const char* keys[] = { "hello", "world" };
|
||||
m[keys[0]] = 1;
|
||||
m.insert(mtype::value_type(keys[1], 2));
|
||||
int sum = 0;
|
||||
for (auto& mi : m) {
|
||||
std::cout << "Found entry [" << mi.first << "," << mi.second << "]"
|
||||
<< std::endl;
|
||||
sum += mi.second;
|
||||
}
|
||||
return sum == 3;
|
||||
}
|
||||
|
||||
static bool test_hash_set()
|
||||
{
|
||||
using stype = kwsys::hash_set<int>;
|
||||
stype s;
|
||||
s.insert(1);
|
||||
s.insert(2);
|
||||
int sum = 0;
|
||||
for (int si : s) {
|
||||
std::cout << "Found entry [" << si << "]" << std::endl;
|
||||
sum += si;
|
||||
}
|
||||
return sum == 3;
|
||||
}
|
||||
|
||||
int testHashSTL(int, char* [])
|
||||
{
|
||||
bool result = true;
|
||||
result = test_hash_map() && result;
|
||||
result = test_hash_set() && result;
|
||||
return result ? 0 : 1;
|
||||
}
|
||||
@@ -24,10 +24,6 @@
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if defined(__BORLANDC__)
|
||||
# pragma warn - 8060 /* possibly incorrect assignment */
|
||||
#endif
|
||||
|
||||
/* Platform-specific sleep functions. */
|
||||
|
||||
#if defined(__BEOS__) && !defined(__ZETA__)
|
||||
|
||||
@@ -11,29 +11,13 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#if defined(KWSYS_USE_LONG_LONG)
|
||||
# if defined(KWSYS_IOS_HAS_OSTREAM_LONG_LONG)
|
||||
# define iostreamLongLong(x) (x)
|
||||
# else
|
||||
# define iostreamLongLong(x) ((long)x)
|
||||
# endif
|
||||
#elif defined(KWSYS_USE___INT64)
|
||||
# if defined(KWSYS_IOS_HAS_OSTREAM___INT64)
|
||||
# define iostreamLongLong(x) (x)
|
||||
# else
|
||||
# define iostreamLongLong(x) ((long)x)
|
||||
# endif
|
||||
#else
|
||||
# error "No Long Long"
|
||||
#endif
|
||||
|
||||
#define printMethod(info, m) std::cout << #m << ": " << info.m() << "\n"
|
||||
|
||||
#define printMethod2(info, m, unit) \
|
||||
std::cout << #m << ": " << info.m() << " " << unit << "\n"
|
||||
|
||||
#define printMethod3(info, m, unit) \
|
||||
std::cout << #m << ": " << iostreamLongLong(info.m) << " " << unit << "\n"
|
||||
std::cout << #m << ": " << info.m << " " << unit << "\n"
|
||||
|
||||
int testSystemInformation(int, char* [])
|
||||
{
|
||||
|
||||
@@ -25,13 +25,13 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#if defined(_WIN32) && !defined(__CYGWIN__)
|
||||
# include <io.h> /* _umask (MSVC) / umask (Borland) */
|
||||
# include <io.h> /* _umask (MSVC) */
|
||||
# ifdef _MSC_VER
|
||||
# define umask _umask // Note this is still umask on Borland
|
||||
# define umask _umask
|
||||
# endif
|
||||
#endif
|
||||
#include <sys/stat.h> /* umask (POSIX), _S_I* constants (Windows) */
|
||||
// Visual C++ does not define mode_t (note that Borland does, however).
|
||||
// Visual C++ does not define mode_t.
|
||||
#if defined(_MSC_VER)
|
||||
typedef unsigned short mode_t;
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user