1
0
mirror of https://git.suyu.dev/suyu/suyu synced 2025-09-16 11:07:58 -05:00

Initial commit

This commit is contained in:
Crimson-Hawk
2024-03-05 16:42:40 +08:00
commit f1e4595ebf
39576 changed files with 7006612 additions and 0 deletions

View File

View File

View File

@@ -0,0 +1,23 @@
# Use, modification, and distribution are
# subject to the Boost Software License, Version 1.0. (See accompanying
# file LICENSE.txt)
#
# Copyright Rene Rivera 2020.
# For Drone CI we use the Starlark scripting language to reduce duplication.
# As the yaml syntax for Drone CI is rather limited.
#
#
globalenv={}
linuxglobalimage="cppalliance/droneubuntu1604:1"
windowsglobalimage="cppalliance/dronevs2019"
def main(ctx):
return [
linux_cxx("TOOLSET=gcc CXXSTD=03,11 Job 0", "g++", packages="", buildtype="boost", buildscript="drone", image=linuxglobalimage, environment={'TOOLSET': 'gcc', 'CXXSTD': '03,11', 'DRONE_JOB_UUID': 'b6589fc6ab'}, globalenv=globalenv),
linux_cxx("TOOLSET=clang CXXSTD=03,11,14,1z Job 1", "clang++", packages="libstdc++-4.9-dev", buildtype="boost", buildscript="drone", image=linuxglobalimage, environment={'TOOLSET': 'clang', 'CXXSTD': '03,11,14,1z', 'DRONE_JOB_UUID': '356a192b79'}, globalenv=globalenv),
osx_cxx("TOOLSET=clang CXXSTD=03,11,14,1z Job 2", "clang++", packages="", buildtype="boost", buildscript="drone", environment={'TOOLSET': 'clang', 'CXXSTD': '03,11,14,1z', 'DRONE_JOB_UUID': 'da4b9237ba'}, globalenv=globalenv),
]
# from https://github.com/boostorg/boost-ci
load("@boost_ci//ci/drone/:functions.star", "linux_cxx","windows_cxx","osx_cxx","freebsd_cxx")

View File

@@ -0,0 +1,36 @@
#!/bin/bash
# Copyright 2020 Rene Rivera, Sam Darwin
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.txt or copy at http://boost.org/LICENSE_1_0.txt)
set -e
export TRAVIS_BUILD_DIR=$(pwd)
export DRONE_BUILD_DIR=$(pwd)
export TRAVIS_BRANCH=$DRONE_BRANCH
export VCS_COMMIT_ID=$DRONE_COMMIT
export GIT_COMMIT=$DRONE_COMMIT
export REPO_NAME=$DRONE_REPO
export PATH=~/.local/bin:/usr/local/bin:$PATH
if [ "$DRONE_JOB_BUILDTYPE" == "boost" ]; then
echo '==================================> INSTALL'
BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true
cd ..
git clone -b $BOOST_BRANCH https://github.com/boostorg/boost.git boost-root
cd boost-root
git submodule update --init tools/build
git submodule update --init libs/config
git submodule update --init tools/boostdep
cp -r $TRAVIS_BUILD_DIR/* libs/intrusive
python tools/boostdep/depinst/depinst.py intrusive
./bootstrap.sh
./b2 headers
echo '==================================> SCRIPT'
./b2 libs/intrusive/test toolset=$TOOLSET cxxstd=$CXXSTD
fi

View File

@@ -0,0 +1,96 @@
* text=auto !eol svneol=native#text/plain
*.gitattributes text svneol=native#text/plain
# Scriptish formats
*.bat text svneol=native#text/plain
*.bsh text svneol=native#text/x-beanshell
*.cgi text svneol=native#text/plain
*.cmd text svneol=native#text/plain
*.js text svneol=native#text/javascript
*.php text svneol=native#text/x-php
*.pl text svneol=native#text/x-perl
*.pm text svneol=native#text/x-perl
*.py text svneol=native#text/x-python
*.sh eol=lf svneol=LF#text/x-sh
configure eol=lf svneol=LF#text/x-sh
# Image formats
*.bmp binary svneol=unset#image/bmp
*.gif binary svneol=unset#image/gif
*.ico binary svneol=unset#image/ico
*.jpeg binary svneol=unset#image/jpeg
*.jpg binary svneol=unset#image/jpeg
*.png binary svneol=unset#image/png
*.tif binary svneol=unset#image/tiff
*.tiff binary svneol=unset#image/tiff
*.svg text svneol=native#image/svg%2Bxml
# Data formats
*.pdf binary svneol=unset#application/pdf
*.avi binary svneol=unset#video/avi
*.doc binary svneol=unset#application/msword
*.dsp text svneol=crlf#text/plain
*.dsw text svneol=crlf#text/plain
*.eps binary svneol=unset#application/postscript
*.gz binary svneol=unset#application/gzip
*.mov binary svneol=unset#video/quicktime
*.mp3 binary svneol=unset#audio/mpeg
*.ppt binary svneol=unset#application/vnd.ms-powerpoint
*.ps binary svneol=unset#application/postscript
*.psd binary svneol=unset#application/photoshop
*.rdf binary svneol=unset#text/rdf
*.rss text svneol=unset#text/xml
*.rtf binary svneol=unset#text/rtf
*.sln text svneol=native#text/plain
*.swf binary svneol=unset#application/x-shockwave-flash
*.tgz binary svneol=unset#application/gzip
*.vcproj text svneol=native#text/xml
*.vcxproj text svneol=native#text/xml
*.vsprops text svneol=native#text/xml
*.wav binary svneol=unset#audio/wav
*.xls binary svneol=unset#application/vnd.ms-excel
*.zip binary svneol=unset#application/zip
# Text formats
.htaccess text svneol=native#text/plain
*.bbk text svneol=native#text/xml
*.cmake text svneol=native#text/plain
*.css text svneol=native#text/css
*.dtd text svneol=native#text/xml
*.htm text svneol=native#text/html
*.html text svneol=native#text/html
*.ini text svneol=native#text/plain
*.log text svneol=native#text/plain
*.mak text svneol=native#text/plain
*.qbk text svneol=native#text/plain
*.rst text svneol=native#text/plain
*.sql text svneol=native#text/x-sql
*.txt text svneol=native#text/plain
*.xhtml text svneol=native#text/xhtml%2Bxml
*.xml text svneol=native#text/xml
*.xsd text svneol=native#text/xml
*.xsl text svneol=native#text/xml
*.xslt text svneol=native#text/xml
*.xul text svneol=native#text/xul
*.yml text svneol=native#text/plain
boost-no-inspect text svneol=native#text/plain
CHANGES text svneol=native#text/plain
COPYING text svneol=native#text/plain
INSTALL text svneol=native#text/plain
Jamfile text svneol=native#text/plain
Jamroot text svneol=native#text/plain
Jamfile.v2 text svneol=native#text/plain
Jamrules text svneol=native#text/plain
Makefile* text svneol=native#text/plain
README text svneol=native#text/plain
TODO text svneol=native#text/plain
# Code formats
*.c text svneol=native#text/plain
*.cpp text svneol=native#text/plain
*.h text svneol=native#text/plain
*.hpp text svneol=native#text/plain
*.ipp text svneol=native#text/plain
*.tpp text svneol=native#text/plain
*.jam text svneol=native#text/plain
*.java text svneol=native#text/plain

View File

@@ -0,0 +1,198 @@
name: CI
on:
pull_request:
push:
branches:
- master
- develop
- feature/**
env:
UBSAN_OPTIONS: print_stacktrace=1
jobs:
posix:
strategy:
fail-fast: false
matrix:
include:
- toolset: gcc-4.8
cxxstd: "03,11"
os: ubuntu-18.04
install: g++-4.8
- toolset: gcc-5
cxxstd: "03,11,14,1z"
os: ubuntu-18.04
install: g++-5
- toolset: gcc-6
cxxstd: "03,11,14,1z"
os: ubuntu-18.04
install: g++-6
- toolset: gcc-7
cxxstd: "03,11,14,17"
os: ubuntu-18.04
- toolset: gcc-8
cxxstd: "03,11,14,17,2a"
os: ubuntu-18.04
install: g++-8
- toolset: gcc-9
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
- toolset: gcc-10
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: g++-10
- toolset: gcc-11
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: g++-11
- toolset: clang
compiler: clang++-3.9
cxxstd: "03,11,14"
os: ubuntu-18.04
install: clang-3.9
- toolset: clang
compiler: clang++-4.0
cxxstd: "03,11,14"
os: ubuntu-18.04
install: clang-4.0
- toolset: clang
compiler: clang++-5.0
cxxstd: "03,11,14,1z"
os: ubuntu-18.04
install: clang-5.0
- toolset: clang
compiler: clang++-6.0
cxxstd: "03,11,14,17"
os: ubuntu-18.04
install: clang-6.0
- toolset: clang
compiler: clang++-7
cxxstd: "03,11,14,17"
os: ubuntu-18.04
install: clang-7
- toolset: clang
compiler: clang++-8
cxxstd: "03,11,14,17"
os: ubuntu-20.04
install: clang-8
- toolset: clang
compiler: clang++-9
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: clang-9
- toolset: clang
compiler: clang++-10
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: clang-10
- toolset: clang
compiler: clang++-11
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: clang-11
- toolset: clang
compiler: clang++-12
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: clang-12
- toolset: clang
cxxstd: "03,11,14,17,2a"
os: macos-10.15
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- name: Install packages
if: matrix.install
run: sudo apt install ${{matrix.install}}
- name: Setup Boost
run: |
echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY
LIBRARY=${GITHUB_REPOSITORY#*/}
echo LIBRARY: $LIBRARY
echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV
echo GITHUB_BASE_REF: $GITHUB_BASE_REF
echo GITHUB_REF: $GITHUB_REF
REF=${GITHUB_BASE_REF:-$GITHUB_REF}
REF=${REF#refs/heads/}
echo REF: $REF
BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true
echo BOOST_BRANCH: $BOOST_BRANCH
cd ..
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
./bootstrap.sh
./b2 -d0 headers
- name: Create user-config.jam
if: matrix.compiler
run: |
echo "using ${{matrix.toolset}} : : ${{matrix.compiler}} ;" > ~/user-config.jam
- name: Run tests
run: |
cd ../boost-root
./b2 -j3 libs/$LIBRARY/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} variant=debug,release
windows:
strategy:
fail-fast: false
matrix:
include:
- toolset: msvc-14.1
cxxstd: "14,17,latest"
addrmd: 32,64
os: windows-2016
- toolset: msvc-14.2
cxxstd: "14,17,latest"
addrmd: 32,64
os: windows-2019
- toolset: msvc-14.3
cxxstd: "14,17,latest"
addrmd: 32,64
os: windows-2022
- toolset: gcc
cxxstd: "03,11,14,17,2a"
addrmd: 64
os: windows-2019
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- name: Setup Boost
shell: cmd
run: |
echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY%
for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi
echo LIBRARY: %LIBRARY%
echo LIBRARY=%LIBRARY%>>%GITHUB_ENV%
echo GITHUB_BASE_REF: %GITHUB_BASE_REF%
echo GITHUB_REF: %GITHUB_REF%
if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF%
set BOOST_BRANCH=develop
for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master
echo BOOST_BRANCH: %BOOST_BRANCH%
cd ..
git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY%
cmd /c bootstrap
b2 -d0 headers
- name: Run tests
shell: cmd
run: |
cd ../boost-root
b2 -j3 libs/%LIBRARY%/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} address-model=${{matrix.addrmd}} variant=debug,release

View File

@@ -0,0 +1,63 @@
# Copyright 2016, 2017 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
language: cpp
sudo: false
python: "2.7"
branches:
only:
- master
- develop
- /feature\/.*/
env:
matrix:
- BOGUS_JOB=true
matrix:
exclude:
- env: BOGUS_JOB=true
include:
- os: linux
compiler: g++
env: TOOLSET=gcc CXXSTD=03,11
- os: linux
compiler: clang++
env: TOOLSET=clang CXXSTD=03,11,14,1z
addons:
apt:
packages:
- libstdc++-4.9-dev
sources:
- ubuntu-toolchain-r-test
- os: osx
compiler: clang++
env: TOOLSET=clang CXXSTD=03,11,14,1z
install:
- BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true
- cd ..
- git clone -b $BOOST_BRANCH https://github.com/boostorg/boost.git boost-root
- cd boost-root
- git submodule update --init tools/build
- git submodule update --init libs/config
- git submodule update --init tools/boostdep
- cp -r $TRAVIS_BUILD_DIR/* libs/intrusive
- python tools/boostdep/depinst/depinst.py intrusive
- ./bootstrap.sh
- ./b2 headers
script:
- ./b2 libs/intrusive/test toolset=$TOOLSET cxxstd=$CXXSTD
notifications:
email:
on_success: always

View File

@@ -0,0 +1,22 @@
# Copyright 2019 Mike Dev
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
cmake_minimum_required( VERSION 3.5...3.20 )
project( boost_intrusive VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX )
add_library( boost_intrusive INTERFACE )
add_library( Boost::intrusive ALIAS boost_intrusive )
target_include_directories( boost_intrusive INTERFACE include )
target_link_libraries( boost_intrusive
INTERFACE
Boost::assert
Boost::config
Boost::container_hash
Boost::core
Boost::move
Boost::static_assert
)

View File

@@ -0,0 +1,11 @@
# Boost.Intrusive Library Jamfile
#
# Copyright (c) 2018 Ion Gaztanaga
#
# Use, modification, and distribution are subject to the
# Boost Software License, Version 1.0. (See accompanying file
# LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
# please order by name to ease maintenance
build-project example ;
build-project test ;

View File

@@ -0,0 +1,40 @@
Boost.Intrusive
==========
Boost.Intrusive, part of collection of the [Boost C++ Libraries](http://github.com/boostorg), is a library presenting intrusive containers to the world of C++. Intrusive containers are special containers that offer better performance and exception safety guarantees than non-intrusive containers (like STL containers). The performance benefits of intrusive containers makes them ideal as a building block to efficiently construct complex data structures like multi-index containers or to design high performance code like memory allocation algorithms.
While intrusive containers were and are widely used in C, they became more and more forgotten in C++ due to the presence of the standard containers which don't support intrusive techniques.Boost.Intrusive wants to push intrusive containers usage encapsulating the implementation in STL-like interfaces. Hence anyone familiar with standard containers can easily use Boost.Intrusive.
### License
Distributed under the [Boost Software License, Version 1.0](http://www.boost.org/LICENSE_1_0.txt).
### Properties
* C++03
* Header-Only
### Build Status
Branch | Travis | Appveyor | Coverity Scan | codecov.io | Deps | Docs | Tests |
:-------------: | ------ | -------- | ------------- | ---------- | ---- | ---- | ----- |
[`master`](https://github.com/boostorg/intrusive/tree/master) | [![Build Status](https://travis-ci.org/boostorg/intrusive.svg?branch=master)](https://travis-ci.org/boostorg/intrusive) | [![Build status](https://ci.appveyor.com/api/projects/status/9ckrveolxsonxfnb/branch/master?svg=true)](https://ci.appveyor.com/project/jeking3/intrusive-0k1xg/branch/master) | [![Coverity Scan Build Status](https://scan.coverity.com/projects/16048/badge.svg)](https://scan.coverity.com/projects/boostorg-intrusive) | [![codecov](https://codecov.io/gh/boostorg/intrusive/branch/master/graph/badge.svg)](https://codecov.io/gh/boostorg/intrusive/branch/master)| [![Deps](https://img.shields.io/badge/deps-master-brightgreen.svg)](https://pdimov.github.io/boostdep-report/master/intrusive.html) | [![Documentation](https://img.shields.io/badge/docs-master-brightgreen.svg)](http://www.boost.org/doc/libs/master/doc/html/intrusive.html) | [![Enter the Matrix](https://img.shields.io/badge/matrix-master-brightgreen.svg)](http://www.boost.org/development/tests/master/developer/intrusive.html)
[`develop`](https://github.com/boostorg/intrusive/tree/develop) | [![Build Status](https://travis-ci.org/boostorg/intrusive.svg?branch=develop)](https://travis-ci.org/boostorg/intrusive) | [![Build status](https://ci.appveyor.com/api/projects/status/9ckrveolxsonxfnb/branch/develop?svg=true)](https://ci.appveyor.com/project/jeking3/intrusive-0k1xg/branch/develop) | [![Coverity Scan Build Status](https://scan.coverity.com/projects/16048/badge.svg)](https://scan.coverity.com/projects/boostorg-intrusive) | [![codecov](https://codecov.io/gh/boostorg/intrusive/branch/develop/graph/badge.svg)](https://codecov.io/gh/boostorg/intrusive/branch/develop) | [![Deps](https://img.shields.io/badge/deps-develop-brightgreen.svg)](https://pdimov.github.io/boostdep-report/develop/intrusive.html) | [![Documentation](https://img.shields.io/badge/docs-develop-brightgreen.svg)](http://www.boost.org/doc/libs/develop/doc/html/intrusive.html) | [![Enter the Matrix](https://img.shields.io/badge/matrix-develop-brightgreen.svg)](http://www.boost.org/development/tests/develop/developer/intrusive.html)
### Directories
| Name | Purpose |
| ----------- | ------------------------------ |
| `doc` | documentation |
| `example` | examples |
| `include` | headers |
| `proj` | ide projects |
| `test` | unit tests |
### More information
* [Ask questions](http://stackoverflow.com/questions/ask?tags=c%2B%2B,boost,boost-intrusive)
* [Report bugs](https://github.com/boostorg/intrusive/issues): Be sure to mention Boost version, platform and compiler you're using. A small compilable code sample to reproduce the problem is always good as well.
* Submit your patches as pull requests against **develop** branch. Note that by submitting patches you agree to license your modifications under the [Boost Software License, Version 1.0](http://www.boost.org/LICENSE_1_0.txt).
* Discussions about the library are held on the [Boost developers mailing list](http://www.boost.org/community/groups.html#main). Be sure to read the [discussion policy](http://www.boost.org/community/policy.html) before posting and add the `[intrusive]` tag at the beginning of the subject line.

View File

@@ -0,0 +1,125 @@
# Boost.Intrusive library documentation Jamfile
#
# Copyright Ion Gaztanaga 2006.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
# See http://www.boost.org/libs/intrusive for documentation.
using auto-index ;
import doxygen ;
import quickbook ;
path-constant here : . ;
doxygen autodoc
:
[ glob ../../../boost/intrusive/*.hpp ]
:
<doxygen:param>HIDE_UNDOC_MEMBERS=YES
<doxygen:param>HIDE_UNDOC_MEMBERS=YES
<doxygen:param>HIDE_UNDOC_CLASSES=YES
<doxygen:param>EXTRACT_PRIVATE=NO
<doxygen:param>ENABLE_PREPROCESSING=YES
<doxygen:param>MACRO_EXPANSION=YES
<doxygen:param>"PREDEFINED=\"BOOST_INTRUSIVE_DOXYGEN_INVOKED\" \\
\"BOOST_INTRUSIVE_IMPDEF(T)=implementation_defined\" \\
\"BOOST_INTRUSIVE_SEEDOC(T)=see_documentation\" \\
\"BOOST_INTRUSIVE_DOC1ST(T1,T2)=T1\" \\
\"BOOST_INTRUSIVE_DOCIGN(T)=\" \\
\"BOOST_INTRUSIVE_I(T)=,\" \\
\"BOOST_RV_REF(T)=T &&\" \\
\"BOOST_RV_REF_BEG=\" \\
\"BOOST_RV_REF_END=&&\" \\
\"BOOST_NOEXCEPT_OR_NOTHROW=noexcept\" \\
\"BOOST_NOEXCEPT_IF(T)=noexcept(T)\" \\
\"BOOST_NOEXCEPT=noexcept\" \\
\"BOOST_INTRUSIVE_FORCEINLINE=inline\" \\
\"list_impl=list\" \\
\"slist_impl=slist\" \\
\"bstree_impl=bstree\" \\
\"bs_set_impl=bs_set\" \\
\"bs_multiset_impl=bs_multiset\" \\
\"rbtree_impl=rbtree\" \\
\"set_impl=set\" \\
\"multiset_impl=multiset\" \\
\"unordered_set_impl=unordered_set\" \\
\"unordered_multiset_impl=unordered_multiset\" \\
\"hashtable_impl=hashtable\" \\
\"splay_set_impl=splay_set\" \\
\"splay_multiset_impl=splay_multiset\" \\
\"splaytree_impl=splaytree\" \\
\"sg_set_impl=sg_set\" \\
\"sg_multiset_impl=sg_multiset\" \\
\"sgtree_impl=sgtree\" \\
\"avl_set_impl=avl_set\" \\
\"avl_multiset_impl=avl_multiset\" \\
\"avltree_impl=avltree\" \\
\"treap_set_impl=treap_set\" \\
\"treap_multiset_impl=treap_multiset\" \\
\"treap_impl=treap\" \\
\"BOOST_INTRUSIVE_OPTION_CONSTANT(OPTION_NAME, TYPE, VALUE, CONSTANT_NAME) = template<TYPE VALUE> struct OPTION_NAME{};\" \\
\"BOOST_INTRUSIVE_OPTION_TYPE(OPTION_NAME, TYPE, TYPEDEF_EXPR, TYPEDEF_NAME) = template<class TYPE> struct OPTION_NAME{};\" "
;
xml intrusive : intrusive.qbk
:
<include>../../../tools/auto_index/include
;
boostbook standalone
:
intrusive
:
<format>html:<xsl:param>boost.root=../../../..
<format>html:<xsl:param>boost.libraries=../../../../libs/libraries.htm
<xsl:param>generate.section.toc.level=3
<xsl:param>chunk.first.sections=1
<dependency>autodoc
# Build requirements go here:
# <auto-index>on (or off) one turns on (or off) indexing:
<auto-index>on
# Turns on (or off) auto-index-verbose for diagnostic info.
# This is highly recommended until you have got all the many details correct!
<auto-index-verbose>on
# Choose the indexing method (separately for html and PDF) - see manual.
# Choose indexing method for PDFs:
<format>pdf:<auto-index-internal>off
# Choose indexing method for html:
<format>html:<auto-index-internal>on
<format>docbook:<auto-index-internal>on
# Set the name of the script file to use (index.idx is popular):
<auto-index-script>$(here)/index.idx
# Commands in the script file should all use RELATIVE PATHS
# otherwise the script will not be portable to other machines.
# Relative paths are normally taken as relative to the location
# of the script file, but we can add a prefix to all
# those relative paths using the <auto-index-prefix> feature.
# The path specified by <auto-index-prefix> may be either relative or
# absolute, for example the following will get us up to the boost root
# directory for most Boost libraries:
<auto-index-prefix>"$(here)/../../.."
;
install pdfinstall : standalone/<format>pdf : <name>intrusive.pdf <location>. <install-type>PDF <format>pdf ;
explicit pdfinstall ;
###############################################################################
alias boostdoc
: standalone/<format>docbook
:
:
: ;
explicit boostdoc ;
alias boostrelease ;
explicit boostrelease ;

View File

@@ -0,0 +1 @@
!scan-path "boost/intrusive" ".*.hpp" false

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,39 @@
# Boost Intrusive Library Example Jamfile
# (C) Copyright Ion Gaztanaga 2006-2013.
# Use, modification and distribution are subject to the
# Boost Software License, Version 1.0. (See accompanying file
# LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
# Adapted from John Maddock's TR1 Jamfile.v2
# Copyright John Maddock 2005.
# Use, modification and distribution are subject to the
# Boost Software License, Version 1.0. (See accompanying file
# LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
# this rule enumerates through all the sources and invokes
# the run rule for each source, the result is a list of all
# the run rules, which we can pass on to the test_suite rule:
rule test_all
{
local all_rules = ;
for local fileb in [ glob *.cpp ]
{
all_rules += [ run $(fileb)
: # additional args
: # test-files
: # requirements
<toolset>acc:<linkflags>-lrt
<toolset>acc-pa_risc:<linkflags>-lrt
<toolset>gcc,<target-os>windows:<linkflags>"-lole32 -loleaut32"
<host-os>hpux,<toolset>gcc:<linkflags>"-Wl,+as,mpas"
<host-os>windows,<toolset>clang:<linkflags>"-lole32 -loleaut32 -lpsapi -ladvapi32"
] ;
}
return $(all_rules) ;
}
test-suite intrusive_example : [ test_all r ] : <threading>multi ;

View File

@@ -0,0 +1,105 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_advanced_value_traits_code
#include <boost/intrusive/link_mode.hpp>
#include <boost/intrusive/list.hpp>
#include <vector>
//This is the node that will be used with algorithms.
struct simple_node
{
simple_node *prev_;
simple_node *next_;
};
//]
//[doc_advanced_value_traits_value_traits
class base_1{};
class base_2{};
struct value_1 : public base_1, public simple_node
{ int id_; };
struct value_2 : public base_1, public base_2, public simple_node
{ float id_; };
//Define the node traits. A single node_traits will be enough.
struct simple_node_traits
{
typedef simple_node node;
typedef node * node_ptr;
typedef const node * const_node_ptr;
static node *get_next(const node *n) { return n->next_; }
static void set_next(node *n, node *next) { n->next_ = next; }
static node *get_previous(const node *n) { return n->prev_; }
static void set_previous(node *n, node *prev) { n->prev_ = prev; }
};
//A templatized value traits for value_1 and value_2
template<class ValueType>
struct simple_value_traits
{
typedef simple_node_traits node_traits;
typedef node_traits::node_ptr node_ptr;
typedef node_traits::const_node_ptr const_node_ptr;
typedef ValueType value_type;
typedef ValueType * pointer;
typedef const ValueType * const_pointer;
static const boost::intrusive::link_mode_type link_mode = boost::intrusive::normal_link;
static node_ptr to_node_ptr (value_type &value) { return node_ptr(&value); }
static const_node_ptr to_node_ptr (const value_type &value) { return const_node_ptr(&value); }
static pointer to_value_ptr(node_ptr n) { return static_cast<value_type*>(n); }
static const_pointer to_value_ptr(const_node_ptr n) { return static_cast<const value_type*>(n); }
};
//]
//[doc_advanced_value_traits_containers
//Now define two intrusive lists. Both lists will use the same algorithms:
// circular_list_algorithms<simple_node_traits>
using namespace boost::intrusive;
typedef list <value_1, value_traits<simple_value_traits<value_1> > > Value1List;
typedef list <value_2, value_traits<simple_value_traits<value_2> > > Value2List;
//]
//[doc_advanced_value_traits_test
int main()
{
typedef std::vector<value_1> Vect1;
typedef std::vector<value_2> Vect2;
//Create values, with a different internal number
Vect1 values1;
Vect2 values2;
for(int i = 0; i < 100; ++i){
value_1 v1; v1.id_ = i; values1.push_back(v1);
value_2 v2; v2.id_ = (float)i; values2.push_back(v2);
}
//Create the lists with the objects
Value1List list1(values1.begin(), values1.end());
Value2List list2(values2.begin(), values2.end());
//Now test both lists
Value1List::const_iterator bit1(list1.begin()), bitend1(list1.end());
Value2List::const_iterator bit2(list2.begin()), bitend2(list2.end());
Vect1::const_iterator it1(values1.begin()), itend1(values1.end());
Vect2::const_iterator it2(values2.begin()), itend2(values2.end());
//Test the objects inserted in our lists
for(; it1 != itend1; ++it1, ++bit1, ++it2, ++bit2){
if(&*bit1 != &*it1 || &*bit2 != &*it2) return 1;
}
return 0;
}
//]

View File

@@ -0,0 +1,65 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2008-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_any_hook
#include <vector>
#include <boost/intrusive/any_hook.hpp>
#include <boost/intrusive/slist.hpp>
#include <boost/intrusive/list.hpp>
using namespace boost::intrusive;
class MyClass : public any_base_hook<> //Base hook
{
int int_;
public:
any_member_hook<> member_hook_; //Member hook
MyClass(int i = 0) : int_(i)
{}
//<-
int get_int() const { return int_; }
//->
};
int main()
{
//Define a base hook option that converts any_base_hook to a slist hook
typedef any_to_slist_hook < base_hook< any_base_hook<> > > BaseSlistOption;
typedef slist<MyClass, BaseSlistOption> BaseSList;
//Define a member hook option that converts any_member_hook to a list hook
typedef any_to_list_hook< member_hook
< MyClass, any_member_hook<>, &MyClass::member_hook_> > MemberListOption;
typedef list<MyClass, MemberListOption> MemberList;
//Create several MyClass objects, each one with a different value
std::vector<MyClass> values;
for(int i = 0; i < 100; ++i){ values.push_back(MyClass(i)); }
BaseSList base_slist; MemberList member_list;
//Now insert them in reverse order in the slist and in order in the list
for(std::vector<MyClass>::iterator it(values.begin()), itend(values.end()); it != itend; ++it)
base_slist.push_front(*it), member_list.push_back(*it);
//Now test lists
BaseSList::iterator bit(base_slist.begin());
MemberList::reverse_iterator mrit(member_list.rbegin());
std::vector<MyClass>::reverse_iterator rit(values.rbegin()), ritend(values.rend());
//Test the objects inserted in the base hook list
for(; rit != ritend; ++rit, ++bit, ++mrit)
if(&*bit != &*rit || &*mrit != &*rit) return 1;
return 0;
}
//]

View File

@@ -0,0 +1,260 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_assoc_optimized_code_normal_find
#include <boost/intrusive/set.hpp>
#include <boost/intrusive/unordered_set.hpp>
#include <cstring>
using namespace boost::intrusive;
// Hash function for strings
struct StrHasher
{
std::size_t operator()(const char *str) const
{
std::size_t seed = 0;
for(; *str; ++str) boost::hash_combine(seed, *str);
return seed;
}
};
class Expensive : public set_base_hook<>, public unordered_set_base_hook<>
{
std::string key_;
// Other members...
public:
Expensive(const char *key)
: key_(key)
{} //other expensive initializations...
const std::string & get_key() const
{ return key_; }
friend bool operator < (const Expensive &a, const Expensive &b)
{ return a.key_ < b.key_; }
friend bool operator == (const Expensive &a, const Expensive &b)
{ return a.key_ == b.key_; }
friend std::size_t hash_value(const Expensive &object)
{ return StrHasher()(object.get_key().c_str()); }
};
// A set and unordered_set that store Expensive objects
typedef set<Expensive> Set;
typedef unordered_set<Expensive> UnorderedSet;
// Search functions
Expensive *get_from_set(const char* key, Set &set_object)
{
Set::iterator it = set_object.find(Expensive(key));
if( it == set_object.end() ) return 0;
return &*it;
}
Expensive *get_from_uset(const char* key, UnorderedSet &uset_object)
{
UnorderedSet::iterator it = uset_object.find(Expensive (key));
if( it == uset_object.end() ) return 0;
return &*it;
}
//]
//[doc_assoc_optimized_code_optimized_find
// These compare Expensive and a c-string
struct StrExpComp
{
bool operator()(const char *str, const Expensive &c) const
{ return std::strcmp(str, c.get_key().c_str()) < 0; }
bool operator()(const Expensive &c, const char *str) const
{ return std::strcmp(c.get_key().c_str(), str) < 0; }
};
struct StrExpEqual
{
bool operator()(const char *str, const Expensive &c) const
{ return std::strcmp(str, c.get_key().c_str()) == 0; }
bool operator()(const Expensive &c, const char *str) const
{ return std::strcmp(c.get_key().c_str(), str) == 0; }
};
// Optimized search functions
Expensive *get_from_set_optimized(const char* key, Set &set_object)
{
Set::iterator it = set_object.find(key, StrExpComp());
if( it == set_object.end() ) return 0;
return &*it;
}
Expensive *get_from_uset_optimized(const char* key, UnorderedSet &uset_object)
{
UnorderedSet::iterator it = uset_object.find(key, StrHasher(), StrExpEqual());
if( it == uset_object.end() ) return 0;
return &*it;
}
//]
//[doc_assoc_optimized_code_normal_insert
// Insertion functions
bool insert_to_set(const char* key, Set &set_object)
{
Expensive *pobject = new Expensive(key);
bool success = set_object.insert(*pobject).second;
if(!success) delete pobject;
return success;
}
bool insert_to_uset(const char* key, UnorderedSet &uset_object)
{
Expensive *pobject = new Expensive(key);
bool success = uset_object.insert(*pobject).second;
if(!success) delete pobject;
return success;
}
//]
//[doc_assoc_optimized_code_optimized_insert
// Optimized insertion functions
bool insert_to_set_optimized(const char* key, Set &set_object)
{
Set::insert_commit_data insert_data;
bool success = set_object.insert_check(key, StrExpComp(), insert_data).second;
if(success) set_object.insert_commit(*new Expensive(key), insert_data);
return success;
}
bool insert_to_uset_optimized(const char* key, UnorderedSet &uset_object)
{
UnorderedSet::insert_commit_data insert_data;
bool success = uset_object.insert_check
(key, StrHasher(), StrExpEqual(), insert_data).second;
if(success) uset_object.insert_commit(*new Expensive(key), insert_data);
return success;
}
//]
int main()
{
Set set;
UnorderedSet::bucket_type buckets[10];
UnorderedSet unordered_set(UnorderedSet::bucket_traits(buckets, 10));
const char * const expensive_key
= "A long string that avoids small string optimization";
Expensive value(expensive_key);
if(get_from_set(expensive_key, set)){
return 1;
}
if(get_from_uset(expensive_key, unordered_set)){
return 1;
}
if(get_from_set_optimized(expensive_key, set)){
return 1;
}
if(get_from_uset_optimized(expensive_key, unordered_set)){
return 1;
}
Set::iterator setit = set.insert(value).first;
UnorderedSet::iterator unordered_setit = unordered_set.insert(value).first;
if(!get_from_set(expensive_key, set)){
return 1;
}
if(!get_from_uset(expensive_key, unordered_set)){
return 1;
}
if(!get_from_set_optimized(expensive_key, set)){
return 1;
}
if(!get_from_uset_optimized(expensive_key, unordered_set)){
return 1;
}
set.erase(setit);
unordered_set.erase(unordered_setit);
if(!insert_to_set(expensive_key, set)){
return 1;
}
if(!insert_to_uset(expensive_key, unordered_set)){
return 1;
}
{
Expensive *ptr = &*set.begin();
set.clear();
delete ptr;
}
{
Expensive *ptr = &*unordered_set.begin();
unordered_set.clear();
delete ptr;
}
if(!insert_to_set_optimized(expensive_key, set)){
return 1;
}
if(!insert_to_uset_optimized(expensive_key, unordered_set)){
return 1;
}
{
Expensive *ptr = &*set.begin();
set.clear();
delete ptr;
}
{
Expensive *ptr = &*unordered_set.begin();
unordered_set.clear();
delete ptr;
}
setit = set.insert(value).first;
unordered_setit = unordered_set.insert(value).first;
if(insert_to_set(expensive_key, set)){
return 1;
}
if(insert_to_uset(expensive_key, unordered_set)){
return 1;
}
if(insert_to_set_optimized(expensive_key, set)){
return 1;
}
if(insert_to_uset_optimized(expensive_key, unordered_set)){
return 1;
}
set.erase(value);
unordered_set.erase(value);
return 0;
}

View File

@@ -0,0 +1,83 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_auto_unlink_code
#include <boost/intrusive/list.hpp>
#include <cassert>
using namespace boost::intrusive;
typedef list_base_hook<link_mode<auto_unlink> > auto_unlink_hook;
class MyClass : public auto_unlink_hook
//This hook removes the node in the destructor
{
int int_;
public:
MyClass(int i = 0) : int_(i) {}
int get_int() { return int_; }
void unlink() { auto_unlink_hook::unlink(); }
bool is_linked() { return auto_unlink_hook::is_linked(); }
};
//Define a list that will store values using the base hook
//The list can't have constant-time size!
typedef list< MyClass, constant_time_size<false> > List;
int main()
{
//Create the list
List l;
{
//Create myclass and check it's linked
MyClass myclass;
assert(myclass.is_linked() == false);
//Insert the object
l.push_back(myclass);
//Check that we have inserted the object
assert(l.empty() == false);
assert(&l.front() == &myclass);
assert(myclass.is_linked() == true);
//Now myclass' destructor will unlink it
//automatically
}
//Check auto-unlink has been executed
assert(l.empty() == true);
{
//Now test the unlink() function
//Create myclass and check it's linked
MyClass myclass;
assert(myclass.is_linked() == false);
//Insert the object
l.push_back(myclass);
//Check that we have inserted the object
assert(l.empty() == false);
assert(&l.front() == &myclass);
assert(myclass.is_linked() == true);
//Now unlink the node
myclass.unlink();
//Check auto-unlink has been executed
assert(l.empty() == true);
}
return 0;
}
//]

View File

@@ -0,0 +1,85 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_avl_set_code
#include <boost/intrusive/avl_set.hpp>
#include <vector>
#include <functional>
#include <cassert>
using namespace boost::intrusive;
//This is a base hook optimized for size
class MyClass : public avl_set_base_hook<optimize_size<true> >
{
int int_;
public:
//This is a member hook
avl_set_member_hook<> member_hook_;
MyClass(int i)
: int_(i)
{}
friend bool operator< (const MyClass &a, const MyClass &b)
{ return a.int_ < b.int_; }
friend bool operator> (const MyClass &a, const MyClass &b)
{ return a.int_ > b.int_; }
friend bool operator== (const MyClass &a, const MyClass &b)
{ return a.int_ == b.int_; }
};
//Define an avl_set using the base hook that will store values in reverse order
typedef avl_set< MyClass, compare<std::greater<MyClass> > > BaseSet;
//Define an multiset using the member hook
typedef member_hook<MyClass, avl_set_member_hook<>, &MyClass::member_hook_> MemberOption;
typedef avl_multiset< MyClass, MemberOption> MemberMultiset;
int main()
{
typedef std::vector<MyClass>::iterator VectIt;
//Create several MyClass objects, each one with a different value
std::vector<MyClass> values;
for(int i = 0; i < 100; ++i) values.push_back(MyClass(i));
BaseSet baseset;
MemberMultiset membermultiset;
//Check that size optimization is activated in the base hook
assert(sizeof(avl_set_base_hook<optimize_size<true> >) == 3*sizeof(void*));
//Check that size optimization is deactivated in the member hook
assert(sizeof(avl_set_member_hook<>) > 3*sizeof(void*));
//Now insert them in the sets
for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it){
baseset.insert(*it);
membermultiset.insert(*it);
}
//Now test avl_sets
{
BaseSet::reverse_iterator rbit(baseset.rbegin());
MemberMultiset::iterator mit(membermultiset.begin());
VectIt it(values.begin()), itend(values.end());
//Test the objects inserted in the base hook avl_set
for(; it != itend; ++it, ++rbit)
if(&*rbit != &*it) return 1;
//Test the objects inserted in the member hook avl_set
for(it = values.begin(); it != itend; ++it, ++mit)
if(&*mit != &*it) return 1;
}
return 0;
}
//]

View File

@@ -0,0 +1,85 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2007-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_avltree_algorithms_code
#include <boost/intrusive/avltree_algorithms.hpp>
#include <cassert>
struct my_node
{
my_node(int i = 0)
: int_(i)
{}
my_node *parent_, *left_, *right_;
int balance_;
//other members
int int_;
};
//Define our own avltree_node_traits
struct my_avltree_node_traits
{
typedef my_node node;
typedef my_node * node_ptr;
typedef const my_node * const_node_ptr;
typedef int balance;
static node_ptr get_parent(const_node_ptr n) { return n->parent_; }
static void set_parent(node_ptr n, node_ptr parent){ n->parent_ = parent; }
static node_ptr get_left(const_node_ptr n) { return n->left_; }
static void set_left(node_ptr n, node_ptr left) { n->left_ = left; }
static node_ptr get_right(const_node_ptr n) { return n->right_; }
static void set_right(node_ptr n, node_ptr right) { n->right_ = right; }
static balance get_balance(const_node_ptr n) { return n->balance_; }
static void set_balance(node_ptr n, balance b) { n->balance_ = b; }
static balance negative() { return -1; }
static balance zero() { return 0; }
static balance positive() { return 1; }
};
struct node_ptr_compare
{
bool operator()(const my_node *a, const my_node *b)
{ return a->int_ < b->int_; }
};
int main()
{
typedef boost::intrusive::avltree_algorithms<my_avltree_node_traits> algo;
my_node header, two(2), three(3);
//Create an empty avltree container:
//"header" will be the header node of the tree
algo::init_header(&header);
//Now insert node "two" in the tree using the sorting functor
algo::insert_equal_upper_bound(&header, &two, node_ptr_compare());
//Now insert node "three" in the tree using the sorting functor
algo::insert_equal_lower_bound(&header, &three, node_ptr_compare());
//Now take the first node (the left node of the header)
my_node *n = header.left_;
assert(n == &two);
//Now go to the next node
n = algo::next_node(n);
assert(n == &three);
//Erase a node just using a pointer to it
algo::unlink(&two);
//Erase a node using also the header (faster)
algo::erase(&header, &three);
return 0;
}
//]

View File

@@ -0,0 +1,83 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2007-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_bucket_traits
#include <boost/intrusive/unordered_set.hpp>
#include <boost/container_hash/hash.hpp>
#include <vector>
using namespace boost::intrusive;
//A class to be inserted in an unordered_set
class MyClass : public unordered_set_base_hook<>
{
int int_;
public:
MyClass(int i = 0) : int_(i)
{}
friend bool operator==(const MyClass &l, const MyClass &r)
{ return l.int_ == r.int_; }
friend std::size_t hash_value(const MyClass &v)
{ return boost::hash_value(v.int_); }
};
//Define the base hook option
typedef base_hook< unordered_set_base_hook<> > BaseHookOption;
//Obtain the types of the bucket and the bucket pointer
typedef unordered_bucket<BaseHookOption>::type BucketType;
typedef unordered_bucket_ptr<BaseHookOption>::type BucketPtr;
//The custom bucket traits.
class custom_bucket_traits
{
public:
static const int NumBuckets = 100;
custom_bucket_traits(BucketPtr buckets)
: buckets_(buckets)
{}
//Functions to be implemented by custom bucket traits
BucketPtr bucket_begin() const { return buckets_; }
std::size_t bucket_count() const { return NumBuckets;}
private:
BucketPtr buckets_;
};
//Define the container using the custom bucket traits
typedef unordered_set<MyClass, bucket_traits<custom_bucket_traits> > BucketTraitsUset;
int main()
{
typedef std::vector<MyClass>::iterator VectIt;
std::vector<MyClass> values;
//Fill values
for(int i = 0; i < 100; ++i) values.push_back(MyClass(i));
//Now create the bucket array and the custom bucket traits object
BucketType buckets[custom_bucket_traits::NumBuckets];
custom_bucket_traits btraits(buckets);
//Now create the unordered set
BucketTraitsUset uset(btraits);
//Insert the values in the unordered set
for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it)
uset.insert(*it);
return 0;
}
//]

View File

@@ -0,0 +1,74 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_clone_from
#include <boost/intrusive/list.hpp>
#include <iostream>
#include <vector>
using namespace boost::intrusive;
//A class that can be inserted in an intrusive list
class my_class : public list_base_hook<>
{
public:
friend bool operator==(const my_class &a, const my_class &b)
{ return a.int_ == b.int_; }
int int_;
//...
};
//Definition of the intrusive list
typedef list<my_class> my_class_list;
//Cloner object function
struct new_cloner
{
my_class *operator()(const my_class &clone_this)
{ return new my_class(clone_this); }
};
//The disposer object function
struct delete_disposer
{
void operator()(my_class *delete_this)
{ delete delete_this; }
};
int main()
{
const std::size_t MaxElem = 100;
std::vector<my_class> nodes(MaxElem);
//Fill all the nodes and insert them in the list
my_class_list list;
for(std::size_t i = 0; i < MaxElem; ++i) nodes[i].int_ = (int)i;
list.insert(list.end(), nodes.begin(), nodes.end());
//Now clone "list" using "new" and "delete" object functions
my_class_list cloned_list;
cloned_list.clone_from(list, new_cloner(), delete_disposer());
//Test that both are equal
if(cloned_list != list)
std::cout << "Both lists are different" << std::endl;
else
std::cout << "Both lists are equal" << std::endl;
//Don't forget to free the memory from the second list
cloned_list.clear_and_dispose(delete_disposer());
return 0;
}
//]

View File

@@ -0,0 +1,94 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#include <boost/intrusive/link_mode.hpp>
#include <boost/intrusive/list.hpp>
#include <boost/intrusive/derivation_value_traits.hpp>
#include <vector>
struct simple_node
{
simple_node *prev_;
simple_node *next_;
};
//Define the node traits. A single node_traits will be enough.
struct simple_node_traits
{
typedef simple_node node;
typedef node * node_ptr;
typedef const node * const_node_ptr;
static node *get_next(const node *n) { return n->next_; }
static void set_next(node *n, node *next) { n->next_ = next; }
static node *get_previous(const node *n) { return n->prev_; }
static void set_previous(node *n, node *prev) { n->prev_ = prev; }
};
//[doc_derivation_value_traits_value_traits
class base_1{};
class base_2{};
struct value_1 : public base_1, public simple_node
{
int id_;
simple_node node_;
};
struct value_2 : public base_1, public base_2, public simple_node
{
simple_node node_;
float id_;
};
using namespace boost::intrusive;
//Now define the needed value traits using derivation_value_traits
typedef derivation_value_traits<value_1, simple_node_traits, normal_link> ValueTraits1;
typedef derivation_value_traits<value_2, simple_node_traits, normal_link> ValueTraits2;
//Now define two intrusive lists. Both lists will use the same algorithms:
// circular_list_algorithms<simple_node_traits>
typedef list <value_1, value_traits<ValueTraits1> > Value1List;
typedef list <value_2, value_traits<ValueTraits2> > Value2List;
//]
//[doc_derivation_value_traits_test
int main()
{
typedef std::vector<value_1> Vect1;
typedef std::vector<value_2> Vect2;
//Create values, with a different internal number
Vect1 values1;
Vect2 values2;
for(int i = 0; i < 100; ++i){
value_1 v1; v1.id_ = i; values1.push_back(v1);
value_2 v2; v2.id_ = (float)i; values2.push_back(v2);
}
//Create the lists with the objects
Value1List list1(values1.begin(), values1.end());
Value2List list2(values2.begin(), values2.end());
//Now test both lists
Value1List::const_iterator bit1(list1.begin()), bitend1(list1.end());
Value2List::const_iterator bit2(list2.begin()), bitend2(list2.end());
Vect1::const_iterator it1(values1.begin()), itend1(values1.end());
Vect2::const_iterator it2(values2.begin()), itend2(values2.end());
//Test the objects inserted in our lists
for(; it1 != itend1; ++it1, ++bit1, ++it2, ++bit2){
if(&*bit1 != &*it1 || &*bit2 != &*it2) return 1;
}
return 0;
}
//]

View File

@@ -0,0 +1,60 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_entity_code
#include <boost/intrusive/list.hpp>
using namespace boost::intrusive;
//A class that can be inserted in an intrusive list
class entity : public list_base_hook<>
{
public:
virtual ~entity();
//...
};
//"some_entity" derives from "entity"
class some_entity : public entity
{/**/};
//Definition of the intrusive list
struct entity_list : list<entity>
{
~entity_list()
{
// entity's destructor removes itself from the global list implicitly
while (!this->empty())
delete &this->front();
}
};
//A global list
entity_list global_list;
//The destructor removes itself from the global list
entity::~entity()
{ global_list.erase(entity_list::s_iterator_to(*this)); }
//Function to insert a new "some_entity" in the global list
void insert_some_entity()
{ global_list.push_back (*new some_entity(/*...*/)); }
int main()
{
//Insert some new entities
insert_some_entity();
insert_some_entity();
//global_list's destructor will free objects
return 0;
}
//]

View File

@@ -0,0 +1,98 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#include <boost/core/no_exceptions_support.hpp>
//[doc_erasing_and_disposing
#include <boost/intrusive/list.hpp>
using namespace boost::intrusive;
//A class that can be inserted in an intrusive list
class my_class : public list_base_hook<>
{
public:
my_class(int i)
: int_(i)
{}
int int_;
//...
};
//Definition of the intrusive list
typedef list<my_class> my_class_list;
//The predicate function
struct is_even
{
bool operator()(const my_class &c) const
{ return 0 == (c.int_ % 2); }
};
//The disposer object function
struct delete_disposer
{
void operator()(my_class *delete_this)
{ delete delete_this; }
};
int main()
{
const int MaxElem = 100;
//Fill all the nodes and insert them in the list
my_class_list list;
//<-
#if 1
BOOST_TRY{
#else
//->
try{
//<-
#endif
//->
//Insert new objects in the container
for(int i = 0; i < MaxElem; ++i) list.push_back(*new my_class(i));
//Now use remove_and_dispose_if to erase and delete the objects
list.remove_and_dispose_if(is_even(), delete_disposer());
}
//<-
#if 1
BOOST_CATCH(...){
#else
//->
catch(...){
//<-
#endif
//->
//If something throws, make sure that all the memory is freed
list.clear_and_dispose(delete_disposer());
//<-
#if 1
BOOST_RETHROW
#else
//->
throw;
//<-
#endif
//->
}
//<-
BOOST_CATCH_END
//->
//Dispose remaining elements
list.erase_and_dispose(list.begin(), list.end(), delete_disposer());
return 0;
}
//]

View File

@@ -0,0 +1,73 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2010-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_function_hooks
#include <boost/intrusive/list.hpp>
#include <boost/intrusive/parent_from_member.hpp>
using namespace boost::intrusive;
struct MyClass
{
int dummy;
//This internal type has a member hook
struct InnerNode
{
int dummy;
list_member_hook<> hook;
} inner;
};
//This functor converts between MyClass and InnerNode's member hook
struct Functor
{
//Required types
typedef list_member_hook<> hook_type;
typedef hook_type* hook_ptr;
typedef const hook_type* const_hook_ptr;
typedef MyClass value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
//Required static functions
static hook_ptr to_hook_ptr (value_type &value)
{ return &value.inner.hook; }
static const_hook_ptr to_hook_ptr(const value_type &value)
{ return &value.inner.hook; }
static pointer to_value_ptr(hook_ptr n)
{
return get_parent_from_member<MyClass>
(get_parent_from_member<MyClass::InnerNode>(n, &MyClass::InnerNode::hook)
,&MyClass::inner
);
}
static const_pointer to_value_ptr(const_hook_ptr n)
{
return get_parent_from_member<MyClass>
(get_parent_from_member<MyClass::InnerNode>(n, &MyClass::InnerNode::hook)
,&MyClass::inner
);
}
};
//Define a list that will use the hook accessed through the function object
typedef list< MyClass, function_hook< Functor> > List;
int main()
{
MyClass n;
List l;
//Insert the node in both lists
l.insert(l.begin(), n);
assert(l.size() == 1);
return 0;
}
//]

View File

@@ -0,0 +1,77 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_how_to_use_code
#include <boost/intrusive/list.hpp>
#include <vector>
using namespace boost::intrusive;
class MyClass : public list_base_hook<>
{
int int_;
public:
list_member_hook<> member_hook_;
MyClass(int i) : int_(i) {}
//<-
int get_int() const { return int_; }
//->
};
//Define a list that will store MyClass using the base hook
typedef list<MyClass> BaseList;
//Define a list that will store MyClass using the member hook
typedef member_hook
< MyClass, list_member_hook<>, &MyClass::member_hook_> MemberOption;
typedef list<MyClass, MemberOption> MemberList;
int main()
{
typedef std::vector<MyClass>::iterator VectIt;
//Create several MyClass objects, each one with a different value
std::vector<MyClass> values;
for(int i = 0; i < 100; ++i) values.push_back(MyClass(i));
BaseList baselist;
MemberList memberlist;
//Now insert them in the reverse order in the base hook list
for(VectIt it(values.begin()), itend(values.end())
; it != itend ; ++it){
baselist.push_front(*it);
}
//Now insert them in the same order as in vector in the member hook list
for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it)
memberlist.push_back(*it);
//Now test lists
{
BaseList::reverse_iterator rbit(baselist.rbegin());
MemberList::iterator mit(memberlist.begin());
VectIt it(values.begin()), itend(values.end());
//Test the objects inserted in the base hook list
for(; it != itend; ++it, ++rbit)
if(&*rbit != &*it) return 1;
//Test the objects inserted in the member hook list
for(it = values.begin(); it != itend; ++it, ++mit)
if(&*mit != &*it) return 1;
}
return 0;
}
//]

View File

@@ -0,0 +1,97 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_iterator_from_value
#include <boost/intrusive/list.hpp>
#include <boost/intrusive/unordered_set.hpp>
#include <boost/container_hash/hash.hpp>
#include <vector>
using namespace boost::intrusive;
class intrusive_data
{
int data_id_;
public:
void set(int id) { data_id_ = id; }
//This class can be inserted in an intrusive list
list_member_hook<> list_hook_;
//This class can be inserted in an intrusive unordered_set
unordered_set_member_hook<> unordered_set_hook_;
//Comparison operators
friend bool operator==(const intrusive_data &a, const intrusive_data &b)
{ return a.data_id_ == b.data_id_; }
friend bool operator!=(const intrusive_data &a, const intrusive_data &b)
{ return a.data_id_ != b.data_id_; }
//The hash function
friend std::size_t hash_value(const intrusive_data &i)
{ return boost::hash<int>()(i.data_id_); }
};
//Definition of the intrusive list that will hold intrusive_data
typedef member_hook<intrusive_data, list_member_hook<>
, &intrusive_data::list_hook_> MemberListOption;
typedef list<intrusive_data, MemberListOption> list_t;
//Definition of the intrusive unordered_set that will hold intrusive_data
typedef member_hook
< intrusive_data, unordered_set_member_hook<>
, &intrusive_data::unordered_set_hook_> MemberUsetOption;
typedef boost::intrusive::unordered_set
< intrusive_data, MemberUsetOption> unordered_set_t;
int main()
{
//Create MaxElem objects
const std::size_t MaxElem = 100;
std::vector<intrusive_data> nodes(MaxElem);
//Declare the intrusive containers
list_t list;
unordered_set_t::bucket_type buckets[MaxElem];
unordered_set_t unordered_set
(unordered_set_t::bucket_traits(buckets, MaxElem));
//Initialize all the nodes
for(std::size_t i = 0; i < MaxElem; ++i) nodes[i].set((int)i);
//Now insert them in both intrusive containers
list.insert(list.end(), nodes.begin(), nodes.end());
unordered_set.insert(nodes.begin(), nodes.end());
//Now check the iterator_to function
list_t::iterator list_it(list.begin());
for(std::size_t i = 0; i < MaxElem; ++i, ++list_it)
if(list.iterator_to(nodes[i]) != list_it ||
list_t::s_iterator_to(nodes[i]) != list_it)
return 1;
//Now check unordered_set::s_iterator_to (which is a member function)
//and unordered_set::s_local_iterator_to (which is an static member function)
unordered_set_t::iterator unordered_set_it(unordered_set.begin());
for(std::size_t i = 0; i < MaxElem; ++i){
unordered_set_it = unordered_set.find(nodes[i]);
if(unordered_set.iterator_to(nodes[i]) != unordered_set_it)
return 1;
if(*unordered_set.local_iterator_to(nodes[i]) != *unordered_set_it ||
*unordered_set_t::s_local_iterator_to(nodes[i]) != *unordered_set_it )
return 1;
}
return 0;
}
//]

View File

@@ -0,0 +1,78 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_list_code
#include <boost/intrusive/list.hpp>
#include <vector>
using namespace boost::intrusive;
class MyClass : public list_base_hook<> //This is a derivation hook
{
int int_;
public:
//This is a member hook
list_member_hook<> member_hook_;
MyClass(int i)
: int_(i)
{}
//<-
int get_int() const { return int_; }
//->
};
//Define a list that will store MyClass using the public base hook
typedef list<MyClass> BaseList;
//Define a list that will store MyClass using the public member hook
typedef list< MyClass
, member_hook< MyClass, list_member_hook<>, &MyClass::member_hook_>
> MemberList;
int main()
{
typedef std::vector<MyClass>::iterator VectIt;
//Create several MyClass objects, each one with a different value
std::vector<MyClass> values;
for(int i = 0; i < 100; ++i) values.push_back(MyClass(i));
BaseList baselist;
MemberList memberlist;
//Now insert them in the reverse order in the base hook list
for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it)
baselist.push_front(*it);
//Now insert them in the same order as in vector in the member hook list
for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it)
memberlist.push_back(*it);
//Now test lists
{
BaseList::reverse_iterator rbit(baselist.rbegin());
MemberList::iterator mit(memberlist.begin());
VectIt it(values.begin()), itend(values.end());
//Test the objects inserted in the base hook list
for(; it != itend; ++it, ++rbit)
if(&*rbit != &*it) return 1;
//Test the objects inserted in the member hook list
for(it = values.begin(); it != itend; ++it, ++mit)
if(&*mit != &*it) return 1;
}
return 0;
}
//]

View File

@@ -0,0 +1,66 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_list_algorithms_code
#include <boost/intrusive/circular_list_algorithms.hpp>
#include <cassert>
struct my_node
{
my_node *next_, *prev_;
//other members...
};
//Define our own list_node_traits
struct my_list_node_traits
{
typedef my_node node;
typedef my_node * node_ptr;
typedef const my_node * const_node_ptr;
static node_ptr get_next(const_node_ptr n) { return n->next_; }
static void set_next(node_ptr n, node_ptr next) { n->next_ = next; }
static node *get_previous(const_node_ptr n) { return n->prev_; }
static void set_previous(node_ptr n, node_ptr prev){ n->prev_ = prev; }
};
int main()
{
typedef boost::intrusive::circular_list_algorithms<my_list_node_traits> algo;
my_node one, two, three;
//Create an empty doubly linked list container:
//"one" will be the first node of the container
algo::init_header(&one);
assert(algo::count(&one) == 1);
//Now add a new node before "one"
algo::link_before(&one, &two);
assert(algo::count(&one) == 2);
//Now add a new node after "two"
algo::link_after(&two, &three);
assert(algo::count(&one) == 3);
//Now unlink the node after one
algo::unlink(&three);
assert(algo::count(&one) == 2);
//Now unlink two
algo::unlink(&two);
assert(algo::count(&one) == 1);
//Now unlink one
algo::unlink(&one);
assert(algo::count(&one) == 1);
return 0;
}
//]

View File

@@ -0,0 +1,84 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2015-2015
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_map_code
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/intrusive/set.hpp>
#include <boost/intrusive/unordered_set.hpp>
#include <vector>
#include <cassert>
using namespace boost::intrusive;
class MyClass : public set_base_hook<>
, public unordered_set_base_hook<>
{
public:
int first;
explicit MyClass(int i) : first(i){}
};
//key_of_value function object, must:
//- be default constructible if the container constructor requires it
//- define the key type using "type"
//- define an operator() taking "const value_type&" and
// returning "type" or "const type &"
struct first_int_is_key
{
typedef int type;
const type & operator()(const MyClass& v) const
{ return v.first; }
};
//Define omap like ordered and unordered classes
typedef set< MyClass, key_of_value<first_int_is_key> > OrderedMap;
typedef unordered_set< MyClass, key_of_value<first_int_is_key> > UnorderedMap;
int main()
{
BOOST_STATIC_ASSERT((boost::is_same< OrderedMap::key_type, int>::value));
BOOST_STATIC_ASSERT((boost::is_same<UnorderedMap::key_type, int>::value));
//Create several MyClass objects, each one with a different value
//and insert them into the omap
std::vector<MyClass> values;
for(int i = 0; i < 100; ++i) values.push_back(MyClass(i));
//Create ordered/unordered maps and insert values
OrderedMap omap(values.begin(), values.end());
UnorderedMap::bucket_type buckets[100];
UnorderedMap umap(values.begin(), values.end(), UnorderedMap::bucket_traits(buckets, 100));
//Test each element using the key_type (int)
for(int i = 0; i != 100; ++i){
assert(omap.find(i) != omap.end());
assert(umap.find(i) != umap.end());
assert(omap.lower_bound(i) != omap.end());
assert(++omap.lower_bound(i) == omap.upper_bound(i));
assert(omap.equal_range(i).first != omap.equal_range(i).second);
assert(umap.equal_range(i).first != umap.equal_range(i).second);
}
//Count and erase by key
for(int i = 0; i != 100; ++i){
assert(1 == omap.count(i));
assert(1 == umap.count(i));
assert(1 == omap.erase(i));
assert(1 == umap.erase(i));
}
assert(omap.empty());
assert(umap.empty());
return 0;
}
//]

View File

@@ -0,0 +1,95 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#include <boost/intrusive/link_mode.hpp>
#include <boost/intrusive/list.hpp>
#include <boost/intrusive/member_value_traits.hpp>
#include <vector>
struct simple_node
{
simple_node *prev_;
simple_node *next_;
};
//Define the node traits. A single node_traits will be enough.
struct simple_node_traits
{
typedef simple_node node;
typedef node * node_ptr;
typedef const node * const_node_ptr;
static node *get_next(const node *n) { return n->next_; }
static void set_next(node *n, node *next) { n->next_ = next; }
static node *get_previous(const node *n) { return n->prev_; }
static void set_previous(node *n, node *prev) { n->prev_ = prev; }
};
//[doc_member_value_traits_value_traits
class base_1{};
class base_2{};
struct value_1 : public base_1, public simple_node
{
int id_;
simple_node node_;
};
struct value_2 : public base_1, public base_2, public simple_node
{
simple_node node_;
float id_;
};
using namespace boost::intrusive;
typedef member_value_traits
<value_1, simple_node_traits, &value_1::node_, normal_link> ValueTraits1;
typedef member_value_traits
<value_2, simple_node_traits, &value_2::node_, normal_link> ValueTraits2;
//Now define two intrusive lists. Both lists will use the same algorithms:
// circular_list_algorithms<simple_node_traits>
typedef list <value_1, value_traits<ValueTraits1> > Value1List;
typedef list <value_2, value_traits<ValueTraits2> > Value2List;
//]
//[doc_member_value_traits_test
int main()
{
typedef std::vector<value_1> Vect1;
typedef std::vector<value_2> Vect2;
//Create values, with a different internal number
Vect1 values1;
Vect2 values2;
for(int i = 0; i < 100; ++i){
value_1 v1; v1.id_ = i; values1.push_back(v1);
value_2 v2; v2.id_ = (float)i; values2.push_back(v2);
}
//Create the lists with the objects
Value1List list1(values1.begin(), values1.end());
Value2List list2(values2.begin(), values2.end());
//Now test both lists
Value1List::const_iterator bit1(list1.begin()), bitend1(list1.end());
Value2List::const_iterator bit2(list2.begin()), bitend2(list2.end());
Vect1::const_iterator it1(values1.begin()), itend1(values1.end());
Vect2::const_iterator it2(values2.begin()), itend2(values2.end());
//Test the objects inserted in our lists
for(; it1 != itend1; ++it1, ++bit1, ++it2, ++bit2){
if(&*bit1 != &*it1 || &*bit2 != &*it2) return 1;
}
return 0;
}
//]

View File

@@ -0,0 +1,116 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#include <boost/config.hpp>
#ifdef BOOST_NO_EXCEPTIONS
//Interprocess does not support BOOST_NO_EXCEPTIONS so nothing to test here
int main()
{
return 0;
}
#else //!BOOST_NO_EXCEPTIONS
//This is needed to allow concurrent test execution in
//several platforms. The shared memory must be unique
//for each process...
#include <boost/interprocess/detail/os_thread_functions.hpp>
#include <sstream>
const char *get_shared_memory_name()
{
std::stringstream s;
s << "process_" << boost::interprocess::ipcdetail::get_current_process_id();
static std::string str = s.str();
return str.c_str();
}
//[doc_offset_ptr_0
#include <boost/intrusive/list.hpp>
#include <boost/interprocess/offset_ptr.hpp>
using namespace boost::intrusive;
namespace ip = boost::interprocess;
class shared_memory_data
//Declare the hook with an offset_ptr from Boost.Interprocess
//to make this class compatible with shared memory
: public list_base_hook< void_pointer< ip::offset_ptr<void> > >
{
int data_id_;
public:
int get() const { return data_id_; }
void set(int id) { data_id_ = id; }
};
//]
//[doc_offset_ptr_1
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/containers/vector.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
//Definition of the shared memory friendly intrusive list
typedef list<shared_memory_data> intrusive_list_t;
int main()
{
//Now create an intrusive list in shared memory:
//nodes and the container itself must be created in shared memory
const std::size_t MaxElem = 100;
const std::size_t ShmSize = 50000;
const char *ShmName = get_shared_memory_name();
{
//Erase all old shared memory
ip::shared_memory_object::remove(ShmName);
ip::managed_shared_memory shm(ip::create_only, ShmName, ShmSize);
//Create all nodes in shared memory using a shared memory vector
//See Boost.Interprocess documentation for more information on this
typedef ip::allocator
< shared_memory_data, ip::managed_shared_memory::segment_manager>
shm_allocator_t;
typedef ip::vector<shared_memory_data, shm_allocator_t> shm_vector_t;
shm_allocator_t shm_alloc(shm.get_segment_manager());
shm_vector_t *pshm_vect =
shm.construct<shm_vector_t>(ip::anonymous_instance)(shm_alloc);
pshm_vect->resize(MaxElem);
//Initialize all the nodes
for(std::size_t i = 0; i < MaxElem; ++i) (*pshm_vect)[i].set((int)i);
//Now create the shared memory intrusive list
intrusive_list_t *plist = shm.construct<intrusive_list_t>(ip::anonymous_instance)();
//Insert objects stored in shared memory vector in the intrusive list
plist->insert(plist->end(), pshm_vect->begin(), pshm_vect->end());
//Check all the inserted nodes
int checker = 0;
for( intrusive_list_t::const_iterator it = plist->begin(), itend(plist->end())
; it != itend; ++it, ++checker){
if(it->get() != checker) return 1;
}
//Now delete the list and after that, the nodes
shm.destroy_ptr(plist);
shm.destroy_ptr(pshm_vect);
}
ip::shared_memory_object::remove(ShmName);
return 0;
}
//]
#endif //BOOST_NO_EXCEPTIONS

View File

@@ -0,0 +1,74 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2009-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_positional_insertion
#include <boost/intrusive/set.hpp>
#include <vector>
#include <functional>
#include <cassert>
using namespace boost::intrusive;
//A simple class with a set hook
class MyClass : public set_base_hook<>
{
public:
int int_;
MyClass(int i) : int_(i) {}
friend bool operator< (const MyClass &a, const MyClass &b)
{ return a.int_ < b.int_; }
friend bool operator> (const MyClass &a, const MyClass &b)
{ return a.int_ > b.int_; }
};
int main()
{
//Create some ORDERED elements
std::vector<MyClass> values;
for(int i = 0; i < 100; ++i) values.push_back(MyClass(i));
{ //Data is naturally ordered in the vector with the same criteria
//as multiset's comparison predicate, so we can just push back
//all elements, which is more efficient than normal insertion
multiset<MyClass> mset;
for(std::size_t i = 0; i != 100u; ++i) mset.push_back(values[i]);
//Now check orderd invariant
multiset<MyClass>::const_iterator next(mset.cbegin()), it(next++);
for(std::size_t i = 0; i < 99u; ++i, ++it, ++next) assert(*it < *next);
}
{ //Now the correct order for the set is the reverse order
//so let's push front all elements
multiset<MyClass, compare< std::greater<MyClass> > > mset;
for(std::size_t i = 0; i < 100u; ++i) mset.push_front(values[i]);
//Now check orderd invariant
multiset<MyClass, compare< std::greater<MyClass> > >::
const_iterator next(mset.cbegin()), it(next++);
for(std::size_t i = 0; i < 99u; ++i, ++it, ++next) assert(*it > *next);
}
{ //Now push the first and the last and insert the rest
//before the last position using "insert_before"
multiset<MyClass> mset;
mset.insert_before(mset.begin(), values[0]);
multiset<MyClass>::const_iterator pos =
mset.insert_before(mset.end(), values[99]);
for(std::size_t i = 1; i < 99u; ++i) mset.insert_before(pos, values[i]);
//Now check orderd invariant
multiset<MyClass>::const_iterator next(mset.cbegin()), it(next++);
for(int i = 0; i < 99; ++i, ++it, ++next) assert(*it < *next);
}
return 0;
}
//]

View File

@@ -0,0 +1,83 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_rbtree_algorithms_code
#include <boost/intrusive/rbtree_algorithms.hpp>
#include <cassert>
struct my_node
{
my_node(int i = 0)
: int_(i)
{}
my_node *parent_, *left_, *right_;
int color_;
//other members
int int_;
};
//Define our own rbtree_node_traits
struct my_rbtree_node_traits
{
typedef my_node node;
typedef my_node * node_ptr;
typedef const my_node * const_node_ptr;
typedef int color;
static node_ptr get_parent(const_node_ptr n) { return n->parent_; }
static void set_parent(node_ptr n, node_ptr parent){ n->parent_ = parent; }
static node_ptr get_left(const_node_ptr n) { return n->left_; }
static void set_left(node_ptr n, node_ptr left) { n->left_ = left; }
static node_ptr get_right(const_node_ptr n) { return n->right_; }
static void set_right(node_ptr n, node_ptr right) { n->right_ = right; }
static color get_color(const_node_ptr n) { return n->color_; }
static void set_color(node_ptr n, color c) { n->color_ = c; }
static color black() { return color(0); }
static color red() { return color(1); }
};
struct node_ptr_compare
{
bool operator()(const my_node *a, const my_node *b)
{ return a->int_ < b->int_; }
};
int main()
{
typedef boost::intrusive::rbtree_algorithms<my_rbtree_node_traits> algo;
my_node header, two(2), three(3);
//Create an empty rbtree container:
//"header" will be the header node of the tree
algo::init_header(&header);
//Now insert node "two" in the tree using the sorting functor
algo::insert_equal_upper_bound(&header, &two, node_ptr_compare());
//Now insert node "three" in the tree using the sorting functor
algo::insert_equal_lower_bound(&header, &three, node_ptr_compare());
//Now take the first node (the left node of the header)
my_node *n = header.left_;
assert(n == &two);
//Now go to the next node
n = algo::next_node(n);
assert(n == &three);
//Erase a node just using a pointer to it
algo::unlink(&two);
//Erase a node using also the header (faster)
algo::erase(&header, &three);
return 0;
}
//]

View File

@@ -0,0 +1,53 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_recursive
#include <boost/intrusive/list.hpp>
#include <cassert>
using namespace boost::intrusive;
typedef list_base_hook<> BaseHook;
//A recursive class
class Recursive : public BaseHook
{
private:
Recursive(const Recursive&);
Recursive & operator=(const Recursive&);
public:
Recursive() : BaseHook(), children(){}
list< Recursive, base_hook<BaseHook> > children;
};
int main()
{
Recursive f, f2;
//A recursive list of Recursive
list< Recursive, base_hook<BaseHook> > l;
//Insert a node in parent list
l.insert(l.begin(), f);
//Insert a node in child list
l.begin()->children.insert(l.begin()->children.begin(), f2);
//Objects properly inserted
assert(l.size() == l.begin()->children.size());
assert(l.size() == 1);
//Clear both lists
l.begin()->children.clear();
l.clear();
return 0;
}
//]

View File

@@ -0,0 +1,83 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2010-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_recursive_member
#include <boost/intrusive/list.hpp>
#include <boost/intrusive/parent_from_member.hpp>
using namespace boost::intrusive;
class Recursive;
//Declaration of the functor that converts betwen the Recursive
//class and the hook
struct Functor
{
//Required types
typedef list_member_hook<> hook_type;
typedef hook_type* hook_ptr;
typedef const hook_type* const_hook_ptr;
typedef Recursive value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
//Required static functions
static hook_ptr to_hook_ptr (value_type &value);
static const_hook_ptr to_hook_ptr(const value_type &value);
static pointer to_value_ptr(hook_ptr n);
static const_pointer to_value_ptr(const_hook_ptr n);
};
//Define the recursive class
class Recursive
{
private:
Recursive(const Recursive&);
Recursive & operator=(const Recursive&);
public:
Recursive() : hook(), children() {}
list_member_hook<> hook;
list< Recursive, function_hook< Functor> > children;
};
//Definition of Functor functions
inline Functor::hook_ptr Functor::to_hook_ptr (Functor::value_type &value)
{ return &value.hook; }
inline Functor::const_hook_ptr Functor::to_hook_ptr(const Functor::value_type &value)
{ return &value.hook; }
inline Functor::pointer Functor::to_value_ptr(Functor::hook_ptr n)
{ return get_parent_from_member<Recursive>(n, &Recursive::hook); }
inline Functor::const_pointer Functor::to_value_ptr(Functor::const_hook_ptr n)
{ return get_parent_from_member<Recursive>(n, &Recursive::hook); }
int main()
{
Recursive f, f2;
//A recursive list of Recursive
list< Recursive, function_hook< Functor> > l;
//Insert a node in parent list
l.insert(l.begin(), f);
//Insert a node in child list
l.begin()->children.insert(l.begin()->children.begin(), f2);
//Objects properly inserted
assert(l.size() == l.begin()->children.size());
assert(l.size() == 1);
//Clear both lists
l.begin()->children.clear();
l.clear();
return 0;
}
//]

View File

@@ -0,0 +1,85 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_set_code
#include <boost/intrusive/set.hpp>
#include <vector>
#include <functional>
#include <cassert>
using namespace boost::intrusive;
//This is a base hook optimized for size
class MyClass : public set_base_hook<optimize_size<true> >
{
int int_;
public:
//This is a member hook
set_member_hook<> member_hook_;
MyClass(int i)
: int_(i)
{}
friend bool operator< (const MyClass &a, const MyClass &b)
{ return a.int_ < b.int_; }
friend bool operator> (const MyClass &a, const MyClass &b)
{ return a.int_ > b.int_; }
friend bool operator== (const MyClass &a, const MyClass &b)
{ return a.int_ == b.int_; }
};
//Define a set using the base hook that will store values in reverse order
typedef set< MyClass, compare<std::greater<MyClass> > > BaseSet;
//Define an multiset using the member hook
typedef member_hook<MyClass, set_member_hook<>, &MyClass::member_hook_> MemberOption;
typedef multiset< MyClass, MemberOption> MemberMultiset;
int main()
{
typedef std::vector<MyClass>::iterator VectIt;
//Create several MyClass objects, each one with a different value
std::vector<MyClass> values;
for(int i = 0; i < 100; ++i) values.push_back(MyClass(i));
BaseSet baseset;
MemberMultiset membermultiset;
//Check that size optimization is activated in the base hook
assert(sizeof(set_base_hook<optimize_size<true> >) == 3*sizeof(void*));
//Check that size optimization is deactivated in the member hook
assert(sizeof(set_member_hook<>) > 3*sizeof(void*));
//Now insert them in the reverse order in the base hook set
for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it){
baseset.insert(*it);
membermultiset.insert(*it);
}
//Now test sets
{
BaseSet::reverse_iterator rbit(baseset.rbegin());
MemberMultiset::iterator mit(membermultiset.begin());
VectIt it(values.begin()), itend(values.end());
//Test the objects inserted in the base hook set
for(; it != itend; ++it, ++rbit)
if(&*rbit != &*it) return 1;
//Test the objects inserted in the member hook set
for(it = values.begin(); it != itend; ++it, ++mit)
if(&*mit != &*it) return 1;
}
return 0;
}
//]

View File

@@ -0,0 +1,84 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2007-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_sg_set_code
#include <boost/intrusive/sg_set.hpp>
#include <vector>
#include <functional>
#include <cassert>
using namespace boost::intrusive;
class MyClass : public bs_set_base_hook<>
{
int int_;
public:
//This is a member hook
bs_set_member_hook<> member_hook_;
MyClass(int i)
: int_(i)
{}
friend bool operator< (const MyClass &a, const MyClass &b)
{ return a.int_ < b.int_; }
friend bool operator> (const MyClass &a, const MyClass &b)
{ return a.int_ > b.int_; }
friend bool operator== (const MyClass &a, const MyClass &b)
{ return a.int_ == b.int_; }
};
//Define an sg_set using the base hook that will store values in reverse order
//and won't execute floating point operations.
typedef sg_set
< MyClass, compare<std::greater<MyClass> >, floating_point<false> > BaseSet;
//Define an multiset using the member hook
typedef member_hook<MyClass, bs_set_member_hook<>, &MyClass::member_hook_> MemberOption;
typedef sg_multiset< MyClass, MemberOption> MemberMultiset;
int main()
{
typedef std::vector<MyClass>::iterator VectIt;
//Create several MyClass objects, each one with a different value
std::vector<MyClass> values;
for(int i = 0; i < 100; ++i) values.push_back(MyClass(i));
BaseSet baseset;
MemberMultiset membermultiset;
//Now insert them in the reverse order in the base hook sg_set
for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it){
baseset.insert(*it);
membermultiset.insert(*it);
}
//Change balance factor
membermultiset.balance_factor(0.9f);
//Now test sg_sets
{
BaseSet::reverse_iterator rbit(baseset.rbegin());
MemberMultiset::iterator mit(membermultiset.begin());
VectIt it(values.begin()), itend(values.end());
//Test the objects inserted in the base hook sg_set
for(; it != itend; ++it, ++rbit)
if(&*rbit != &*it) return 1;
//Test the objects inserted in the member hook sg_set
for(it = values.begin(); it != itend; ++it, ++mit)
if(&*mit != &*it) return 1;
}
return 0;
}
//]

View File

@@ -0,0 +1,82 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_slist_code
#include <boost/intrusive/slist.hpp>
#include <vector>
using namespace boost::intrusive;
//This is a base hook
class MyClass : public slist_base_hook<>
{
int int_;
public:
//This is a member hook
slist_member_hook<> member_hook_;
MyClass(int i)
: int_(i)
{}
//<-
int get_int() const { return int_; }
//->
};
//Define an slist that will store MyClass using the public base hook
typedef slist<MyClass> BaseList;
//Define an slist that will store MyClass using the public member hook
typedef member_hook<MyClass, slist_member_hook<>, &MyClass::member_hook_> MemberOption;
typedef slist<MyClass, MemberOption> MemberList;
int main()
{
typedef std::vector<MyClass>::iterator VectIt;
typedef std::vector<MyClass>::reverse_iterator VectRit;
//Create several MyClass objects, each one with a different value
std::vector<MyClass> values;
for(int i = 0; i < 100; ++i) values.push_back(MyClass(i));
BaseList baselist;
MemberList memberlist;
//Now insert them in the reverse order in the base hook list
for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it)
baselist.push_front(*it);
//Now insert them in the same order as in vector in the member hook list
for(BaseList::iterator it(baselist.begin()), itend(baselist.end())
; it != itend; ++it){
memberlist.push_front(*it);
}
//Now test lists
{
BaseList::iterator bit(baselist.begin());
MemberList::iterator mit(memberlist.begin());
VectRit rit(values.rbegin()), ritend(values.rend());
VectIt it(values.begin()), itend(values.end());
//Test the objects inserted in the base hook list
for(; rit != ritend; ++rit, ++bit)
if(&*bit != &*rit) return 1;
//Test the objects inserted in the member hook list
for(; it != itend; ++it, ++mit)
if(&*mit != &*it) return 1;
}
return 0;
}
//]

View File

@@ -0,0 +1,60 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_slist_algorithms_code
#include <boost/intrusive/circular_slist_algorithms.hpp>
#include <cassert>
struct my_node
{
my_node *next_;
//other members...
};
//Define our own slist_node_traits
struct my_slist_node_traits
{
typedef my_node node;
typedef my_node * node_ptr;
typedef const my_node * const_node_ptr;
static node_ptr get_next(const_node_ptr n) { return n->next_; }
static void set_next(node_ptr n, node_ptr next) { n->next_ = next; }
};
int main()
{
typedef boost::intrusive::circular_slist_algorithms<my_slist_node_traits> algo;
my_node one, two, three;
//Create an empty singly linked list container:
//"one" will be the first node of the container
algo::init_header(&one);
assert(algo::count(&one) == 1);
//Now add a new node
algo::link_after(&one, &two);
assert(algo::count(&one) == 2);
//Now add a new node after "one"
algo::link_after(&one, &three);
assert(algo::count(&one) == 3);
//Now unlink the node after one
algo::unlink_after(&one);
assert(algo::count(&one) == 2);
//Now unlink two
algo::unlink(&two);
assert(algo::count(&one) == 1);
return 0;
}
//]

View File

@@ -0,0 +1,78 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_splaytree_algorithms_code
#include <boost/intrusive/splaytree_algorithms.hpp>
#include <cassert>
struct my_node
{
my_node(int i = 0)
: int_(i)
{}
my_node *parent_, *left_, *right_;
int color_;
//other members
int int_;
};
//Define our own splaytree_node_traits
struct my_splaytree_node_traits
{
typedef my_node node;
typedef my_node * node_ptr;
typedef const my_node * const_node_ptr;
static node_ptr get_parent(const_node_ptr n) { return n->parent_; }
static void set_parent(node_ptr n, node_ptr parent){ n->parent_ = parent; }
static node_ptr get_left(const_node_ptr n) { return n->left_; }
static void set_left(node_ptr n, node_ptr left) { n->left_ = left; }
static node_ptr get_right(const_node_ptr n) { return n->right_; }
static void set_right(node_ptr n, node_ptr right) { n->right_ = right; }
};
struct node_ptr_compare
{
bool operator()(const my_node *a, const my_node *b)
{ return a->int_ < b->int_; }
};
int main()
{
typedef boost::intrusive::splaytree_algorithms<my_splaytree_node_traits> algo;
my_node header, two(2), three(3);
//Create an empty splaytree container:
//"header" will be the header node of the tree
algo::init_header(&header);
//Now insert node "two" in the tree using the sorting functor
algo::insert_equal_upper_bound(&header, &two, node_ptr_compare());
//Now insert node "three" in the tree using the sorting functor
algo::insert_equal_lower_bound(&header, &three, node_ptr_compare());
//Now take the first node (the left node of the header)
my_node *n = header.left_;
assert(n == &two);
//Now go to the next node
n = algo::next_node(n);
assert(n == &three);
//Erase a node just using a pointer to it
algo::unlink(&two);
//Erase a node using also the header (faster)
algo::erase(&header, &three);
return 0;
}
//]

View File

@@ -0,0 +1,84 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_splay_set_code
#include <boost/intrusive/splay_set.hpp>
#include <vector>
#include <functional>
using namespace boost::intrusive;
class mytag;
class MyClass
: public bs_set_base_hook<>
{
int int_;
public:
//This is a member hook
bs_set_member_hook<> member_hook_;
MyClass(int i)
: int_(i)
{}
friend bool operator< (const MyClass &a, const MyClass &b)
{ return a.int_ < b.int_; }
friend bool operator> (const MyClass &a, const MyClass &b)
{ return a.int_ > b.int_; }
friend bool operator== (const MyClass &a, const MyClass &b)
{ return a.int_ == b.int_; }
};
//Define a set using the base hook that will store values in reverse order
typedef splay_set< MyClass, compare<std::greater<MyClass> > > BaseSplaySet;
//Define an multiset using the member hook
typedef member_hook<MyClass, bs_set_member_hook<>, &MyClass::member_hook_> MemberOption;
typedef splay_multiset< MyClass, MemberOption> MemberSplayMultiset;
int main()
{
typedef std::vector<MyClass>::iterator VectIt;
//Create several MyClass objects, each one with a different value
std::vector<MyClass> values;
for(int i = 0; i < 100; ++i) values.push_back(MyClass(i));
BaseSplaySet baseset;
MemberSplayMultiset membermultiset;
//Insert values in the container
for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it){
baseset.insert(*it);
membermultiset.insert(*it);
}
//Now test sets
{
BaseSplaySet::reverse_iterator rbit(baseset.rbegin());
MemberSplayMultiset::iterator mit(membermultiset.begin());
VectIt it(values.begin()), itend(values.end());
//Test the objects inserted in the base hook set
for(; it != itend; ++it, ++rbit){
if(&*rbit != &*it) return 1;
}
//Test the objects inserted in member and binary search hook sets
for(it = values.begin(); it != itend; ++it, ++mit){
if(&*mit != &*it) return 1;
}
}
return 0;
}
//]

View File

@@ -0,0 +1,78 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2007-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_splaytree_algorithms_code
#include <boost/intrusive/splaytree_algorithms.hpp>
#include <cassert>
struct my_node
{
my_node(int i = 0)
: int_(i)
{}
my_node *parent_, *left_, *right_;
//other members
int int_;
};
//Define our own splaytree_node_traits
struct my_splaytree_node_traits
{
typedef my_node node;
typedef my_node * node_ptr;
typedef const my_node * const_node_ptr;
static node_ptr get_parent(const_node_ptr n) { return n->parent_; }
static void set_parent(node_ptr n, node_ptr parent){ n->parent_ = parent; }
static node_ptr get_left(const_node_ptr n) { return n->left_; }
static void set_left(node_ptr n, node_ptr left) { n->left_ = left; }
static node_ptr get_right(const_node_ptr n) { return n->right_; }
static void set_right(node_ptr n, node_ptr right) { n->right_ = right; }
};
struct node_ptr_compare
{
bool operator()(const my_node *a, const my_node *b)
{ return a->int_ < b->int_; }
};
int main()
{
typedef boost::intrusive::splaytree_algorithms<my_splaytree_node_traits> algo;
my_node header, two(2), three(3);
//Create an empty splaytree container:
//"header" will be the header node of the tree
algo::init_header(&header);
//Now insert node "two" in the tree using the sorting functor
algo::insert_equal_upper_bound(&header, &two, node_ptr_compare());
//Now insert node "three" in the tree using the sorting functor
algo::insert_equal_lower_bound(&header, &three, node_ptr_compare());
//Now take the first node (the left node of the header)
my_node *n = header.left_;
assert(n == &two);
//Now go to the next node
n = algo::next_node(n);
assert(n == &three);
//Erase a node just using a pointer to it
algo::unlink(&two);
//Erase a node using also the header (faster)
algo::erase(&header, &three);
return 0;
}
//]

View File

@@ -0,0 +1,87 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2007-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_stateful_value_traits
#include <boost/intrusive/list.hpp>
using namespace boost::intrusive;
//This type is not modifiable so we can't store hooks or custom nodes
typedef int identifier_t;
//This value traits will associate elements from an array of identifiers with
//elements of an array of nodes. The element i of the value array will use the
//node i of the node array:
struct stateful_value_traits
{
typedef list_node_traits<void*> node_traits;
typedef node_traits::node node;
typedef node * node_ptr;
typedef const node * const_node_ptr;
typedef identifier_t value_type;
typedef identifier_t * pointer;
typedef const identifier_t * const_pointer;
static const link_mode_type link_mode = normal_link;
stateful_value_traits(pointer ids, node_ptr node_array)
: ids_(ids), nodes_(node_array)
{}
///Note: non static functions!
node_ptr to_node_ptr (value_type &value) const
{ return this->nodes_ + (&value - this->ids_); }
const_node_ptr to_node_ptr (const value_type &value) const
{ return this->nodes_ + (&value - this->ids_); }
pointer to_value_ptr(node_ptr n) const
{ return this->ids_ + (n - this->nodes_); }
const_pointer to_value_ptr(const_node_ptr n) const
{ return this->ids_ + (n - this->nodes_); }
private:
pointer ids_;
node_ptr nodes_;
};
int main()
{
const int NumElements = 100;
//This is an array of ids that we want to "store"
identifier_t ids [NumElements];
//This is an array of nodes that is necessary to form the linked list
list_node_traits<void*>::node nodes [NumElements];
//Initialize id objects, each one with a different number
for(int i = 0; i != NumElements; ++i) ids[i] = i;
//Define a list that will "link" identifiers using external nodes
typedef list<identifier_t, value_traits<stateful_value_traits> > List;
//This list will store ids without modifying identifier_t instances
//Stateful value traits must be explicitly passed in the constructor.
List my_list (stateful_value_traits (ids, nodes));
//Insert ids in reverse order in the list
for(identifier_t * it(&ids[0]), *itend(&ids[NumElements]); it != itend; ++it)
my_list.push_front(*it);
//Now test lists
List::const_iterator list_it (my_list.cbegin());
identifier_t *it_val(&ids[NumElements]), *it_rbeg_val(&ids[0]);
//Test the objects inserted in the base hook list
for(; it_val != it_rbeg_val; --it_val, ++list_it)
if(&*list_it != &it_val[-1]) return 1;
return 0;
}
//]

View File

@@ -0,0 +1,79 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2007-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_treap_algorithms_code
#include <boost/intrusive/treap_algorithms.hpp>
#include <cassert>
struct my_node
{
my_node(int i = 0, int priority = 0)
: prio_(priority), int_(i)
{}
my_node *parent_, *left_, *right_;
int prio_;
//other members
int int_;
};
//Define our own treap_node_traits
struct my_treap_node_traits
{
typedef my_node node;
typedef my_node * node_ptr;
typedef const my_node * const_node_ptr;
static node_ptr get_parent(const_node_ptr n) { return n->parent_; }
static void set_parent(node_ptr n, node_ptr parent){ n->parent_ = parent; }
static node_ptr get_left(const_node_ptr n) { return n->left_; }
static void set_left(node_ptr n, node_ptr left) { n->left_ = left; }
static node_ptr get_right(const_node_ptr n) { return n->right_; }
static void set_right(node_ptr n, node_ptr right) { n->right_ = right; }
};
struct node_ptr_compare
{ bool operator()(const my_node *a, const my_node *b) { return a->int_ < b->int_; } };
struct node_ptr_priority
{ bool operator()(const my_node *a, const my_node *b) { return a->prio_ < b->prio_;} };
int main()
{
typedef boost::intrusive::treap_algorithms<my_treap_node_traits> algo;
my_node header, two(2, 5), three(3, 1);
//Create an empty treap container:
//"header" will be the header node of the tree
algo::init_header(&header);
//Now insert node "two" in the tree using the sorting functor
algo::insert_equal_upper_bound(&header, &two, node_ptr_compare(), node_ptr_priority());
//Now insert node "three" in the tree using the sorting functor
algo::insert_equal_lower_bound(&header, &three, node_ptr_compare(), node_ptr_priority());
//Now take the first node (the left node of the header)
my_node *n = header.left_;
assert(n == &two);
//Now go to the next node
n = algo::next_node(n);
assert(n == &three);
//Erase a node just using a pointer to it
algo::unlink(&two, node_ptr_priority());
//Erase a node using also the header (faster)
algo::erase(&header, &three, node_ptr_priority());
return 0;
}
//]

View File

@@ -0,0 +1,106 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_treap_set_code
#include <boost/intrusive/treap_set.hpp>
#include <vector>
#include <functional>
#include <cassert>
using namespace boost::intrusive;
class MyClass : public bs_set_base_hook<> //This is a base hook
{
int int_;
unsigned int prio_;
public:
//This is a member hook
bs_set_member_hook<> member_hook_;
MyClass(int i, unsigned int prio) : int_(i), prio_(prio)
{}
unsigned int get_priority() const
{ return this->prio_; }
//Less and greater operators
friend bool operator< (const MyClass &a, const MyClass &b)
{ return a.int_ < b.int_; }
friend bool operator> (const MyClass &a, const MyClass &b)
{ return a.int_ > b.int_; }
//Default priority compare
friend bool priority_order (const MyClass &a, const MyClass &b)
{ return a.prio_ < b.prio_; } //Lower value means higher priority
//Inverse priority compare
friend bool priority_inverse_order (const MyClass &a, const MyClass &b)
{ return a.prio_ > b.prio_; } //Higher value means higher priority
};
struct inverse_priority
{
bool operator()(const MyClass &a, const MyClass &b) const
{ return priority_inverse_order(a, b); }
};
//Define an treap_set using the base hook that will store values in reverse order
typedef treap_set< MyClass, compare<std::greater<MyClass> > > BaseSet;
//Define an multiset using the member hook that will store
typedef member_hook<MyClass, bs_set_member_hook<>, &MyClass::member_hook_> MemberOption;
typedef treap_multiset
< MyClass, MemberOption, priority<inverse_priority> > MemberMultiset;
int main()
{
typedef std::vector<MyClass>::iterator VectIt;
//Create several MyClass objects, each one with a different value
std::vector<MyClass> values;
for(std::size_t i = 0; i < 100u; ++i) values.push_back(MyClass((int)i, unsigned(i % 10)));
BaseSet baseset;
MemberMultiset membermultiset;
//Now insert them in the sets
for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it){
baseset.insert(*it);
membermultiset.insert(*it);
}
//Now test treap_sets
{
BaseSet::reverse_iterator rbit(baseset.rbegin());
MemberMultiset::iterator mit(membermultiset.begin());
VectIt it(values.begin()), itend(values.end());
//Test the objects inserted in the base hook treap_set
for(; it != itend; ++it, ++rbit)
if(&*rbit != &*it) return 1;
//Test the objects inserted in the member hook treap_set
for(it = values.begin(); it != itend; ++it, ++mit)
if(&*mit != &*it) return 1;
//Test priority order
for(int i = 0; i < 100; ++i){
if(baseset.top()->get_priority() != static_cast<unsigned int>(i/10))
return 1;
if(membermultiset.top()->get_priority() != 9u - static_cast<unsigned int>(i/10))
return 1;
baseset.erase(baseset.top());
membermultiset.erase(membermultiset.top());
}
}
return 0;
}
//]

View File

@@ -0,0 +1,92 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_unordered_set_code
#include <boost/intrusive/unordered_set.hpp>
#include <vector>
#include <functional>
#include <boost/container_hash/hash.hpp>
using namespace boost::intrusive;
class MyClass : public unordered_set_base_hook<>
{ //This is a derivation hook
int int_;
public:
unordered_set_member_hook<> member_hook_; //This is a member hook
MyClass(int i)
: int_(i)
{}
friend bool operator== (const MyClass &a, const MyClass &b)
{ return a.int_ == b.int_; }
friend std::size_t hash_value(const MyClass &value)
{ return std::size_t(value.int_); }
};
//Define an unordered_set that will store MyClass objects using the base hook
typedef unordered_set<MyClass> BaseSet;
//Define an unordered_multiset that will store MyClass using the member hook
typedef member_hook<MyClass, unordered_set_member_hook<>, &MyClass::member_hook_>
MemberOption;
typedef unordered_multiset< MyClass, MemberOption> MemberMultiSet;
int main()
{
typedef std::vector<MyClass>::iterator VectIt;
//Create a vector with 100 different MyClass objects
std::vector<MyClass> values;
for(int i = 0; i < 100; ++i) values.push_back(MyClass(i));
//Create a copy of the vector
std::vector<MyClass> values2(values);
//Create a bucket array for base_set
BaseSet::bucket_type base_buckets[100];
//Create a bucket array for member_multi_set
MemberMultiSet::bucket_type member_buckets[200];
//Create unordered containers taking buckets as arguments
BaseSet base_set(BaseSet::bucket_traits(base_buckets, 100));
MemberMultiSet member_multi_set
(MemberMultiSet::bucket_traits(member_buckets, 200));
//Now insert values's elements in the unordered_set
for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it)
base_set.insert(*it);
//Now insert values's and values2's elements in the unordered_multiset
for(VectIt it(values.begin()), itend(values.end()), it2(values2.begin())
; it != itend; ++it, ++it2){
member_multi_set.insert(*it);
member_multi_set.insert(*it2);
}
//Now find every element
{
VectIt it(values.begin()), itend(values.end());
for(; it != itend; ++it){
//base_set should contain one element for each key
if(base_set.count(*it) != 1) return 1;
//member_multi_set should contain two elements for each key
if(member_multi_set.count(*it) != 2) return 1;
}
}
return 0;
}
//]

View File

@@ -0,0 +1,118 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_value_traits_code_legacy
#include <boost/intrusive/link_mode.hpp>
#include <boost/intrusive/list.hpp>
#include <boost/intrusive/slist.hpp>
//<-
#include <boost/intrusive/trivial_value_traits.hpp>
//->
#include <vector>
//This node is the legacy type we can't modify and we want to insert in
//intrusive list and slist containers using only two pointers, since
//we know the object will never be at the same time in both lists.
struct legacy_value
{
legacy_value *prev_;
legacy_value *next_;
int id_;
};
//]
//[doc_value_traits_value_traits
//Define our own NodeTraits that will configure singly and doubly linked
//list algorithms. Note that this node traits is compatible with
//circular_slist_algorithms and circular_list_algorithms.
namespace bi = boost::intrusive;
struct legacy_node_traits
{
typedef legacy_value node;
typedef legacy_value * node_ptr;
typedef const legacy_value * const_node_ptr;
static node *get_next(const node *n) { return n->next_; }
static void set_next(node *n, node *next) { n->next_ = next; }
static node *get_previous(const node *n) { return n->prev_; }
static void set_previous(node *n, node *prev) { n->prev_ = prev; }
};
//This ValueTraits will configure list and slist. In this case,
//legacy_node_traits::node is the same as the
//legacy_value_traits::value_type so to_node_ptr/to_value_ptr
//functions are trivial.
struct legacy_value_traits
{
typedef legacy_node_traits node_traits;
typedef node_traits::node_ptr node_ptr;
typedef node_traits::const_node_ptr const_node_ptr;
typedef legacy_value value_type;
typedef legacy_value * pointer;
typedef const legacy_value * const_pointer;
static const bi::link_mode_type link_mode = bi::normal_link;
static node_ptr to_node_ptr (value_type &value) { return node_ptr(&value); }
static const_node_ptr to_node_ptr (const value_type &value) { return const_node_ptr(&value); }
static pointer to_value_ptr(node_ptr n) { return pointer(n); }
static const_pointer to_value_ptr(const_node_ptr n) { return const_pointer(n); }
};
//]
//[doc_value_traits_trivial
typedef bi::trivial_value_traits<legacy_node_traits, bi::normal_link> trivial_legacy_value_traits;
//]
//[doc_value_traits_test
//Now define an intrusive list and slist that will store legacy_value objects
typedef bi::value_traits<legacy_value_traits> ValueTraitsOption;
typedef bi::value_traits<trivial_legacy_value_traits> TrivialValueTraitsOption;
typedef bi::list<legacy_value, ValueTraitsOption> LegacyAbiList;
typedef bi::slist<legacy_value, ValueTraitsOption> LegacyAbiSlist;
typedef bi::list<legacy_value, TrivialValueTraitsOption> TrivialLegacyAbiList;
typedef bi::slist<legacy_value, TrivialValueTraitsOption> TrivialLegacyAbiSlist;
template<class List>
bool test_list()
{
typedef std::vector<legacy_value> Vect;
//Create legacy_value objects, with a different internal number
Vect legacy_vector;
for(int i = 0; i < 100; ++i){
legacy_value value; value.id_ = i; legacy_vector.push_back(value);
}
//Create the list with the objects
List mylist(legacy_vector.begin(), legacy_vector.end());
//Now test both lists
typename List::const_iterator bit(mylist.begin()), bitend(mylist.end());
typename Vect::const_iterator it(legacy_vector.begin()), itend(legacy_vector.end());
//Test the objects inserted in our list
for(; it != itend; ++it, ++bit)
if(&*bit != &*it) return false;
return true;
}
int main()
{
return test_list<LegacyAbiList>() && test_list<LegacyAbiSlist>() &&
test_list<TrivialLegacyAbiList>() && test_list<TrivialLegacyAbiSlist>()
? 0 : 1;
}
//]

View File

@@ -0,0 +1,83 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_window_code
#include <boost/intrusive/list.hpp>
using namespace boost::intrusive;
//An abstract class that can be inserted in an intrusive list
class Window : public list_base_hook<>
{
public:
//This is a container those value is an abstract class: you can't do this with std::list.
typedef list<Window> win_list;
//A static intrusive list declaration
static win_list all_windows;
//Constructor. Includes this window in the list
Window() { all_windows.push_back(*this); }
//Destructor. Removes this node from the list
virtual ~Window() { all_windows.erase(win_list::s_iterator_to(*this)); }
//Pure virtual function to be implemented by derived classes
virtual void Paint() = 0;
};
//The static intrusive list declaration
Window::win_list Window::all_windows;
//Some Window derived classes
class FrameWindow : public Window
{ virtual void Paint() BOOST_OVERRIDE {/**/} };
class EditWindow : public Window
{ virtual void Paint() BOOST_OVERRIDE {/**/} };
class CanvasWindow : public Window
{ virtual void Paint() BOOST_OVERRIDE {/**/} };
//A function that prints all windows stored in the intrusive list
void paint_all_windows()
{
for(Window::win_list::iterator i(Window::all_windows.begin())
, e(Window::all_windows.end())
; i != e; ++i)
i->Paint();
}
//...
//A class derived from Window
class MainWindow : public Window
{
FrameWindow frame_; //these are derived from Window too
EditWindow edit_;
CanvasWindow canvas_;
public:
void Paint() BOOST_OVERRIDE {/**/}
//...
};
//Main function
int main()
{
//When a Window class is created, is automatically registered in the global list
MainWindow window;
//Paint all the windows, sub-windows and so on
paint_all_windows();
//All the windows are automatically unregistered in their destructors.
return 0;
}
//]

View File

@@ -0,0 +1,338 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_ANY_HOOK_HPP
#define BOOST_INTRUSIVE_ANY_HOOK_HPP
#include <boost/intrusive/detail/config_begin.hpp>
#include <boost/intrusive/intrusive_fwd.hpp>
#include <boost/intrusive/detail/any_node_and_algorithms.hpp>
#include <boost/intrusive/options.hpp>
#include <boost/intrusive/detail/generic_hook.hpp>
#include <boost/intrusive/detail/mpl.hpp>
#include <boost/intrusive/pointer_rebind.hpp>
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
namespace boost {
namespace intrusive {
//! Helper metafunction to define a \c \c any_base_hook that yields to the same
//! type when the same options (either explicitly or implicitly) are used.
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template<class ...Options>
#else
template<class O1 = void, class O2 = void, class O3 = void>
#endif
struct make_any_base_hook
{
/// @cond
typedef typename pack_options
< hook_defaults,
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
O1, O2, O3
#else
Options...
#endif
>::type packed_options;
typedef generic_hook
< AnyAlgorithm
, any_node_traits<typename packed_options::void_pointer>
, typename packed_options::tag
, packed_options::link_mode
, AnyBaseHookId
> implementation_defined;
/// @endcond
typedef implementation_defined type;
};
//! Derive a class from this hook in order to store objects of that class
//! in an intrusive container.
//!
//! The hook admits the following options: \c tag<>, \c void_pointer<> and
//! \c link_mode<>.
//!
//! \c tag<> defines a tag to identify the node.
//! The same tag value can be used in different classes, but if a class is
//! derived from more than one \c any_base_hook, then each \c any_base_hook needs its
//! unique tag.
//!
//! \c link_mode<> will specify the linking mode of the hook (\c normal_link, \c safe_link).
//!
//! \c void_pointer<> is the pointer type that will be used internally in the hook
//! and the container configured to use this hook.
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template<class ...Options>
#else
template<class O1, class O2, class O3>
#endif
class any_base_hook
: public make_any_base_hook
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
<O1, O2, O3>
#else
<Options...>
#endif
::type
{
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
public:
//! <b>Effects</b>: If link_mode is or \c safe_link
//! initializes the node to an unlinked state.
//!
//! <b>Throws</b>: Nothing.
any_base_hook();
//! <b>Effects</b>: If link_mode is or \c safe_link
//! initializes the node to an unlinked state. The argument is ignored.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Rationale</b>: Providing a copy-constructor
//! makes classes using the hook STL-compliant without forcing the
//! user to do some additional work. \c swap can be used to emulate
//! move-semantics.
any_base_hook(const any_base_hook& );
//! <b>Effects</b>: Empty function. The argument is ignored.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Rationale</b>: Providing an assignment operator
//! makes classes using the hook STL-compliant without forcing the
//! user to do some additional work. \c swap can be used to emulate
//! move-semantics.
any_base_hook& operator=(const any_base_hook& );
//! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
//! nothing (ie. no code is generated). If link_mode is \c safe_link and the
//! object is stored in a container an assertion is raised.
//!
//! <b>Throws</b>: Nothing.
~any_base_hook();
//! <b>Precondition</b>: link_mode must be \c safe_link.
//!
//! <b>Returns</b>: true, if the node belongs to a container, false
//! otherwise. This function can be used to test whether \c container::iterator_to
//! will return a valid iterator.
//!
//! <b>Complexity</b>: Constant
bool is_linked() const;
#endif
};
//! Helper metafunction to define a \c \c any_member_hook that yields to the same
//! type when the same options (either explicitly or implicitly) are used.
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template<class ...Options>
#else
template<class O1 = void, class O2 = void, class O3 = void>
#endif
struct make_any_member_hook
{
/// @cond
typedef typename pack_options
< hook_defaults,
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
O1, O2, O3
#else
Options...
#endif
>::type packed_options;
typedef generic_hook
< AnyAlgorithm
, any_node_traits<typename packed_options::void_pointer>
, member_tag
, packed_options::link_mode
, NoBaseHookId
> implementation_defined;
/// @endcond
typedef implementation_defined type;
};
//! Store this hook in a class to be inserted
//! in an intrusive container.
//!
//! The hook admits the following options: \c void_pointer<> and
//! \c link_mode<>.
//!
//! \c link_mode<> will specify the linking mode of the hook (\c normal_link or \c safe_link).
//!
//! \c void_pointer<> is the pointer type that will be used internally in the hook
//! and the container configured to use this hook.
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template<class ...Options>
#else
template<class O1, class O2, class O3>
#endif
class any_member_hook
: public make_any_member_hook
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
<O1, O2, O3>
#else
<Options...>
#endif
::type
{
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
public:
//! <b>Effects</b>: If link_mode is or \c safe_link
//! initializes the node to an unlinked state.
//!
//! <b>Throws</b>: Nothing.
any_member_hook() BOOST_NOEXCEPT;
//! <b>Effects</b>: If link_mode is or \c safe_link
//! initializes the node to an unlinked state. The argument is ignored.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Rationale</b>: Providing a copy-constructor
//! makes classes using the hook STL-compliant without forcing the
//! user to do some additional work. \c swap can be used to emulate
//! move-semantics.
any_member_hook(const any_member_hook&) BOOST_NOEXCEPT;
//! <b>Effects</b>: Empty function. The argument is ignored.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Rationale</b>: Providing an assignment operator
//! makes classes using the hook STL-compliant without forcing the
//! user to do some additional work. \c swap can be used to emulate
//! move-semantics.
any_member_hook& operator=(const any_member_hook&) BOOST_NOEXCEPT;
//! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
//! nothing (ie. no code is generated). If link_mode is \c safe_link and the
//! object is stored in a container an assertion is raised.
//!
//! <b>Throws</b>: Nothing.
~any_member_hook();
//! <b>Precondition</b>: link_mode must be \c safe_link.
//!
//! <b>Returns</b>: true, if the node belongs to a container, false
//! otherwise. This function can be used to test whether \c container::iterator_to
//! will return a valid iterator.
//!
//! <b>Complexity</b>: Constant
bool is_linked() const BOOST_NOEXCEPT;
#endif
};
/// @cond
namespace detail{
BOOST_INTRUSIVE_INTERNAL_STATIC_BOOL_IS_TRUE(old_proto_value_traits_base_hook, hooktags::is_base_hook)
//!This option setter specifies that the container
//!must use the specified base hook
template<class BasicHook, template <class> class NodeTraits>
struct any_to_some_hook
{
typedef typename BasicHook::template pack<empty>::proto_value_traits old_proto_value_traits;
template<class Base>
struct pack : public Base
{
struct proto_value_traits
{
//proto_value_traits::hooktags::is_base_hook is used by get_value_traits
//to detect base hooks, so mark it in case BasicHook has it.
struct hooktags
{
static const bool is_base_hook = old_proto_value_traits_base_hook_bool_is_true
<old_proto_value_traits>::value;
};
typedef old_proto_value_traits basic_hook_t;
static const bool is_any_hook = true;
template<class VoidPtr>
struct node_traits_from_voidptr
{ typedef NodeTraits<VoidPtr> type; };
};
};
};
} //namespace detail{
/// @endcond
//!This option setter specifies that
//!any hook should behave as an slist hook
template<class BasicHook>
struct any_to_slist_hook
/// @cond
: public detail::any_to_some_hook<BasicHook, any_slist_node_traits>
/// @endcond
{};
//!This option setter specifies that
//!any hook should behave as an list hook
template<class BasicHook>
struct any_to_list_hook
/// @cond
: public detail::any_to_some_hook<BasicHook, any_list_node_traits>
/// @endcond
{};
//!This option setter specifies that
//!any hook should behave as a set hook
template<class BasicHook>
struct any_to_set_hook
/// @cond
: public detail::any_to_some_hook<BasicHook, any_rbtree_node_traits>
/// @endcond
{};
//!This option setter specifies that
//!any hook should behave as an avl_set hook
template<class BasicHook>
struct any_to_avl_set_hook
/// @cond
: public detail::any_to_some_hook<BasicHook, any_avltree_node_traits>
/// @endcond
{};
//!This option setter specifies that any
//!hook should behave as a bs_set hook
template<class BasicHook>
struct any_to_bs_set_hook
/// @cond
: public detail::any_to_some_hook<BasicHook, any_tree_node_traits>
/// @endcond
{};
//!This option setter specifies that any hook
//!should behave as an unordered set hook
template<class BasicHook>
struct any_to_unordered_set_hook
/// @cond
: public detail::any_to_some_hook<BasicHook, any_unordered_node_traits>
/// @endcond
{};
} //namespace intrusive
} //namespace boost
#include <boost/intrusive/detail/config_end.hpp>
#endif //BOOST_INTRUSIVE_ANY_HOOK_HPP

View File

@@ -0,0 +1,293 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2007-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_AVL_SET_HOOK_HPP
#define BOOST_INTRUSIVE_AVL_SET_HOOK_HPP
#include <boost/intrusive/detail/config_begin.hpp>
#include <boost/intrusive/intrusive_fwd.hpp>
#include <boost/intrusive/detail/avltree_node.hpp>
#include <boost/intrusive/avltree_algorithms.hpp>
#include <boost/intrusive/options.hpp>
#include <boost/intrusive/detail/generic_hook.hpp>
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
namespace boost {
namespace intrusive {
//! Helper metafunction to define a \c avl_set_base_hook that yields to the same
//! type when the same options (either explicitly or implicitly) are used.
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template<class ...Options>
#else
template<class O1 = void, class O2 = void, class O3 = void, class O4 = void>
#endif
struct make_avl_set_base_hook
{
/// @cond
typedef typename pack_options
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
<hook_defaults, O1, O2, O3, O4>
#else
<hook_defaults, Options...>
#endif
::type packed_options;
typedef generic_hook
< AvlTreeAlgorithms
, avltree_node_traits<typename packed_options::void_pointer, packed_options::optimize_size>
, typename packed_options::tag
, packed_options::link_mode
, AvlTreeBaseHookId
> implementation_defined;
/// @endcond
typedef implementation_defined type;
};
//! Derive a class from avl_set_base_hook in order to store objects in
//! in an avl_set/avl_multiset. avl_set_base_hook holds the data necessary to maintain
//! the avl_set/avl_multiset and provides an appropriate value_traits class for avl_set/avl_multiset.
//!
//! The hook admits the following options: \c tag<>, \c void_pointer<>,
//! \c link_mode<> and \c optimize_size<>.
//!
//! \c tag<> defines a tag to identify the node.
//! The same tag value can be used in different classes, but if a class is
//! derived from more than one \c list_base_hook, then each \c list_base_hook needs its
//! unique tag.
//!
//! \c void_pointer<> is the pointer type that will be used internally in the hook
//! and the container configured to use this hook.
//!
//! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
//! \c auto_unlink or \c safe_link).
//!
//! \c optimize_size<> will tell the hook to optimize the hook for size instead
//! of speed.
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template<class ...Options>
#else
template<class O1, class O2, class O3, class O4>
#endif
class avl_set_base_hook
: public make_avl_set_base_hook
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
<O1, O2, O3, O4>
#else
<Options...>
#endif
::type
{
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
public:
//! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
//! initializes the node to an unlinked state.
//!
//! <b>Throws</b>: Nothing.
avl_set_base_hook();
//! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
//! initializes the node to an unlinked state. The argument is ignored.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Rationale</b>: Providing a copy-constructor
//! makes classes using the hook STL-compliant without forcing the
//! user to do some additional work. \c swap can be used to emulate
//! move-semantics.
avl_set_base_hook(const avl_set_base_hook& );
//! <b>Effects</b>: Empty function. The argument is ignored.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Rationale</b>: Providing an assignment operator
//! makes classes using the hook STL-compliant without forcing the
//! user to do some additional work. \c swap can be used to emulate
//! move-semantics.
avl_set_base_hook& operator=(const avl_set_base_hook& );
//! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
//! nothing (ie. no code is generated). If link_mode is \c safe_link and the
//! object is stored in a set an assertion is raised. If link_mode is
//! \c auto_unlink and \c is_linked() is true, the node is unlinked.
//!
//! <b>Throws</b>: Nothing.
~avl_set_base_hook();
//! <b>Effects</b>: Swapping two nodes swaps the position of the elements
//! related to those nodes in one or two containers. That is, if the node
//! this is part of the element e1, the node x is part of the element e2
//! and both elements are included in the containers s1 and s2, then after
//! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
//! at the position of e1. If one element is not in a container, then
//! after the swap-operation the other element is not in a container.
//! Iterators to e1 and e2 related to those nodes are invalidated.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
void swap_nodes(avl_set_base_hook &other);
//! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
//!
//! <b>Returns</b>: true, if the node belongs to a container, false
//! otherwise. This function can be used to test whether \c set::iterator_to
//! will return a valid iterator.
//!
//! <b>Complexity</b>: Constant
bool is_linked() const;
//! <b>Effects</b>: Removes the node if it's inserted in a container.
//! This function is only allowed if link_mode is \c auto_unlink.
//!
//! <b>Throws</b>: Nothing.
void unlink();
#endif
};
//! Helper metafunction to define a \c avl_set_member_hook that yields to the same
//! type when the same options (either explicitly or implicitly) are used.
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template<class ...Options>
#else
template<class O1 = void, class O2 = void, class O3 = void, class O4 = void>
#endif
struct make_avl_set_member_hook
{
/// @cond
typedef typename pack_options
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
<hook_defaults, O1, O2, O3, O4>
#else
<hook_defaults, Options...>
#endif
::type packed_options;
typedef generic_hook
< AvlTreeAlgorithms
, avltree_node_traits<typename packed_options::void_pointer, packed_options::optimize_size>
, member_tag
, packed_options::link_mode
, NoBaseHookId
> implementation_defined;
/// @endcond
typedef implementation_defined type;
};
//! Put a public data member avl_set_member_hook in order to store objects of this class in
//! an avl_set/avl_multiset. avl_set_member_hook holds the data necessary for maintaining the
//! avl_set/avl_multiset and provides an appropriate value_traits class for avl_set/avl_multiset.
//!
//! The hook admits the following options: \c void_pointer<>,
//! \c link_mode<> and \c optimize_size<>.
//!
//! \c void_pointer<> is the pointer type that will be used internally in the hook
//! and the container configured to use this hook.
//!
//! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
//! \c auto_unlink or \c safe_link).
//!
//! \c optimize_size<> will tell the hook to optimize the hook for size instead
//! of speed.
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template<class ...Options>
#else
template<class O1, class O2, class O3, class O4>
#endif
class avl_set_member_hook
: public make_avl_set_member_hook
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
<O1, O2, O3, O4>
#else
<Options...>
#endif
::type
{
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
public:
//! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
//! initializes the node to an unlinked state.
//!
//! <b>Throws</b>: Nothing.
avl_set_member_hook();
//! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
//! initializes the node to an unlinked state. The argument is ignored.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Rationale</b>: Providing a copy-constructor
//! makes classes using the hook STL-compliant without forcing the
//! user to do some additional work. \c swap can be used to emulate
//! move-semantics.
avl_set_member_hook(const avl_set_member_hook& );
//! <b>Effects</b>: Empty function. The argument is ignored.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Rationale</b>: Providing an assignment operator
//! makes classes using the hook STL-compliant without forcing the
//! user to do some additional work. \c swap can be used to emulate
//! move-semantics.
avl_set_member_hook& operator=(const avl_set_member_hook& );
//! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
//! nothing (ie. no code is generated). If link_mode is \c safe_link and the
//! object is stored in a set an assertion is raised. If link_mode is
//! \c auto_unlink and \c is_linked() is true, the node is unlinked.
//!
//! <b>Throws</b>: Nothing.
~avl_set_member_hook();
//! <b>Effects</b>: Swapping two nodes swaps the position of the elements
//! related to those nodes in one or two containers. That is, if the node
//! this is part of the element e1, the node x is part of the element e2
//! and both elements are included in the containers s1 and s2, then after
//! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
//! at the position of e1. If one element is not in a container, then
//! after the swap-operation the other element is not in a container.
//! Iterators to e1 and e2 related to those nodes are invalidated.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
void swap_nodes(avl_set_member_hook &other);
//! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
//!
//! <b>Returns</b>: true, if the node belongs to a container, false
//! otherwise. This function can be used to test whether \c set::iterator_to
//! will return a valid iterator.
//!
//! <b>Complexity</b>: Constant
bool is_linked() const;
//! <b>Effects</b>: Removes the node if it's inserted in a container.
//! This function is only allowed if link_mode is \c auto_unlink.
//!
//! <b>Throws</b>: Nothing.
void unlink();
#endif
};
} //namespace intrusive
} //namespace boost
#include <boost/intrusive/detail/config_end.hpp>
#endif //BOOST_INTRUSIVE_AVL_SET_HOOK_HPP

View File

@@ -0,0 +1,588 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2007-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_AVLTREE_HPP
#define BOOST_INTRUSIVE_AVLTREE_HPP
#include <boost/intrusive/detail/config_begin.hpp>
#include <boost/intrusive/intrusive_fwd.hpp>
#include <cstddef>
#include <boost/intrusive/detail/minimal_less_equal_header.hpp>
#include <boost/intrusive/detail/minimal_pair_header.hpp>
#include <boost/static_assert.hpp>
#include <boost/intrusive/avl_set_hook.hpp>
#include <boost/intrusive/detail/avltree_node.hpp>
#include <boost/intrusive/bstree.hpp>
#include <boost/intrusive/detail/tree_node.hpp>
#include <boost/intrusive/detail/ebo_functor_holder.hpp>
#include <boost/intrusive/detail/mpl.hpp>
#include <boost/intrusive/pointer_traits.hpp>
#include <boost/intrusive/detail/get_value_traits.hpp>
#include <boost/intrusive/avltree_algorithms.hpp>
#include <boost/intrusive/link_mode.hpp>
#include <boost/move/utility_core.hpp>
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
namespace boost {
namespace intrusive {
/// @cond
struct default_avltree_hook_applier
{ template <class T> struct apply{ typedef typename T::default_avltree_hook type; }; };
template<>
struct is_default_hook_tag<default_avltree_hook_applier>
{ static const bool value = true; };
struct avltree_defaults
: bstree_defaults
{
typedef default_avltree_hook_applier proto_value_traits;
};
/// @endcond
//! The class template avltree is an intrusive AVL tree container, that
//! is used to construct intrusive avl_set and avl_multiset containers.
//! The no-throw guarantee holds only, if the key_compare object
//! doesn't throw.
//!
//! The template parameter \c T is the type to be managed by the container.
//! The user can specify additional options and if no options are provided
//! default options are used.
//!
//! The container supports the following options:
//! \c base_hook<>/member_hook<>/value_traits<>,
//! \c constant_time_size<>, \c size_type<> and
//! \c compare<>.
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
template<class T, class ...Options>
#else
template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyComp, class SizeType, bool ConstantTimeSize, typename HeaderHolder>
#endif
class avltree_impl
/// @cond
: public bstree_impl<ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, SizeType, ConstantTimeSize, AvlTreeAlgorithms, HeaderHolder>
/// @endcond
{
public:
typedef ValueTraits value_traits;
/// @cond
typedef bstree_impl< ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, SizeType
, ConstantTimeSize, AvlTreeAlgorithms
, HeaderHolder> tree_type;
typedef tree_type implementation_defined;
/// @endcond
typedef typename implementation_defined::pointer pointer;
typedef typename implementation_defined::const_pointer const_pointer;
typedef typename implementation_defined::value_type value_type;
typedef typename implementation_defined::key_type key_type;
typedef typename implementation_defined::key_of_value key_of_value;
typedef typename implementation_defined::reference reference;
typedef typename implementation_defined::const_reference const_reference;
typedef typename implementation_defined::difference_type difference_type;
typedef typename implementation_defined::size_type size_type;
typedef typename implementation_defined::value_compare value_compare;
typedef typename implementation_defined::key_compare key_compare;
typedef typename implementation_defined::iterator iterator;
typedef typename implementation_defined::const_iterator const_iterator;
typedef typename implementation_defined::reverse_iterator reverse_iterator;
typedef typename implementation_defined::const_reverse_iterator const_reverse_iterator;
typedef typename implementation_defined::node_traits node_traits;
typedef typename implementation_defined::node node;
typedef typename implementation_defined::node_ptr node_ptr;
typedef typename implementation_defined::const_node_ptr const_node_ptr;
typedef typename implementation_defined::node_algorithms node_algorithms;
static const bool constant_time_size = implementation_defined::constant_time_size;
/// @cond
private:
//noncopyable
BOOST_MOVABLE_BUT_NOT_COPYABLE(avltree_impl)
/// @endcond
public:
typedef typename implementation_defined::insert_commit_data insert_commit_data;
//! @copydoc ::boost::intrusive::bstree::bstree()
avltree_impl()
: tree_type()
{}
//! @copydoc ::boost::intrusive::bstree::bstree(const key_compare &,const value_traits &)
explicit avltree_impl( const key_compare &cmp, const value_traits &v_traits = value_traits())
: tree_type(cmp, v_traits)
{}
//! @copydoc ::boost::intrusive::bstree::bstree(bool,Iterator,Iterator,const key_compare &,const value_traits &)
template<class Iterator>
avltree_impl( bool unique, Iterator b, Iterator e
, const key_compare &cmp = key_compare()
, const value_traits &v_traits = value_traits())
: tree_type(unique, b, e, cmp, v_traits)
{}
//! @copydoc ::boost::intrusive::bstree::bstree(bstree &&)
avltree_impl(BOOST_RV_REF(avltree_impl) x)
: tree_type(BOOST_MOVE_BASE(tree_type, x))
{}
//! @copydoc ::boost::intrusive::bstree::operator=(bstree &&)
avltree_impl& operator=(BOOST_RV_REF(avltree_impl) x)
{ return static_cast<avltree_impl&>(tree_type::operator=(BOOST_MOVE_BASE(tree_type, x))); }
#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
//! @copydoc ::boost::intrusive::bstree::~bstree()
~avltree_impl();
//! @copydoc ::boost::intrusive::bstree::begin()
iterator begin() BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::begin()const
const_iterator begin() const BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::cbegin()const
const_iterator cbegin() const BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::end()
iterator end() BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::end()const
const_iterator end() const BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::cend()const
const_iterator cend() const BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::rbegin()
reverse_iterator rbegin() BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::rbegin()const
const_reverse_iterator rbegin() const BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::crbegin()const
const_reverse_iterator crbegin() const BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::rend()
reverse_iterator rend() BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::rend()const
const_reverse_iterator rend() const BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::crend()const
const_reverse_iterator crend() const BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::root()
iterator root() BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::root()const
const_iterator root() const BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::croot()const
const_iterator croot() const BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(iterator)
static avltree_impl &container_from_end_iterator(iterator end_iterator) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(const_iterator)
static const avltree_impl &container_from_end_iterator(const_iterator end_iterator) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::container_from_iterator(iterator)
static avltree_impl &container_from_iterator(iterator it) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::container_from_iterator(const_iterator)
static const avltree_impl &container_from_iterator(const_iterator it) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::key_comp()const
key_compare key_comp() const;
//! @copydoc ::boost::intrusive::bstree::value_comp()const
value_compare value_comp() const;
//! @copydoc ::boost::intrusive::bstree::empty()const
bool empty() const BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::size()const
size_type size() const BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::swap
void swap(avltree_impl& other);
//! @copydoc ::boost::intrusive::bstree::clone_from(const bstree&,Cloner,Disposer)
template <class Cloner, class Disposer>
void clone_from(const avltree_impl &src, Cloner cloner, Disposer disposer);
#else //BOOST_INTRUSIVE_DOXYGEN_INVOKED
using tree_type::clone_from;
#endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
//! @copydoc ::boost::intrusive::bstree::clone_from(bstree&&,Cloner,Disposer)
template <class Cloner, class Disposer>
void clone_from(BOOST_RV_REF(avltree_impl) src, Cloner cloner, Disposer disposer)
{ tree_type::clone_from(BOOST_MOVE_BASE(tree_type, src), cloner, disposer); }
#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
//! @copydoc ::boost::intrusive::bstree::insert_equal(reference)
iterator insert_equal(reference value);
//! @copydoc ::boost::intrusive::bstree::insert_equal(const_iterator,reference)
iterator insert_equal(const_iterator hint, reference value);
//! @copydoc ::boost::intrusive::bstree::insert_equal(Iterator,Iterator)
template<class Iterator>
void insert_equal(Iterator b, Iterator e);
//! @copydoc ::boost::intrusive::bstree::insert_unique(reference)
std::pair<iterator, bool> insert_unique(reference value);
//! @copydoc ::boost::intrusive::bstree::insert_unique(const_iterator,reference)
iterator insert_unique(const_iterator hint, reference value);
//! @copydoc ::boost::intrusive::bstree::insert_unique_check(const KeyType&,KeyTypeKeyCompare,insert_commit_data&)
template<class KeyType, class KeyTypeKeyCompare>
std::pair<iterator, bool> insert_unique_check
(const KeyType &key, KeyTypeKeyCompare comp, insert_commit_data &commit_data);
//! @copydoc ::boost::intrusive::bstree::insert_unique_check(const_iterator,const KeyType&,KeyTypeKeyCompare,insert_commit_data&)
template<class KeyType, class KeyTypeKeyCompare>
std::pair<iterator, bool> insert_unique_check
(const_iterator hint, const KeyType &key
,KeyTypeKeyCompare comp, insert_commit_data &commit_data);
//! @copydoc ::boost::intrusive::bstree::insert_unique_check(const key_type&,insert_commit_data&)
std::pair<iterator, bool> insert_unique_check
(const key_type &key, insert_commit_data &commit_data);
//! @copydoc ::boost::intrusive::bstree::insert_unique_check(const_iterator,const key_type&,insert_commit_data&)
std::pair<iterator, bool> insert_unique_check
(const_iterator hint, const key_type &key, insert_commit_data &commit_data);
//! @copydoc ::boost::intrusive::bstree::insert_unique_commit
iterator insert_unique_commit(reference value, const insert_commit_data &commit_data) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::insert_unique(Iterator,Iterator)
template<class Iterator>
void insert_unique(Iterator b, Iterator e);
//! @copydoc ::boost::intrusive::bstree::insert_before
iterator insert_before(const_iterator pos, reference value) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::push_back
void push_back(reference value) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::push_front
void push_front(reference value) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::erase(const_iterator)
iterator erase(const_iterator i) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::erase(const_iterator,const_iterator)
iterator erase(const_iterator b, const_iterator e) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::erase(const key_type &)
size_type erase(const key_type &key);
//! @copydoc ::boost::intrusive::bstree::erase(const KeyType&,KeyTypeKeyCompare)
template<class KeyType, class KeyTypeKeyCompare>
size_type erase(const KeyType& key, KeyTypeKeyCompare comp);
//! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_iterator,Disposer)
template<class Disposer>
iterator erase_and_dispose(const_iterator i, Disposer disposer) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_iterator,const_iterator,Disposer)
template<class Disposer>
iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const key_type &, Disposer)
template<class Disposer>
size_type erase_and_dispose(const key_type &key, Disposer disposer);
//! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const KeyType&,KeyTypeKeyCompare,Disposer)
template<class KeyType, class KeyTypeKeyCompare, class Disposer>
size_type erase_and_dispose(const KeyType& key, KeyTypeKeyCompare comp, Disposer disposer);
//! @copydoc ::boost::intrusive::bstree::clear
void clear() BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::clear_and_dispose
template<class Disposer>
void clear_and_dispose(Disposer disposer) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::count(const key_type &ke)const
size_type count(const key_type &key) const;
//! @copydoc ::boost::intrusive::bstree::count(const KeyType&,KeyTypeKeyCompare)const
template<class KeyType, class KeyTypeKeyCompare>
size_type count(const KeyType& key, KeyTypeKeyCompare comp) const;
//! @copydoc ::boost::intrusive::bstree::lower_bound(const key_type &)
iterator lower_bound(const key_type &key);
//! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyTypeKeyCompare)
template<class KeyType, class KeyTypeKeyCompare>
iterator lower_bound(const KeyType& key, KeyTypeKeyCompare comp);
//! @copydoc ::boost::intrusive::bstree::lower_bound(const key_type &)const
const_iterator lower_bound(const key_type &key) const;
//! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyTypeKeyCompare)const
template<class KeyType, class KeyTypeKeyCompare>
const_iterator lower_bound(const KeyType& key, KeyTypeKeyCompare comp) const;
//! @copydoc ::boost::intrusive::bstree::upper_bound(const key_type &key)
iterator upper_bound(const key_type &key);
//! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyTypeKeyCompare)
template<class KeyType, class KeyTypeKeyCompare>
iterator upper_bound(const KeyType& key, KeyTypeKeyCompare comp);
//! @copydoc ::boost::intrusive::bstree::upper_bound(const key_type &)const
const_iterator upper_bound(const key_type &key) const;
//! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyTypeKeyCompare)const
template<class KeyType, class KeyTypeKeyCompare>
const_iterator upper_bound(const KeyType& key, KeyTypeKeyCompare comp) const;
//! @copydoc ::boost::intrusive::bstree::find(const key_type &)
iterator find(const key_type &key);
//! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyTypeKeyCompare)
template<class KeyType, class KeyTypeKeyCompare>
iterator find(const KeyType& key, KeyTypeKeyCompare comp);
//! @copydoc ::boost::intrusive::bstree::find(const key_type &)const
const_iterator find(const key_type &key) const;
//! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyTypeKeyCompare)const
template<class KeyType, class KeyTypeKeyCompare>
const_iterator find(const KeyType& key, KeyTypeKeyCompare comp) const;
//! @copydoc ::boost::intrusive::bstree::equal_range(const key_type &)
std::pair<iterator,iterator> equal_range(const key_type &key);
//! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyTypeKeyCompare)
template<class KeyType, class KeyTypeKeyCompare>
std::pair<iterator,iterator> equal_range(const KeyType& key, KeyTypeKeyCompare comp);
//! @copydoc ::boost::intrusive::bstree::equal_range(const key_type &)const
std::pair<const_iterator, const_iterator>
equal_range(const key_type &key) const;
//! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyTypeKeyCompare)const
template<class KeyType, class KeyTypeKeyCompare>
std::pair<const_iterator, const_iterator>
equal_range(const KeyType& key, KeyTypeKeyCompare comp) const;
//! @copydoc ::boost::intrusive::bstree::bounded_range(const key_type &,const key_type &,bool,bool)
std::pair<iterator,iterator> bounded_range
(const key_type &lower, const key_type &upper_key, bool left_closed, bool right_closed);
//! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyTypeKeyCompare,bool,bool)
template<class KeyType, class KeyTypeKeyCompare>
std::pair<iterator,iterator> bounded_range
(const KeyType& lower_key, const KeyType& upper_key, KeyTypeKeyCompare comp, bool left_closed, bool right_closed);
//! @copydoc ::boost::intrusive::bstree::bounded_range(const key_type &,const key_type &,bool,bool)const
std::pair<const_iterator, const_iterator>
bounded_range(const key_type &lower_key, const key_type &upper_key, bool left_closed, bool right_closed) const;
//! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyTypeKeyCompare,bool,bool)const
template<class KeyType, class KeyTypeKeyCompare>
std::pair<const_iterator, const_iterator> bounded_range
(const KeyType& lower_key, const KeyType& upper_key, KeyTypeKeyCompare comp, bool left_closed, bool right_closed) const;
//! @copydoc ::boost::intrusive::bstree::s_iterator_to(reference)
static iterator s_iterator_to(reference value) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::s_iterator_to(const_reference)
static const_iterator s_iterator_to(const_reference value) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::iterator_to(reference)
iterator iterator_to(reference value) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::iterator_to(const_reference)const
const_iterator iterator_to(const_reference value) const BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::init_node(reference)
static void init_node(reference value) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::unlink_leftmost_without_rebalance
pointer unlink_leftmost_without_rebalance() BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::replace_node
void replace_node(iterator replace_this, reference with_this) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::remove_node
void remove_node(reference value) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree::merge_unique(bstree<T, Options2...>&)
template<class T, class ...Options2>
void merge_unique(avltree<T, Options2...> &);
//! @copydoc ::boost::intrusive::bstree::merge_equal(bstree<T, Options2...>&)
template<class T, class ...Options2>
void merge_equal(avltree<T, Options2...> &);
friend bool operator< (const avltree_impl &x, const avltree_impl &y);
friend bool operator==(const avltree_impl &x, const avltree_impl &y);
friend bool operator!= (const avltree_impl &x, const avltree_impl &y);
friend bool operator>(const avltree_impl &x, const avltree_impl &y);
friend bool operator<=(const avltree_impl &x, const avltree_impl &y);
friend bool operator>=(const avltree_impl &x, const avltree_impl &y);
friend void swap(avltree_impl &x, avltree_impl &y);
#endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
};
//! Helper metafunction to define a \c avltree that yields to the same type when the
//! same options (either explicitly or implicitly) are used.
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template<class T, class ...Options>
#else
template<class T, class O1 = void, class O2 = void
, class O3 = void, class O4 = void
, class O5 = void, class O6 = void>
#endif
struct make_avltree
{
/// @cond
typedef typename pack_options
< avltree_defaults,
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
O1, O2, O3, O4, O5, O6
#else
Options...
#endif
>::type packed_options;
typedef typename detail::get_value_traits
<T, typename packed_options::proto_value_traits>::type value_traits;
typedef avltree_impl
< value_traits
, typename packed_options::key_of_value
, typename packed_options::compare
, typename packed_options::size_type
, packed_options::constant_time_size
, typename packed_options::header_holder_type
> implementation_defined;
/// @endcond
typedef implementation_defined type;
};
#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template<class T, class O1, class O2, class O3, class O4, class O5, class O6>
#else
template<class T, class ...Options>
#endif
class avltree
: public make_avltree<T,
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
O1, O2, O3, O4, O5, O6
#else
Options...
#endif
>::type
{
typedef typename make_avltree
<T,
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
O1, O2, O3, O4, O5, O6
#else
Options...
#endif
>::type Base;
BOOST_MOVABLE_BUT_NOT_COPYABLE(avltree)
public:
typedef typename Base::key_compare key_compare;
typedef typename Base::value_traits value_traits;
typedef typename Base::iterator iterator;
typedef typename Base::const_iterator const_iterator;
typedef typename Base::reverse_iterator reverse_iterator;
typedef typename Base::const_reverse_iterator const_reverse_iterator;
//Assert if passed value traits are compatible with the type
BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
BOOST_INTRUSIVE_FORCEINLINE avltree()
: Base()
{}
BOOST_INTRUSIVE_FORCEINLINE explicit avltree( const key_compare &cmp, const value_traits &v_traits = value_traits())
: Base(cmp, v_traits)
{}
template<class Iterator>
BOOST_INTRUSIVE_FORCEINLINE avltree( bool unique, Iterator b, Iterator e
, const key_compare &cmp = key_compare()
, const value_traits &v_traits = value_traits())
: Base(unique, b, e, cmp, v_traits)
{}
BOOST_INTRUSIVE_FORCEINLINE avltree(BOOST_RV_REF(avltree) x)
: Base(BOOST_MOVE_BASE(Base, x))
{}
BOOST_INTRUSIVE_FORCEINLINE avltree& operator=(BOOST_RV_REF(avltree) x)
{ return static_cast<avltree &>(this->Base::operator=(BOOST_MOVE_BASE(Base, x))); }
template <class Cloner, class Disposer>
BOOST_INTRUSIVE_FORCEINLINE void clone_from(const avltree &src, Cloner cloner, Disposer disposer)
{ Base::clone_from(src, cloner, disposer); }
template <class Cloner, class Disposer>
BOOST_INTRUSIVE_FORCEINLINE void clone_from(BOOST_RV_REF(avltree) src, Cloner cloner, Disposer disposer)
{ Base::clone_from(BOOST_MOVE_BASE(Base, src), cloner, disposer); }
BOOST_INTRUSIVE_FORCEINLINE static avltree &container_from_end_iterator(iterator end_iterator) BOOST_NOEXCEPT
{ return static_cast<avltree &>(Base::container_from_end_iterator(end_iterator)); }
BOOST_INTRUSIVE_FORCEINLINE static const avltree &container_from_end_iterator(const_iterator end_iterator) BOOST_NOEXCEPT
{ return static_cast<const avltree &>(Base::container_from_end_iterator(end_iterator)); }
BOOST_INTRUSIVE_FORCEINLINE static avltree &container_from_iterator(iterator it) BOOST_NOEXCEPT
{ return static_cast<avltree &>(Base::container_from_iterator(it)); }
BOOST_INTRUSIVE_FORCEINLINE static const avltree &container_from_iterator(const_iterator it) BOOST_NOEXCEPT
{ return static_cast<const avltree &>(Base::container_from_iterator(it)); }
};
#endif
} //namespace intrusive
} //namespace boost
#include <boost/intrusive/detail/config_end.hpp>
#endif //BOOST_INTRUSIVE_AVLTREE_HPP

View File

@@ -0,0 +1,727 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Daniel K. O. 2005.
// (C) Copyright Ion Gaztanaga 2007-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_AVLTREE_ALGORITHMS_HPP
#define BOOST_INTRUSIVE_AVLTREE_ALGORITHMS_HPP
#include <boost/intrusive/detail/config_begin.hpp>
#include <boost/intrusive/intrusive_fwd.hpp>
#include <cstddef>
#include <boost/intrusive/detail/assert.hpp>
#include <boost/intrusive/detail/algo_type.hpp>
#include <boost/intrusive/detail/ebo_functor_holder.hpp>
#include <boost/intrusive/bstree_algorithms.hpp>
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
namespace boost {
namespace intrusive {
/// @cond
template<class NodeTraits, class F>
struct avltree_node_cloner
//Use public inheritance to avoid MSVC bugs with closures
: public detail::ebo_functor_holder<F>
{
typedef typename NodeTraits::node_ptr node_ptr;
typedef detail::ebo_functor_holder<F> base_t;
BOOST_INTRUSIVE_FORCEINLINE avltree_node_cloner(F f)
: base_t(f)
{}
node_ptr operator()(node_ptr p)
{
node_ptr n = base_t::get()(p);
NodeTraits::set_balance(n, NodeTraits::get_balance(p));
return n;
}
node_ptr operator()(node_ptr p) const
{
node_ptr n = base_t::get()(p);
NodeTraits::set_balance(n, NodeTraits::get_balance(p));
return n;
}
};
namespace detail {
template<class ValueTraits, class NodePtrCompare, class ExtraChecker>
struct avltree_node_checker
: public bstree_node_checker<ValueTraits, NodePtrCompare, ExtraChecker>
{
typedef bstree_node_checker<ValueTraits, NodePtrCompare, ExtraChecker> base_checker_t;
typedef ValueTraits value_traits;
typedef typename value_traits::node_traits node_traits;
typedef typename node_traits::const_node_ptr const_node_ptr;
struct return_type
: public base_checker_t::return_type
{
return_type() : height(0) {}
int height;
};
avltree_node_checker(const NodePtrCompare& comp, ExtraChecker extra_checker)
: base_checker_t(comp, extra_checker)
{}
void operator () (const_node_ptr p,
const return_type& check_return_left, const return_type& check_return_right,
return_type& check_return)
{
const int height_diff = check_return_right.height - check_return_left.height; (void)height_diff;
BOOST_INTRUSIVE_INVARIANT_ASSERT(
(height_diff == -1 && node_traits::get_balance(p) == node_traits::negative()) ||
(height_diff == 0 && node_traits::get_balance(p) == node_traits::zero()) ||
(height_diff == 1 && node_traits::get_balance(p) == node_traits::positive())
);
check_return.height = 1 +
(check_return_left.height > check_return_right.height ? check_return_left.height : check_return_right.height);
base_checker_t::operator()(p, check_return_left, check_return_right, check_return);
}
};
} // namespace detail
/// @endcond
//! avltree_algorithms is configured with a NodeTraits class, which encapsulates the
//! information about the node to be manipulated. NodeTraits must support the
//! following interface:
//!
//! <b>Typedefs</b>:
//!
//! <tt>node</tt>: The type of the node that forms the binary search tree
//!
//! <tt>node_ptr</tt>: A pointer to a node
//!
//! <tt>const_node_ptr</tt>: A pointer to a const node
//!
//! <tt>balance</tt>: The type of the balance factor
//!
//! <b>Static functions</b>:
//!
//! <tt>static node_ptr get_parent(const_node_ptr n);</tt>
//!
//! <tt>static void set_parent(node_ptr n, node_ptr parent);</tt>
//!
//! <tt>static node_ptr get_left(const_node_ptr n);</tt>
//!
//! <tt>static void set_left(node_ptr n, node_ptr left);</tt>
//!
//! <tt>static node_ptr get_right(const_node_ptr n);</tt>
//!
//! <tt>static void set_right(node_ptr n, node_ptr right);</tt>
//!
//! <tt>static balance get_balance(const_node_ptr n);</tt>
//!
//! <tt>static void set_balance(node_ptr n, balance b);</tt>
//!
//! <tt>static balance negative();</tt>
//!
//! <tt>static balance zero();</tt>
//!
//! <tt>static balance positive();</tt>
template<class NodeTraits>
class avltree_algorithms
#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
: public bstree_algorithms<NodeTraits>
#endif
{
public:
typedef typename NodeTraits::node node;
typedef NodeTraits node_traits;
typedef typename NodeTraits::node_ptr node_ptr;
typedef typename NodeTraits::const_node_ptr const_node_ptr;
typedef typename NodeTraits::balance balance;
/// @cond
private:
typedef bstree_algorithms<NodeTraits> bstree_algo;
/// @endcond
public:
//! This type is the information that will be
//! filled by insert_unique_check
typedef typename bstree_algo::insert_commit_data insert_commit_data;
#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
//! @copydoc ::boost::intrusive::bstree_algorithms::get_header(const_node_ptr)
static node_ptr get_header(const_node_ptr n) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree_algorithms::begin_node
static node_ptr begin_node(const_node_ptr header) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree_algorithms::end_node
static node_ptr end_node(const_node_ptr header) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree_algorithms::swap_tree
static void swap_tree(node_ptr header1, node_ptr header2) BOOST_NOEXCEPT;
#endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
//! @copydoc ::boost::intrusive::bstree_algorithms::swap_nodes(node_ptr,node_ptr)
static void swap_nodes(node_ptr node1, node_ptr node2) BOOST_NOEXCEPT
{
if(node1 == node2)
return;
node_ptr header1(bstree_algo::get_header(node1)), header2(bstree_algo::get_header(node2));
swap_nodes(node1, header1, node2, header2);
}
//! @copydoc ::boost::intrusive::bstree_algorithms::swap_nodes(node_ptr,node_ptr,node_ptr,node_ptr)
static void swap_nodes(node_ptr node1, node_ptr header1, node_ptr node2, node_ptr header2) BOOST_NOEXCEPT
{
if(node1 == node2) return;
bstree_algo::swap_nodes(node1, header1, node2, header2);
//Swap balance
balance c = NodeTraits::get_balance(node1);
NodeTraits::set_balance(node1, NodeTraits::get_balance(node2));
NodeTraits::set_balance(node2, c);
}
//! @copydoc ::boost::intrusive::bstree_algorithms::replace_node(node_ptr,node_ptr)
static void replace_node(node_ptr node_to_be_replaced, node_ptr new_node) BOOST_NOEXCEPT
{
if(node_to_be_replaced == new_node)
return;
replace_node(node_to_be_replaced, bstree_algo::get_header(node_to_be_replaced), new_node);
}
//! @copydoc ::boost::intrusive::bstree_algorithms::replace_node(node_ptr,node_ptr,node_ptr)
static void replace_node(node_ptr node_to_be_replaced, node_ptr header, node_ptr new_node) BOOST_NOEXCEPT
{
bstree_algo::replace_node(node_to_be_replaced, header, new_node);
NodeTraits::set_balance(new_node, NodeTraits::get_balance(node_to_be_replaced));
}
//! @copydoc ::boost::intrusive::bstree_algorithms::unlink(node_ptr)
static void unlink(node_ptr node) BOOST_NOEXCEPT
{
node_ptr x = NodeTraits::get_parent(node);
if(x){
while(!is_header(x))
x = NodeTraits::get_parent(x);
erase(x, node);
}
}
#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
//! @copydoc ::boost::intrusive::bstree_algorithms::unlink_leftmost_without_rebalance
static node_ptr unlink_leftmost_without_rebalance(node_ptr header) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree_algorithms::unique(const_node_ptr)
static bool unique(const_node_ptr node) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree_algorithms::size(const_node_ptr)
static std::size_t size(const_node_ptr header) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree_algorithms::next_node(node_ptr)
static node_ptr next_node(node_ptr node) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree_algorithms::prev_node(node_ptr)
static node_ptr prev_node(node_ptr node) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree_algorithms::init(node_ptr)
static void init(node_ptr node) BOOST_NOEXCEPT;
#endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
//! <b>Requires</b>: node must not be part of any tree.
//!
//! <b>Effects</b>: Initializes the header to represent an empty tree.
//! unique(header) == true.
//!
//! <b>Complexity</b>: Constant.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree.
static void init_header(node_ptr header) BOOST_NOEXCEPT
{
bstree_algo::init_header(header);
NodeTraits::set_balance(header, NodeTraits::zero());
}
//! @copydoc ::boost::intrusive::bstree_algorithms::erase(node_ptr,node_ptr)
static node_ptr erase(node_ptr header, node_ptr z) BOOST_NOEXCEPT
{
typename bstree_algo::data_for_rebalance info;
bstree_algo::erase(header, z, info);
rebalance_after_erasure(header, z, info);
return z;
}
//! @copydoc ::boost::intrusive::bstree_algorithms::transfer_unique
template<class NodePtrCompare>
static bool transfer_unique
(node_ptr header1, NodePtrCompare comp, node_ptr header2, node_ptr z)
{
typename bstree_algo::data_for_rebalance info;
bool const transferred = bstree_algo::transfer_unique(header1, comp, header2, z, info);
if(transferred){
rebalance_after_erasure(header2, z, info);
rebalance_after_insertion(header1, z);
}
return transferred;
}
//! @copydoc ::boost::intrusive::bstree_algorithms::transfer_equal
template<class NodePtrCompare>
static void transfer_equal
(node_ptr header1, NodePtrCompare comp, node_ptr header2, node_ptr z)
{
typename bstree_algo::data_for_rebalance info;
bstree_algo::transfer_equal(header1, comp, header2, z, info);
rebalance_after_erasure(header2, z, info);
rebalance_after_insertion(header1, z);
}
//! @copydoc ::boost::intrusive::bstree_algorithms::clone(const_node_ptr,node_ptr,Cloner,Disposer)
template <class Cloner, class Disposer>
static void clone
(const_node_ptr source_header, node_ptr target_header, Cloner cloner, Disposer disposer)
{
avltree_node_cloner<NodeTraits, Cloner> new_cloner(cloner);
bstree_algo::clone(source_header, target_header, new_cloner, disposer);
}
#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
//! @copydoc ::boost::intrusive::bstree_algorithms::clear_and_dispose(node_ptr,Disposer)
template<class Disposer>
static void clear_and_dispose(node_ptr header, Disposer disposer) BOOST_NOEXCEPT;
//! @copydoc ::boost::intrusive::bstree_algorithms::lower_bound(const_node_ptr,const KeyType&,KeyNodePtrCompare)
template<class KeyType, class KeyNodePtrCompare>
static node_ptr lower_bound
(const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp);
//! @copydoc ::boost::intrusive::bstree_algorithms::upper_bound(const_node_ptr,const KeyType&,KeyNodePtrCompare)
template<class KeyType, class KeyNodePtrCompare>
static node_ptr upper_bound
(const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp);
//! @copydoc ::boost::intrusive::bstree_algorithms::find(const_node_ptr,const KeyType&,KeyNodePtrCompare)
template<class KeyType, class KeyNodePtrCompare>
static node_ptr find
(const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp);
//! @copydoc ::boost::intrusive::bstree_algorithms::equal_range(const_node_ptr,const KeyType&,KeyNodePtrCompare)
template<class KeyType, class KeyNodePtrCompare>
static std::pair<node_ptr, node_ptr> equal_range
(const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp);
//! @copydoc ::boost::intrusive::bstree_algorithms::bounded_range(const_node_ptr,const KeyType&,const KeyType&,KeyNodePtrCompare,bool,bool)
template<class KeyType, class KeyNodePtrCompare>
static std::pair<node_ptr, node_ptr> bounded_range
(const_node_ptr header, const KeyType &lower_key, const KeyType &upper_key, KeyNodePtrCompare comp
, bool left_closed, bool right_closed);
//! @copydoc ::boost::intrusive::bstree_algorithms::count(const_node_ptr,const KeyType&,KeyNodePtrCompare)
template<class KeyType, class KeyNodePtrCompare>
static std::size_t count(const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp);
#endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
//! @copydoc ::boost::intrusive::bstree_algorithms::insert_equal_upper_bound(node_ptr,node_ptr,NodePtrCompare)
template<class NodePtrCompare>
static node_ptr insert_equal_upper_bound
(node_ptr h, node_ptr new_node, NodePtrCompare comp)
{
bstree_algo::insert_equal_upper_bound(h, new_node, comp);
rebalance_after_insertion(h, new_node);
return new_node;
}
//! @copydoc ::boost::intrusive::bstree_algorithms::insert_equal_lower_bound(node_ptr,node_ptr,NodePtrCompare)
template<class NodePtrCompare>
static node_ptr insert_equal_lower_bound
(node_ptr h, node_ptr new_node, NodePtrCompare comp)
{
bstree_algo::insert_equal_lower_bound(h, new_node, comp);
rebalance_after_insertion(h, new_node);
return new_node;
}
//! @copydoc ::boost::intrusive::bstree_algorithms::insert_equal(node_ptr,node_ptr,node_ptr,NodePtrCompare)
template<class NodePtrCompare>
static node_ptr insert_equal
(node_ptr header, node_ptr hint, node_ptr new_node, NodePtrCompare comp)
{
bstree_algo::insert_equal(header, hint, new_node, comp);
rebalance_after_insertion(header, new_node);
return new_node;
}
//! @copydoc ::boost::intrusive::bstree_algorithms::insert_before(node_ptr,node_ptr,node_ptr)
static node_ptr insert_before
(node_ptr header, node_ptr pos, node_ptr new_node) BOOST_NOEXCEPT
{
bstree_algo::insert_before(header, pos, new_node);
rebalance_after_insertion(header, new_node);
return new_node;
}
//! @copydoc ::boost::intrusive::bstree_algorithms::push_back(node_ptr,node_ptr)
static void push_back(node_ptr header, node_ptr new_node) BOOST_NOEXCEPT
{
bstree_algo::push_back(header, new_node);
rebalance_after_insertion(header, new_node);
}
//! @copydoc ::boost::intrusive::bstree_algorithms::push_front(node_ptr,node_ptr)
static void push_front(node_ptr header, node_ptr new_node) BOOST_NOEXCEPT
{
bstree_algo::push_front(header, new_node);
rebalance_after_insertion(header, new_node);
}
#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
//! @copydoc ::boost::intrusive::bstree_algorithms::insert_unique_check(const_node_ptr,const KeyType&,KeyNodePtrCompare,insert_commit_data&)
template<class KeyType, class KeyNodePtrCompare>
static std::pair<node_ptr, bool> insert_unique_check
(const_node_ptr header, const KeyType &key
,KeyNodePtrCompare comp, insert_commit_data &commit_data);
//! @copydoc ::boost::intrusive::bstree_algorithms::insert_unique_check(const_node_ptr,node_ptr,const KeyType&,KeyNodePtrCompare,insert_commit_data&)
template<class KeyType, class KeyNodePtrCompare>
static std::pair<node_ptr, bool> insert_unique_check
(const_node_ptr header, node_ptr hint, const KeyType &key
,KeyNodePtrCompare comp, insert_commit_data &commit_data);
#endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
//! @copydoc ::boost::intrusive::bstree_algorithms::insert_unique_commit(node_ptr,node_ptr,const insert_commit_data &)
static void insert_unique_commit
(node_ptr header, node_ptr new_value, const insert_commit_data &commit_data) BOOST_NOEXCEPT
{
bstree_algo::insert_unique_commit(header, new_value, commit_data);
rebalance_after_insertion(header, new_value);
}
//! @copydoc ::boost::intrusive::bstree_algorithms::is_header
static bool is_header(const_node_ptr p) BOOST_NOEXCEPT
{ return NodeTraits::get_balance(p) == NodeTraits::zero() && bstree_algo::is_header(p); }
/// @cond
static bool verify(node_ptr header)
{
std::size_t height;
std::size_t count;
return verify_recursion(NodeTraits::get_parent(header), count, height);
}
private:
static bool verify_recursion(node_ptr n, std::size_t &count, std::size_t &height)
{
if (!n){
count = 0;
height = 0;
return true;
}
std::size_t leftcount, rightcount;
std::size_t leftheight, rightheight;
if(!verify_recursion(NodeTraits::get_left (n), leftcount, leftheight) ||
!verify_recursion(NodeTraits::get_right(n), rightcount, rightheight) ){
return false;
}
count = 1u + leftcount + rightcount;
height = 1u + (leftheight > rightheight ? leftheight : rightheight);
//If equal height, balance must be zero
if(rightheight == leftheight){
if(NodeTraits::get_balance(n) != NodeTraits::zero()){
BOOST_ASSERT(0);
return false;
}
}
//If right is taller than left, then the difference must be at least 1 and the balance positive
else if(rightheight > leftheight){
if(rightheight - leftheight > 1 ){
BOOST_ASSERT(0);
return false;
}
else if(NodeTraits::get_balance(n) != NodeTraits::positive()){
BOOST_ASSERT(0);
return false;
}
}
//If left is taller than right, then the difference must be at least 1 and the balance negative
else{
if(leftheight - rightheight > 1 ){
BOOST_ASSERT(0);
return false;
}
else if(NodeTraits::get_balance(n) != NodeTraits::negative()){
BOOST_ASSERT(0);
return false;
}
}
return true;
}
static void rebalance_after_erasure
( node_ptr header, node_ptr z, const typename bstree_algo::data_for_rebalance &info) BOOST_NOEXCEPT
{
if(info.y != z){
NodeTraits::set_balance(info.y, NodeTraits::get_balance(z));
}
//Rebalance avltree
rebalance_after_erasure_restore_invariants(header, info.x, info.x_parent);
}
static void rebalance_after_erasure_restore_invariants(node_ptr header, node_ptr x, node_ptr x_parent) BOOST_NOEXCEPT
{
for ( node_ptr root = NodeTraits::get_parent(header)
; x != root
; root = NodeTraits::get_parent(header), x_parent = NodeTraits::get_parent(x)) {
const balance x_parent_balance = NodeTraits::get_balance(x_parent);
//Don't cache x_is_leftchild or similar because x can be null and
//equal to both x_parent_left and x_parent_right
const node_ptr x_parent_left (NodeTraits::get_left(x_parent));
const node_ptr x_parent_right(NodeTraits::get_right(x_parent));
if(x_parent_balance == NodeTraits::zero()){
NodeTraits::set_balance( x_parent, x == x_parent_right ? NodeTraits::negative() : NodeTraits::positive() );
break; // the height didn't change, let's stop here
}
else if(x_parent_balance == NodeTraits::negative()){
if (x == x_parent_left) { ////x is left child or x and sibling are null
NodeTraits::set_balance(x_parent, NodeTraits::zero()); // balanced
x = x_parent;
}
else {
// x is right child (x_parent_left is the left child)
BOOST_INTRUSIVE_INVARIANT_ASSERT(x_parent_left);
if (NodeTraits::get_balance(x_parent_left) == NodeTraits::positive()) {
// x_parent_left MUST have a right child
BOOST_INTRUSIVE_INVARIANT_ASSERT(NodeTraits::get_right(x_parent_left));
x = avl_rotate_left_right(x_parent, x_parent_left, header);
}
else {
avl_rotate_right(x_parent, x_parent_left, header);
x = x_parent_left;
}
// if changed from negative to NodeTraits::positive(), no need to check above
if (NodeTraits::get_balance(x) == NodeTraits::positive()){
break;
}
}
}
else if(x_parent_balance == NodeTraits::positive()){
if (x == x_parent_right) { //x is right child or x and sibling are null
NodeTraits::set_balance(x_parent, NodeTraits::zero()); // balanced
x = x_parent;
}
else {
// x is left child (x_parent_right is the right child)
BOOST_INTRUSIVE_INVARIANT_ASSERT(x_parent_right);
if (NodeTraits::get_balance(x_parent_right) == NodeTraits::negative()) {
// x_parent_right MUST have then a left child
BOOST_INTRUSIVE_INVARIANT_ASSERT(NodeTraits::get_left(x_parent_right));
x = avl_rotate_right_left(x_parent, x_parent_right, header);
}
else {
avl_rotate_left(x_parent, x_parent_right, header);
x = x_parent_right;
}
// if changed from NodeTraits::positive() to negative, no need to check above
if (NodeTraits::get_balance(x) == NodeTraits::negative()){
break;
}
}
}
else{
BOOST_INTRUSIVE_INVARIANT_ASSERT(false); // never reached
}
}
}
static void rebalance_after_insertion(node_ptr header, node_ptr x) BOOST_NOEXCEPT
{
NodeTraits::set_balance(x, NodeTraits::zero());
// Rebalance.
for(node_ptr root = NodeTraits::get_parent(header); x != root; root = NodeTraits::get_parent(header)){
node_ptr const x_parent(NodeTraits::get_parent(x));
node_ptr const x_parent_left(NodeTraits::get_left(x_parent));
const balance x_parent_balance = NodeTraits::get_balance(x_parent);
const bool x_is_leftchild(x == x_parent_left);
if(x_parent_balance == NodeTraits::zero()){
// if x is left, parent will have parent->bal_factor = negative
// else, parent->bal_factor = NodeTraits::positive()
NodeTraits::set_balance( x_parent, x_is_leftchild ? NodeTraits::negative() : NodeTraits::positive() );
x = x_parent;
}
else if(x_parent_balance == NodeTraits::positive()){
// if x is a left child, parent->bal_factor = zero
if (x_is_leftchild)
NodeTraits::set_balance(x_parent, NodeTraits::zero());
else{ // x is a right child, needs rebalancing
if (NodeTraits::get_balance(x) == NodeTraits::negative())
avl_rotate_right_left(x_parent, x, header);
else
avl_rotate_left(x_parent, x, header);
}
break;
}
else if(x_parent_balance == NodeTraits::negative()){
// if x is a left child, needs rebalancing
if (x_is_leftchild) {
if (NodeTraits::get_balance(x) == NodeTraits::positive())
avl_rotate_left_right(x_parent, x, header);
else
avl_rotate_right(x_parent, x, header);
}
else
NodeTraits::set_balance(x_parent, NodeTraits::zero());
break;
}
else{
BOOST_INTRUSIVE_INVARIANT_ASSERT(false); // never reached
}
}
}
static void left_right_balancing(node_ptr a, node_ptr b, node_ptr c) BOOST_NOEXCEPT
{
// balancing...
const balance c_balance = NodeTraits::get_balance(c);
const balance zero_balance = NodeTraits::zero();
const balance posi_balance = NodeTraits::positive();
const balance nega_balance = NodeTraits::negative();
NodeTraits::set_balance(c, zero_balance);
if(c_balance == nega_balance){
NodeTraits::set_balance(a, posi_balance);
NodeTraits::set_balance(b, zero_balance);
}
else if(c_balance == zero_balance){
NodeTraits::set_balance(a, zero_balance);
NodeTraits::set_balance(b, zero_balance);
}
else if(c_balance == posi_balance){
NodeTraits::set_balance(a, zero_balance);
NodeTraits::set_balance(b, nega_balance);
}
else{
BOOST_INTRUSIVE_INVARIANT_ASSERT(false); // never reached
}
}
static node_ptr avl_rotate_left_right(const node_ptr a, const node_ptr a_oldleft, node_ptr hdr) BOOST_NOEXCEPT
{ // [note: 'a_oldleft' is 'b']
// | | //
// a(-2) c //
// / \ / \ //
// / \ ==> / \ //
// (pos)b [g] b a //
// / \ / \ / \ //
// [d] c [d] e f [g] //
// / \ //
// e f //
const node_ptr c = NodeTraits::get_right(a_oldleft);
bstree_algo::rotate_left_no_parent_fix(a_oldleft, c);
//No need to link c with a [NodeTraits::set_parent(c, a) + NodeTraits::set_left(a, c)]
//as c is not root and another rotation is coming
bstree_algo::rotate_right(a, c, NodeTraits::get_parent(a), hdr);
left_right_balancing(a, a_oldleft, c);
return c;
}
static node_ptr avl_rotate_right_left(const node_ptr a, const node_ptr a_oldright, node_ptr hdr) BOOST_NOEXCEPT
{ // [note: 'a_oldright' is 'b']
// | | //
// a(pos) c //
// / \ / \ //
// / \ / \ //
// [d] b(neg) ==> a b //
// / \ / \ / \ //
// c [g] [d] e f [g] //
// / \ //
// e f //
const node_ptr c (NodeTraits::get_left(a_oldright));
bstree_algo::rotate_right_no_parent_fix(a_oldright, c);
//No need to link c with a [NodeTraits::set_parent(c, a) + NodeTraits::set_right(a, c)]
//as c is not root and another rotation is coming.
bstree_algo::rotate_left(a, c, NodeTraits::get_parent(a), hdr);
left_right_balancing(a_oldright, a, c);
return c;
}
static void avl_rotate_left(node_ptr x, node_ptr x_oldright, node_ptr hdr) BOOST_NOEXCEPT
{
bstree_algo::rotate_left(x, x_oldright, NodeTraits::get_parent(x), hdr);
// reset the balancing factor
if (NodeTraits::get_balance(x_oldright) == NodeTraits::positive()) {
NodeTraits::set_balance(x, NodeTraits::zero());
NodeTraits::set_balance(x_oldright, NodeTraits::zero());
}
else { // this doesn't happen during insertions
NodeTraits::set_balance(x, NodeTraits::positive());
NodeTraits::set_balance(x_oldright, NodeTraits::negative());
}
}
static void avl_rotate_right(node_ptr x, node_ptr x_oldleft, node_ptr hdr) BOOST_NOEXCEPT
{
bstree_algo::rotate_right(x, x_oldleft, NodeTraits::get_parent(x), hdr);
// reset the balancing factor
if (NodeTraits::get_balance(x_oldleft) == NodeTraits::negative()) {
NodeTraits::set_balance(x, NodeTraits::zero());
NodeTraits::set_balance(x_oldleft, NodeTraits::zero());
}
else { // this doesn't happen during insertions
NodeTraits::set_balance(x, NodeTraits::negative());
NodeTraits::set_balance(x_oldleft, NodeTraits::positive());
}
}
/// @endcond
};
/// @cond
template<class NodeTraits>
struct get_algo<AvlTreeAlgorithms, NodeTraits>
{
typedef avltree_algorithms<NodeTraits> type;
};
template <class ValueTraits, class NodePtrCompare, class ExtraChecker>
struct get_node_checker<AvlTreeAlgorithms, ValueTraits, NodePtrCompare, ExtraChecker>
{
typedef detail::avltree_node_checker<ValueTraits, NodePtrCompare, ExtraChecker> type;
};
/// @endcond
} //namespace intrusive
} //namespace boost
#include <boost/intrusive/detail/config_end.hpp>
#endif //BOOST_INTRUSIVE_AVLTREE_ALGORITHMS_HPP

View File

@@ -0,0 +1,288 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2007-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_BS_SET_HOOK_HPP
#define BOOST_INTRUSIVE_BS_SET_HOOK_HPP
#include <boost/intrusive/detail/config_begin.hpp>
#include <boost/intrusive/intrusive_fwd.hpp>
#include <boost/intrusive/detail/tree_node.hpp>
#include <boost/intrusive/bstree_algorithms.hpp>
#include <boost/intrusive/options.hpp>
#include <boost/intrusive/detail/generic_hook.hpp>
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
namespace boost {
namespace intrusive {
//! Helper metafunction to define a \c bs_set_base_hook that yields to the same
//! type when the same options (either explicitly or implicitly) are used.
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template<class ...Options>
#else
template<class O1 = void, class O2 = void, class O3 = void>
#endif
struct make_bs_set_base_hook
{
/// @cond
typedef typename pack_options
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
< hook_defaults, O1, O2, O3>
#else
< hook_defaults, Options...>
#endif
::type packed_options;
typedef generic_hook
< BsTreeAlgorithms
, tree_node_traits<typename packed_options::void_pointer>
, typename packed_options::tag
, packed_options::link_mode
, BsTreeBaseHookId
> implementation_defined;
/// @endcond
typedef implementation_defined type;
};
//! Derive a class from bs_set_base_hook in order to store objects in
//! in a bs_set/bs_multiset. bs_set_base_hook holds the data necessary to maintain
//! the bs_set/bs_multiset and provides an appropriate value_traits class for bs_set/bs_multiset.
//!
//! The hook admits the following options: \c tag<>, \c void_pointer<>,
//! \c link_mode<>.
//!
//! \c tag<> defines a tag to identify the node.
//! The same tag value can be used in different classes, but if a class is
//! derived from more than one \c list_base_hook, then each \c list_base_hook needs its
//! unique tag.
//!
//! \c void_pointer<> is the pointer type that will be used internally in the hook
//! and the container configured to use this hook.
//!
//! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
//! \c auto_unlink or \c safe_link).
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template<class ...Options>
#else
template<class O1, class O2, class O3>
#endif
class bs_set_base_hook
: public make_bs_set_base_hook
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
<O1, O2, O3>
#else
<Options...>
#endif
::type
{
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
public:
//! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
//! initializes the node to an unlinked state.
//!
//! <b>Throws</b>: Nothing.
bs_set_base_hook();
//! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
//! initializes the node to an unlinked state. The argument is ignored.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Rationale</b>: Providing a copy-constructor
//! makes classes using the hook STL-compliant without forcing the
//! user to do some additional work. \c swap can be used to emulate
//! move-semantics.
bs_set_base_hook(const bs_set_base_hook& );
//! <b>Effects</b>: Empty function. The argument is ignored.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Rationale</b>: Providing an assignment operator
//! makes classes using the hook STL-compliant without forcing the
//! user to do some additional work. \c swap can be used to emulate
//! move-semantics.
bs_set_base_hook& operator=(const bs_set_base_hook& );
//! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
//! nothing (ie. no code is generated). If link_mode is \c safe_link and the
//! object is stored in a set an assertion is raised. If link_mode is
//! \c auto_unlink and \c is_linked() is true, the node is unlinked.
//!
//! <b>Throws</b>: Nothing.
~bs_set_base_hook();
//! <b>Effects</b>: Swapping two nodes swaps the position of the elements
//! related to those nodes in one or two containers. That is, if the node
//! this is part of the element e1, the node x is part of the element e2
//! and both elements are included in the containers s1 and s2, then after
//! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
//! at the position of e1. If one element is not in a container, then
//! after the swap-operation the other element is not in a container.
//! Iterators to e1 and e2 related to those nodes are invalidated.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
void swap_nodes(bs_set_base_hook &other);
//! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
//!
//! <b>Returns</b>: true, if the node belongs to a container, false
//! otherwise. This function can be used to test whether \c set::iterator_to
//! will return a valid iterator.
//!
//! <b>Complexity</b>: Constant
bool is_linked() const;
//! <b>Effects</b>: Removes the node if it's inserted in a container.
//! This function is only allowed if link_mode is \c auto_unlink.
//!
//! <b>Throws</b>: Nothing.
void unlink();
#endif
};
//! Helper metafunction to define a \c bs_set_member_hook that yields to the same
//! type when the same options (either explicitly or implicitly) are used.
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template<class ...Options>
#else
template<class O1 = void, class O2 = void, class O3 = void>
#endif
struct make_bs_set_member_hook
{
/// @cond
typedef typename pack_options
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
< hook_defaults, O1, O2, O3>
#else
< hook_defaults, Options...>
#endif
::type packed_options;
typedef generic_hook
< BsTreeAlgorithms
, tree_node_traits<typename packed_options::void_pointer>
, member_tag
, packed_options::link_mode
, NoBaseHookId
> implementation_defined;
/// @endcond
typedef implementation_defined type;
};
//! Put a public data member bs_set_member_hook in order to store objects of this class in
//! a bs_set/bs_multiset. bs_set_member_hook holds the data necessary for maintaining the
//! bs_set/bs_multiset and provides an appropriate value_traits class for bs_set/bs_multiset.
//!
//! The hook admits the following options: \c void_pointer<>, \c link_mode<>.
//!
//! \c void_pointer<> is the pointer type that will be used internally in the hook
//! and the container configured to use this hook.
//!
//! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
//! \c auto_unlink or \c safe_link).
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template<class ...Options>
#else
template<class O1, class O2, class O3>
#endif
class bs_set_member_hook
: public make_bs_set_member_hook
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
<O1, O2, O3>
#else
<Options...>
#endif
::type
{
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
public:
//! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
//! initializes the node to an unlinked state.
//!
//! <b>Throws</b>: Nothing.
bs_set_member_hook();
//! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
//! initializes the node to an unlinked state. The argument is ignored.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Rationale</b>: Providing a copy-constructor
//! makes classes using the hook STL-compliant without forcing the
//! user to do some additional work. \c swap can be used to emulate
//! move-semantics.
bs_set_member_hook(const bs_set_member_hook& );
//! <b>Effects</b>: Empty function. The argument is ignored.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Rationale</b>: Providing an assignment operator
//! makes classes using the hook STL-compliant without forcing the
//! user to do some additional work. \c swap can be used to emulate
//! move-semantics.
bs_set_member_hook& operator=(const bs_set_member_hook& );
//! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
//! nothing (ie. no code is generated). If link_mode is \c safe_link and the
//! object is stored in a set an assertion is raised. If link_mode is
//! \c auto_unlink and \c is_linked() is true, the node is unlinked.
//!
//! <b>Throws</b>: Nothing.
~bs_set_member_hook();
//! <b>Effects</b>: Swapping two nodes swaps the position of the elements
//! related to those nodes in one or two containers. That is, if the node
//! this is part of the element e1, the node x is part of the element e2
//! and both elements are included in the containers s1 and s2, then after
//! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
//! at the position of e1. If one element is not in a container, then
//! after the swap-operation the other element is not in a container.
//! Iterators to e1 and e2 related to those nodes are invalidated.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
void swap_nodes(bs_set_member_hook &other);
//! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
//!
//! <b>Returns</b>: true, if the node belongs to a container, false
//! otherwise. This function can be used to test whether \c set::iterator_to
//! will return a valid iterator.
//!
//! <b>Complexity</b>: Constant
bool is_linked() const;
//! <b>Effects</b>: Removes the node if it's inserted in a container.
//! This function is only allowed if link_mode is \c auto_unlink.
//!
//! <b>Throws</b>: Nothing.
void unlink();
#endif
};
} //namespace intrusive
} //namespace boost
#include <boost/intrusive/detail/config_end.hpp>
#endif //BOOST_INTRUSIVE_BS_SET_HOOK_HPP

View File

@@ -0,0 +1,466 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Olaf Krzikalla 2004-2006.
// (C) Copyright Ion Gaztanaga 2006-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_CIRCULAR_LIST_ALGORITHMS_HPP
#define BOOST_INTRUSIVE_CIRCULAR_LIST_ALGORITHMS_HPP
#include <boost/intrusive/detail/config_begin.hpp>
#include <boost/intrusive/intrusive_fwd.hpp>
#include <boost/intrusive/detail/algo_type.hpp>
#include <boost/core/no_exceptions_support.hpp>
#include <cstddef>
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
namespace boost {
namespace intrusive {
//! circular_list_algorithms provides basic algorithms to manipulate nodes
//! forming a circular doubly linked list. An empty circular list is formed by a node
//! whose pointers point to itself.
//!
//! circular_list_algorithms is configured with a NodeTraits class, which encapsulates the
//! information about the node to be manipulated. NodeTraits must support the
//! following interface:
//!
//! <b>Typedefs</b>:
//!
//! <tt>node</tt>: The type of the node that forms the circular list
//!
//! <tt>node_ptr</tt>: A pointer to a node
//!
//! <tt>const_node_ptr</tt>: A pointer to a const node
//!
//! <b>Static functions</b>:
//!
//! <tt>static node_ptr get_previous(const_node_ptr n);</tt>
//!
//! <tt>static void set_previous(node_ptr n, node_ptr prev);</tt>
//!
//! <tt>static node_ptr get_next(const_node_ptr n);</tt>
//!
//! <tt>static void set_next(node_ptr n, node_ptr next);</tt>
template<class NodeTraits>
class circular_list_algorithms
{
public:
typedef typename NodeTraits::node node;
typedef typename NodeTraits::node_ptr node_ptr;
typedef typename NodeTraits::const_node_ptr const_node_ptr;
typedef NodeTraits node_traits;
//! <b>Effects</b>: Constructs an non-used list element, so that
//! inited(this_node) == true
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
static void init(node_ptr this_node) BOOST_NOEXCEPT
{
const node_ptr null_node = node_ptr();
NodeTraits::set_next(this_node, null_node);
NodeTraits::set_previous(this_node, null_node);
}
//! <b>Effects</b>: Returns true is "this_node" is in a non-used state
//! as if it was initialized by the "init" function.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
BOOST_INTRUSIVE_FORCEINLINE static bool inited(const_node_ptr this_node) BOOST_NOEXCEPT
{ return !NodeTraits::get_next(this_node); }
//! <b>Effects</b>: Constructs an empty list, making this_node the only
//! node of the circular list:
//! <tt>NodeTraits::get_next(this_node) == NodeTraits::get_previous(this_node)
//! == this_node</tt>.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
static void init_header(node_ptr this_node) BOOST_NOEXCEPT
{
NodeTraits::set_next(this_node, this_node);
NodeTraits::set_previous(this_node, this_node);
}
//! <b>Requires</b>: this_node must be in a circular list or be an empty circular list.
//!
//! <b>Effects</b>: Returns true is "this_node" is the only node of a circular list:
//! <tt>return NodeTraits::get_next(this_node) == this_node</tt>
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
static bool unique(const_node_ptr this_node) BOOST_NOEXCEPT
{
node_ptr next = NodeTraits::get_next(this_node);
return !next || next == this_node;
}
//! <b>Requires</b>: this_node must be in a circular list or be an empty circular list.
//!
//! <b>Effects</b>: Returns the number of nodes in a circular list. If the circular list
//! is empty, returns 1.
//!
//! <b>Complexity</b>: Linear
//!
//! <b>Throws</b>: Nothing.
static std::size_t count(const_node_ptr this_node) BOOST_NOEXCEPT
{
std::size_t result = 0;
const_node_ptr p = this_node;
do{
p = NodeTraits::get_next(p);
++result;
}while (p != this_node);
return result;
}
//! <b>Requires</b>: this_node must be in a circular list or be an empty circular list.
//!
//! <b>Effects</b>: Unlinks the node from the circular list.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
static node_ptr unlink(node_ptr this_node) BOOST_NOEXCEPT
{
node_ptr next(NodeTraits::get_next(this_node));
node_ptr prev(NodeTraits::get_previous(this_node));
NodeTraits::set_next(prev, next);
NodeTraits::set_previous(next, prev);
return next;
}
//! <b>Requires</b>: b and e must be nodes of the same circular list or an empty range.
//!
//! <b>Effects</b>: Unlinks the node [b, e) from the circular list.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
static void unlink(node_ptr b, node_ptr e) BOOST_NOEXCEPT
{
if (b != e) {
node_ptr prevb(NodeTraits::get_previous(b));
NodeTraits::set_previous(e, prevb);
NodeTraits::set_next(prevb, e);
}
}
//! <b>Requires</b>: nxt_node must be a node of a circular list.
//!
//! <b>Effects</b>: Links this_node before nxt_node in the circular list.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
static void link_before(node_ptr nxt_node, node_ptr this_node) BOOST_NOEXCEPT
{
node_ptr prev(NodeTraits::get_previous(nxt_node));
NodeTraits::set_previous(this_node, prev);
NodeTraits::set_next(this_node, nxt_node);
//nxt_node might be an alias for prev->next_
//so use it before NodeTraits::set_next(prev, ...)
//is called and the reference changes its value
NodeTraits::set_previous(nxt_node, this_node);
NodeTraits::set_next(prev, this_node);
}
//! <b>Requires</b>: prev_node must be a node of a circular list.
//!
//! <b>Effects</b>: Links this_node after prev_node in the circular list.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
static void link_after(node_ptr prev_node, node_ptr this_node) BOOST_NOEXCEPT
{
node_ptr next(NodeTraits::get_next(prev_node));
NodeTraits::set_previous(this_node, prev_node);
NodeTraits::set_next(this_node, next);
//prev_node might be an alias for next->next_
//so use it before update it before NodeTraits::set_previous(next, ...)
//is called and the reference changes it's value
NodeTraits::set_next(prev_node, this_node);
NodeTraits::set_previous(next, this_node);
}
//! <b>Requires</b>: this_node and other_node must be nodes inserted
//! in circular lists or be empty circular lists.
//!
//! <b>Effects</b>: Swaps the position of the nodes: this_node is inserted in
//! other_nodes position in the second circular list and the other_node is inserted
//! in this_node's position in the first circular list.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
static void swap_nodes(node_ptr this_node, node_ptr other_node) BOOST_NOEXCEPT
{
if (other_node == this_node)
return;
bool this_inited = inited(this_node);
bool other_inited = inited(other_node);
if(this_inited){
init_header(this_node);
}
if(other_inited){
init_header(other_node);
}
node_ptr next_this(NodeTraits::get_next(this_node));
node_ptr prev_this(NodeTraits::get_previous(this_node));
node_ptr next_other(NodeTraits::get_next(other_node));
node_ptr prev_other(NodeTraits::get_previous(other_node));
//these first two swaps must happen before the other two
swap_prev(next_this, next_other);
swap_next(prev_this, prev_other);
swap_next(this_node, other_node);
swap_prev(this_node, other_node);
if(this_inited){
init(other_node);
}
if(other_inited){
init(this_node);
}
}
//! <b>Requires</b>: b and e must be nodes of the same circular list or an empty range.
//! and p must be a node of a different circular list or may not be an iterator in
// [b, e).
//!
//! <b>Effects</b>: Removes the nodes from [b, e) range from their circular list and inserts
//! them before p in p's circular list.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
static void transfer(node_ptr p, node_ptr b, node_ptr e) BOOST_NOEXCEPT
{
if (b != e && p != b && p != e) {
node_ptr prev_p(NodeTraits::get_previous(p));
node_ptr prev_b(NodeTraits::get_previous(b));
node_ptr prev_e(NodeTraits::get_previous(e));
NodeTraits::set_next(prev_e, p);
NodeTraits::set_previous(p, prev_e);
NodeTraits::set_next(prev_b, e);
NodeTraits::set_previous(e, prev_b);
NodeTraits::set_next(prev_p, b);
NodeTraits::set_previous(b, prev_p);
}
}
//! <b>Requires</b>: i must a node of a circular list
//! and p must be a node of a different circular list.
//!
//! <b>Effects</b>: Removes the node i from its circular list and inserts
//! it before p in p's circular list.
//! If p == i or p == NodeTraits::get_next(i), this function is a null operation.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
static void transfer(node_ptr p, node_ptr i) BOOST_NOEXCEPT
{
node_ptr n(NodeTraits::get_next(i));
if(n != p && i != p){
node_ptr prev_p(NodeTraits::get_previous(p));
node_ptr prev_i(NodeTraits::get_previous(i));
NodeTraits::set_next(prev_p, i);
NodeTraits::set_previous(i, prev_p);
NodeTraits::set_next(i, p);
NodeTraits::set_previous(p, i);
NodeTraits::set_previous(n, prev_i);
NodeTraits::set_next(prev_i, n);
}
}
//! <b>Effects</b>: Reverses the order of elements in the list.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: This function is linear time.
static void reverse(node_ptr p) BOOST_NOEXCEPT
{
node_ptr f(NodeTraits::get_next(p));
node_ptr i(NodeTraits::get_next(f)), e(p);
while(i != e) {
node_ptr n = i;
i = NodeTraits::get_next(i);
transfer(f, n, i);
f = n;
}
}
//! <b>Effects</b>: Moves the node p n positions towards the end of the list.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Linear to the number of moved positions.
static void move_backwards(node_ptr p, std::size_t n) BOOST_NOEXCEPT
{
//Null shift, nothing to do
if(!n) return;
node_ptr first = NodeTraits::get_next(p);
//size() == 0 or 1, nothing to do
if(first == NodeTraits::get_previous(p)) return;
unlink(p);
//Now get the new first node
while(n--){
first = NodeTraits::get_next(first);
}
link_before(first, p);
}
//! <b>Effects</b>: Moves the node p n positions towards the beginning of the list.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Linear to the number of moved positions.
static void move_forward(node_ptr p, std::size_t n) BOOST_NOEXCEPT
{
//Null shift, nothing to do
if(!n) return;
node_ptr last = NodeTraits::get_previous(p);
//size() == 0 or 1, nothing to do
if(last == NodeTraits::get_next(p)) return;
unlink(p);
//Now get the new last node
while(n--){
last = NodeTraits::get_previous(last);
}
link_after(last, p);
}
//! <b>Requires</b>: f and l must be in a circular list.
//!
//! <b>Effects</b>: Returns the number of nodes in the range [f, l).
//!
//! <b>Complexity</b>: Linear
//!
//! <b>Throws</b>: Nothing.
static std::size_t distance(const_node_ptr f, const_node_ptr l) BOOST_NOEXCEPT
{
std::size_t result = 0;
while(f != l){
f = NodeTraits::get_next(f);
++result;
}
return result;
}
struct stable_partition_info
{
std::size_t num_1st_partition;
std::size_t num_2nd_partition;
node_ptr beg_2st_partition;
};
template<class Pred>
static void stable_partition(node_ptr beg, node_ptr end, Pred pred, stable_partition_info &info)
{
node_ptr bcur = node_traits::get_previous(beg);
node_ptr cur = beg;
node_ptr new_f = end;
std::size_t num1 = 0, num2 = 0;
while(cur != end){
if(pred(cur)){
++num1;
bcur = cur;
cur = node_traits::get_next(cur);
}
else{
++num2;
node_ptr last_to_remove = bcur;
new_f = cur;
bcur = cur;
cur = node_traits::get_next(cur);
BOOST_TRY{
//Main loop
while(cur != end){
if(pred(cur)){ //Might throw
++num1;
//Process current node
node_traits::set_next (last_to_remove, cur);
node_traits::set_previous(cur, last_to_remove);
last_to_remove = cur;
node_ptr nxt = node_traits::get_next(cur);
node_traits::set_next (bcur, nxt);
node_traits::set_previous(nxt, bcur);
cur = nxt;
}
else{
++num2;
bcur = cur;
cur = node_traits::get_next(cur);
}
}
}
BOOST_CATCH(...){
node_traits::set_next (last_to_remove, new_f);
node_traits::set_previous(new_f, last_to_remove);
BOOST_RETHROW;
}
BOOST_CATCH_END
node_traits::set_next(last_to_remove, new_f);
node_traits::set_previous(new_f, last_to_remove);
break;
}
}
info.num_1st_partition = num1;
info.num_2nd_partition = num2;
info.beg_2st_partition = new_f;
}
private:
static void swap_prev(node_ptr this_node, node_ptr other_node) BOOST_NOEXCEPT
{
node_ptr temp(NodeTraits::get_previous(this_node));
NodeTraits::set_previous(this_node, NodeTraits::get_previous(other_node));
NodeTraits::set_previous(other_node, temp);
}
static void swap_next(node_ptr this_node, node_ptr other_node) BOOST_NOEXCEPT
{
node_ptr temp(NodeTraits::get_next(this_node));
NodeTraits::set_next(this_node, NodeTraits::get_next(other_node));
NodeTraits::set_next(other_node, temp);
}
};
/// @cond
template<class NodeTraits>
struct get_algo<CircularListAlgorithms, NodeTraits>
{
typedef circular_list_algorithms<NodeTraits> type;
};
/// @endcond
} //namespace intrusive
} //namespace boost
#include <boost/intrusive/detail/config_end.hpp>
#endif //BOOST_INTRUSIVE_CIRCULAR_LIST_ALGORITHMS_HPP

View File

@@ -0,0 +1,406 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Olaf Krzikalla 2004-2006.
// (C) Copyright Ion Gaztanaga 2006-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_CIRCULAR_SLIST_ALGORITHMS_HPP
#define BOOST_INTRUSIVE_CIRCULAR_SLIST_ALGORITHMS_HPP
#include <cstddef>
#include <boost/intrusive/detail/config_begin.hpp>
#include <boost/intrusive/intrusive_fwd.hpp>
#include <boost/intrusive/detail/common_slist_algorithms.hpp>
#include <boost/intrusive/detail/algo_type.hpp>
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
namespace boost {
namespace intrusive {
//! circular_slist_algorithms provides basic algorithms to manipulate nodes
//! forming a circular singly linked list. An empty circular list is formed by a node
//! whose pointer to the next node points to itself.
//!
//! circular_slist_algorithms is configured with a NodeTraits class, which encapsulates the
//! information about the node to be manipulated. NodeTraits must support the
//! following interface:
//!
//! <b>Typedefs</b>:
//!
//! <tt>node</tt>: The type of the node that forms the circular list
//!
//! <tt>node_ptr</tt>: A pointer to a node
//!
//! <tt>const_node_ptr</tt>: A pointer to a const node
//!
//! <b>Static functions</b>:
//!
//! <tt>static node_ptr get_next(const_node_ptr n);</tt>
//!
//! <tt>static void set_next(node_ptr n, node_ptr next);</tt>
template<class NodeTraits>
class circular_slist_algorithms
/// @cond
: public detail::common_slist_algorithms<NodeTraits>
/// @endcond
{
/// @cond
typedef detail::common_slist_algorithms<NodeTraits> base_t;
/// @endcond
public:
typedef typename NodeTraits::node node;
typedef typename NodeTraits::node_ptr node_ptr;
typedef typename NodeTraits::const_node_ptr const_node_ptr;
typedef NodeTraits node_traits;
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
//! <b>Effects</b>: Constructs an non-used list element, putting the next
//! pointer to null:
//! <tt>NodeTraits::get_next(this_node) == node_ptr()</tt>
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
static void init(node_ptr this_node) BOOST_NOEXCEPT;
//! <b>Requires</b>: this_node must be in a circular list or be an empty circular list.
//!
//! <b>Effects</b>: Returns true is "this_node" is the only node of a circular list:
//! or it's a not inserted node:
//! <tt>return node_ptr() == NodeTraits::get_next(this_node) || NodeTraits::get_next(this_node) == this_node</tt>
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
static bool unique(const_node_ptr this_node) BOOST_NOEXCEPT;
//! <b>Effects</b>: Returns true is "this_node" has the same state as
//! if it was inited using "init(node_ptr)"
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
static bool inited(const_node_ptr this_node) BOOST_NOEXCEPT;
//! <b>Requires</b>: prev_node must be in a circular list or be an empty circular list.
//!
//! <b>Effects</b>: Unlinks the next node of prev_node from the circular list.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
static void unlink_after(node_ptr prev_node) BOOST_NOEXCEPT;
//! <b>Requires</b>: prev_node and last_node must be in a circular list
//! or be an empty circular list.
//!
//! <b>Effects</b>: Unlinks the range (prev_node, last_node) from the circular list.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
static void unlink_after(node_ptr prev_node, node_ptr last_node) BOOST_NOEXCEPT;
//! <b>Requires</b>: prev_node must be a node of a circular list.
//!
//! <b>Effects</b>: Links this_node after prev_node in the circular list.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
static void link_after(node_ptr prev_node, node_ptr this_node) BOOST_NOEXCEPT;
//! <b>Requires</b>: b and e must be nodes of the same circular list or an empty range.
//! and p must be a node of a different circular list.
//!
//! <b>Effects</b>: Removes the nodes from (b, e] range from their circular list and inserts
//! them after p in p's circular list.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
static void transfer_after(node_ptr p, node_ptr b, node_ptr e) BOOST_NOEXCEPT;
#endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
//! <b>Effects</b>: Constructs an empty list, making this_node the only
//! node of the circular list:
//! <tt>NodeTraits::get_next(this_node) == this_node</tt>.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
BOOST_INTRUSIVE_FORCEINLINE static void init_header(node_ptr this_node) BOOST_NOEXCEPT
{ NodeTraits::set_next(this_node, this_node); }
//! <b>Requires</b>: this_node and prev_init_node must be in the same circular list.
//!
//! <b>Effects</b>: Returns the previous node of this_node in the circular list starting.
//! the search from prev_init_node. The first node checked for equality
//! is NodeTraits::get_next(prev_init_node).
//!
//! <b>Complexity</b>: Linear to the number of elements between prev_init_node and this_node.
//!
//! <b>Throws</b>: Nothing.
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_previous_node(node_ptr prev_init_node, node_ptr this_node) BOOST_NOEXCEPT
{ return base_t::get_previous_node(prev_init_node, this_node); }
//! <b>Requires</b>: this_node must be in a circular list or be an empty circular list.
//!
//! <b>Effects</b>: Returns the previous node of this_node in the circular list.
//!
//! <b>Complexity</b>: Linear to the number of elements in the circular list.
//!
//! <b>Throws</b>: Nothing.
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_previous_node(node_ptr this_node) BOOST_NOEXCEPT
{ return base_t::get_previous_node(this_node, this_node); }
//! <b>Requires</b>: this_node must be in a circular list or be an empty circular list.
//!
//! <b>Effects</b>: Returns the previous node of the previous node of this_node in the circular list.
//!
//! <b>Complexity</b>: Linear to the number of elements in the circular list.
//!
//! <b>Throws</b>: Nothing.
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_previous_previous_node(node_ptr this_node) BOOST_NOEXCEPT
{ return get_previous_previous_node(this_node, this_node); }
//! <b>Requires</b>: this_node and p must be in the same circular list.
//!
//! <b>Effects</b>: Returns the previous node of the previous node of this_node in the
//! circular list starting. the search from p. The first node checked
//! for equality is NodeTraits::get_next((NodeTraits::get_next(p)).
//!
//! <b>Complexity</b>: Linear to the number of elements in the circular list.
//!
//! <b>Throws</b>: Nothing.
static node_ptr get_previous_previous_node(node_ptr p, node_ptr this_node) BOOST_NOEXCEPT
{
node_ptr p_next = NodeTraits::get_next(p);
node_ptr p_next_next = NodeTraits::get_next(p_next);
while (this_node != p_next_next){
p = p_next;
p_next = p_next_next;
p_next_next = NodeTraits::get_next(p_next);
}
return p;
}
//! <b>Requires</b>: this_node must be in a circular list or be an empty circular list.
//!
//! <b>Effects</b>: Returns the number of nodes in a circular list. If the circular list
//! is empty, returns 1.
//!
//! <b>Complexity</b>: Linear
//!
//! <b>Throws</b>: Nothing.
static std::size_t count(const_node_ptr this_node) BOOST_NOEXCEPT
{
std::size_t result = 0;
const_node_ptr p = this_node;
do{
p = NodeTraits::get_next(p);
++result;
} while (p != this_node);
return result;
}
//! <b>Requires</b>: this_node must be in a circular list, be an empty circular list or be inited.
//!
//! <b>Effects</b>: Unlinks the node from the circular list.
//!
//! <b>Complexity</b>: Linear to the number of elements in the circular list
//!
//! <b>Throws</b>: Nothing.
static void unlink(node_ptr this_node) BOOST_NOEXCEPT
{
if(NodeTraits::get_next(this_node))
base_t::unlink_after(get_previous_node(this_node));
}
//! <b>Requires</b>: nxt_node must be a node of a circular list.
//!
//! <b>Effects</b>: Links this_node before nxt_node in the circular list.
//!
//! <b>Complexity</b>: Linear to the number of elements in the circular list.
//!
//! <b>Throws</b>: Nothing.
BOOST_INTRUSIVE_FORCEINLINE static void link_before (node_ptr nxt_node, node_ptr this_node) BOOST_NOEXCEPT
{ base_t::link_after(get_previous_node(nxt_node), this_node); }
//! <b>Requires</b>: this_node and other_node must be nodes inserted
//! in circular lists or be empty circular lists.
//!
//! <b>Effects</b>: Swaps the position of the nodes: this_node is inserted in
//! other_nodes position in the second circular list and the other_node is inserted
//! in this_node's position in the first circular list.
//!
//! <b>Complexity</b>: Linear to number of elements of both lists
//!
//! <b>Throws</b>: Nothing.
static void swap_nodes(node_ptr this_node, node_ptr other_node) BOOST_NOEXCEPT
{
if (other_node == this_node)
return;
const node_ptr this_next = NodeTraits::get_next(this_node);
const node_ptr other_next = NodeTraits::get_next(other_node);
const bool this_null = !this_next;
const bool other_null = !other_next;
const bool this_empty = this_next == this_node;
const bool other_empty = other_next == other_node;
if(!(other_null || other_empty)){
NodeTraits::set_next(this_next == other_node ? other_node : get_previous_node(other_node), this_node );
}
if(!(this_null | this_empty)){
NodeTraits::set_next(other_next == this_node ? this_node : get_previous_node(this_node), other_node );
}
NodeTraits::set_next(this_node, other_empty ? this_node : (other_next == this_node ? other_node : other_next) );
NodeTraits::set_next(other_node, this_empty ? other_node : (this_next == other_node ? this_node : this_next ) );
}
//! <b>Effects</b>: Reverses the order of elements in the list.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: This function is linear to the contained elements.
static void reverse(node_ptr p) BOOST_NOEXCEPT
{
node_ptr i = NodeTraits::get_next(p), e(p);
for (;;) {
node_ptr nxt(NodeTraits::get_next(i));
if (nxt == e)
break;
base_t::transfer_after(e, i, nxt);
}
}
//! <b>Effects</b>: Moves the node p n positions towards the end of the list.
//!
//! <b>Returns</b>: The previous node of p after the function if there has been any movement,
//! Null if n leads to no movement.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Linear to the number of elements plus the number moved positions.
static node_ptr move_backwards(node_ptr p, std::size_t n) BOOST_NOEXCEPT
{
//Null shift, nothing to do
if(!n) return node_ptr();
node_ptr first = NodeTraits::get_next(p);
//count() == 1 or 2, nothing to do
if(NodeTraits::get_next(first) == p)
return node_ptr();
bool end_found = false;
node_ptr new_last = node_ptr();
//Now find the new last node according to the shift count.
//If we find p before finding the new last node
//unlink p, shortcut the search now that we know the size of the list
//and continue.
for(std::size_t i = 1; i <= n; ++i){
new_last = first;
first = NodeTraits::get_next(first);
if(first == p){
//Shortcut the shift with the modulo of the size of the list
n %= i;
if(!n)
return node_ptr();
i = 0;
//Unlink p and continue the new first node search
first = NodeTraits::get_next(p);
base_t::unlink_after(new_last);
end_found = true;
}
}
//If the p has not been found in the previous loop, find it
//starting in the new first node and unlink it
if(!end_found){
base_t::unlink_after(base_t::get_previous_node(first, p));
}
//Now link p after the new last node
base_t::link_after(new_last, p);
return new_last;
}
//! <b>Effects</b>: Moves the node p n positions towards the beginning of the list.
//!
//! <b>Returns</b>: The previous node of p after the function if there has been any movement,
//! Null if n leads equals to no movement.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Linear to the number of elements plus the number moved positions.
static node_ptr move_forward(node_ptr p, std::size_t n) BOOST_NOEXCEPT
{
//Null shift, nothing to do
if(!n) return node_ptr();
node_ptr first = node_traits::get_next(p);
//count() == 1 or 2, nothing to do
if(node_traits::get_next(first) == p) return node_ptr();
//Iterate until p is found to know where the current last node is.
//If the shift count is less than the size of the list, we can also obtain
//the position of the new last node after the shift.
node_ptr old_last(first), next_to_it, new_last(p);
std::size_t distance = 1;
while(p != (next_to_it = node_traits::get_next(old_last))){
if(++distance > n)
new_last = node_traits::get_next(new_last);
old_last = next_to_it;
}
//If the shift was bigger or equal than the size, obtain the equivalent
//forward shifts and find the new last node.
if(distance <= n){
//Now find the equivalent forward shifts.
//Shortcut the shift with the modulo of the size of the list
std::size_t new_before_last_pos = (distance - (n % distance))% distance;
//If the shift is a multiple of the size there is nothing to do
if(!new_before_last_pos) return node_ptr();
for( new_last = p
; new_before_last_pos--
; new_last = node_traits::get_next(new_last)){
//empty
}
}
//Now unlink p and link it after the new last node
base_t::unlink_after(old_last);
base_t::link_after(new_last, p);
return new_last;
}
};
/// @cond
template<class NodeTraits>
struct get_algo<CircularSListAlgorithms, NodeTraits>
{
typedef circular_slist_algorithms<NodeTraits> type;
};
/// @endcond
} //namespace intrusive
} //namespace boost
#include <boost/intrusive/detail/config_end.hpp>
#endif //BOOST_INTRUSIVE_CIRCULAR_SLIST_ALGORITHMS_HPP

View File

@@ -0,0 +1,77 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DERIVATION_VALUE_TRAITS_HPP
#define BOOST_INTRUSIVE_DERIVATION_VALUE_TRAITS_HPP
#include <boost/intrusive/detail/config_begin.hpp>
#include <boost/intrusive/intrusive_fwd.hpp>
#include <boost/intrusive/link_mode.hpp>
#include <boost/intrusive/pointer_traits.hpp>
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
namespace boost {
namespace intrusive {
//!This value traits template is used to create value traits
//!from user defined node traits where value_traits::value_type will
//!derive from node_traits::node
template<class T, class NodeTraits, link_mode_type LinkMode
#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
= safe_link
#endif
>
struct derivation_value_traits
{
public:
typedef NodeTraits node_traits;
typedef T value_type;
typedef typename node_traits::node node;
typedef typename node_traits::node_ptr node_ptr;
typedef typename node_traits::const_node_ptr const_node_ptr;
typedef typename pointer_traits<node_ptr>::
template rebind_pointer<value_type>::type pointer;
typedef typename pointer_traits<node_ptr>::
template rebind_pointer<const value_type>::type const_pointer;
typedef typename boost::intrusive::
pointer_traits<pointer>::reference reference;
typedef typename boost::intrusive::
pointer_traits<const_pointer>::reference const_reference;
static const link_mode_type link_mode = LinkMode;
BOOST_INTRUSIVE_FORCEINLINE static node_ptr to_node_ptr(reference value) BOOST_NOEXCEPT
{ return node_ptr(&value); }
BOOST_INTRUSIVE_FORCEINLINE static const_node_ptr to_node_ptr(const_reference value) BOOST_NOEXCEPT
{ return node_ptr(&value); }
BOOST_INTRUSIVE_FORCEINLINE static pointer to_value_ptr(node_ptr n) BOOST_NOEXCEPT
{
return pointer_traits<pointer>::pointer_to(static_cast<reference>(*n));
}
BOOST_INTRUSIVE_FORCEINLINE static const_pointer to_value_ptr(const_node_ptr n) BOOST_NOEXCEPT
{
return pointer_traits<const_pointer>::pointer_to(static_cast<const_reference>(*n));
}
};
} //namespace intrusive
} //namespace boost
#include <boost/intrusive/detail/config_end.hpp>
#endif //BOOST_INTRUSIVE_DERIVATION_VALUE_TRAITS_HPP

View File

@@ -0,0 +1,53 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2014-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_ALGO_TYPE_HPP
#define BOOST_INTRUSIVE_DETAIL_ALGO_TYPE_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
namespace boost {
namespace intrusive {
enum algo_types
{
CircularListAlgorithms,
CircularSListAlgorithms,
LinearSListAlgorithms,
CommonSListAlgorithms,
BsTreeAlgorithms,
RbTreeAlgorithms,
AvlTreeAlgorithms,
SgTreeAlgorithms,
SplayTreeAlgorithms,
TreapAlgorithms,
UnorderedAlgorithms,
UnorderedCircularSlistAlgorithms,
AnyAlgorithm
};
template<algo_types AlgoType, class NodeTraits>
struct get_algo;
template<algo_types AlgoType, class ValueTraits, class NodePtrCompare, class ExtraChecker>
struct get_node_checker;
} //namespace intrusive
} //namespace boost
#endif //BOOST_INTRUSIVE_DETAIL_ALGO_TYPE_HPP

View File

@@ -0,0 +1,90 @@
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2014-2014.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_ALGORITHM_HPP
#define BOOST_INTRUSIVE_DETAIL_ALGORITHM_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
namespace boost {
namespace intrusive {
struct algo_pred_equal
{
template<class T>
bool operator()(const T &x, const T &y) const
{ return x == y; }
};
struct algo_pred_less
{
template<class T>
bool operator()(const T &x, const T &y) const
{ return x < y; }
};
template<class InputIt1, class InputIt2, class BinaryPredicate>
bool algo_equal(InputIt1 first1, InputIt1 last1, InputIt2 first2, BinaryPredicate p)
{
for (; first1 != last1; ++first1, ++first2) {
if (!p(*first1, *first2)) {
return false;
}
}
return true;
}
template<class InputIt1, class InputIt2>
bool algo_equal(InputIt1 first1, InputIt1 last1, InputIt2 first2)
{ return (algo_equal)(first1, last1, first2, algo_pred_equal()); }
template<class InputIt1, class InputIt2, class BinaryPredicate>
bool algo_equal(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, BinaryPredicate pred)
{
for (; first1 != last1 && first2 != last2; ++first1, ++first2)
if (!pred(*first1, *first2))
return false;
return first1 == last1 && first2 == last2;
}
template<class InputIt1, class InputIt2>
bool algo_equal(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2)
{ return (algo_equal)(first1, last1, first2, last2, algo_pred_equal()); }
template <class InputIterator1, class InputIterator2, class BinaryPredicate>
bool algo_lexicographical_compare (InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
BinaryPredicate pred)
{
while (first1 != last1){
if (first2 == last2 || *first2 < *first1) return false;
else if (pred(*first1, *first2)) return true;
++first1; ++first2;
}
return (first2 != last2);
}
template <class InputIterator1, class InputIterator2>
bool algo_lexicographical_compare (InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2)
{ return (algo_lexicographical_compare)(first1, last1, first2, last2, algo_pred_less()); }
} //namespace intrusive {
} //namespace boost {
#endif //#ifndef BOOST_INTRUSIVE_DETAIL_ALGORITHM_HPP

View File

@@ -0,0 +1,297 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_ANY_NODE_HPP
#define BOOST_INTRUSIVE_ANY_NODE_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/intrusive/detail/workaround.hpp>
#include <boost/intrusive/pointer_rebind.hpp>
#include <boost/intrusive/detail/mpl.hpp>
#include <boost/intrusive/detail/algo_type.hpp>
#include <cstddef>
namespace boost {
namespace intrusive {
template<class VoidPointer>
struct any_node
{
typedef any_node node;
typedef typename pointer_rebind<VoidPointer, node>::type node_ptr;
typedef typename pointer_rebind<VoidPointer, const node>::type const_node_ptr;
node_ptr node_ptr_1;
node_ptr node_ptr_2;
node_ptr node_ptr_3;
std::size_t size_t_1;
};
template<class VoidPointer>
struct any_list_node_traits
{
typedef any_node<VoidPointer> node;
typedef typename node::node_ptr node_ptr;
typedef typename node::const_node_ptr const_node_ptr;
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_next(const_node_ptr n)
{ return n->node_ptr_1; }
BOOST_INTRUSIVE_FORCEINLINE static void set_next(node_ptr n, node_ptr next)
{ n->node_ptr_1 = next; }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_previous(const_node_ptr n)
{ return n->node_ptr_2; }
BOOST_INTRUSIVE_FORCEINLINE static void set_previous(node_ptr n, node_ptr prev)
{ n->node_ptr_2 = prev; }
};
template<class VoidPointer>
struct any_slist_node_traits
{
typedef any_node<VoidPointer> node;
typedef typename node::node_ptr node_ptr;
typedef typename node::const_node_ptr const_node_ptr;
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_next(const_node_ptr n)
{ return n->node_ptr_1; }
BOOST_INTRUSIVE_FORCEINLINE static void set_next(node_ptr n, node_ptr next)
{ n->node_ptr_1 = next; }
};
template<class VoidPointer>
struct any_unordered_node_traits
: public any_slist_node_traits<VoidPointer>
{
typedef any_slist_node_traits<VoidPointer> reduced_slist_node_traits;
typedef typename reduced_slist_node_traits::node node;
typedef typename reduced_slist_node_traits::node_ptr node_ptr;
typedef typename reduced_slist_node_traits::const_node_ptr const_node_ptr;
static const bool store_hash = true;
static const bool optimize_multikey = true;
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_next(const_node_ptr n)
{ return n->node_ptr_1; }
BOOST_INTRUSIVE_FORCEINLINE static void set_next(node_ptr n, node_ptr next)
{ n->node_ptr_1 = next; }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_prev_in_group(const_node_ptr n)
{ return n->node_ptr_2; }
BOOST_INTRUSIVE_FORCEINLINE static void set_prev_in_group(node_ptr n, node_ptr prev)
{ n->node_ptr_2 = prev; }
BOOST_INTRUSIVE_FORCEINLINE static std::size_t get_hash(const_node_ptr n)
{ return n->size_t_1; }
BOOST_INTRUSIVE_FORCEINLINE static void set_hash(node_ptr n, std::size_t h)
{ n->size_t_1 = h; }
};
template<class VoidPointer>
struct any_rbtree_node_traits
{
typedef any_node<VoidPointer> node;
typedef typename node::node_ptr node_ptr;
typedef typename node::const_node_ptr const_node_ptr;
typedef std::size_t color;
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_parent(const_node_ptr n)
{ return n->node_ptr_1; }
BOOST_INTRUSIVE_FORCEINLINE static void set_parent(node_ptr n, node_ptr p)
{ n->node_ptr_1 = p; }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_left(const_node_ptr n)
{ return n->node_ptr_2; }
BOOST_INTRUSIVE_FORCEINLINE static void set_left(node_ptr n, node_ptr l)
{ n->node_ptr_2 = l; }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_right(const_node_ptr n)
{ return n->node_ptr_3; }
BOOST_INTRUSIVE_FORCEINLINE static void set_right(node_ptr n, node_ptr r)
{ n->node_ptr_3 = r; }
BOOST_INTRUSIVE_FORCEINLINE static color get_color(const_node_ptr n)
{ return n->size_t_1; }
BOOST_INTRUSIVE_FORCEINLINE static void set_color(node_ptr n, color c)
{ n->size_t_1 = c; }
BOOST_INTRUSIVE_FORCEINLINE static color black()
{ return 0u; }
BOOST_INTRUSIVE_FORCEINLINE static color red()
{ return 1u; }
};
template<class VoidPointer>
struct any_avltree_node_traits
{
typedef any_node<VoidPointer> node;
typedef typename node::node_ptr node_ptr;
typedef typename node::const_node_ptr const_node_ptr;
typedef std::size_t balance;
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_parent(const_node_ptr n)
{ return n->node_ptr_1; }
BOOST_INTRUSIVE_FORCEINLINE static void set_parent(node_ptr n, node_ptr p)
{ n->node_ptr_1 = p; }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_left(const_node_ptr n)
{ return n->node_ptr_2; }
BOOST_INTRUSIVE_FORCEINLINE static void set_left(node_ptr n, node_ptr l)
{ n->node_ptr_2 = l; }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_right(const_node_ptr n)
{ return n->node_ptr_3; }
BOOST_INTRUSIVE_FORCEINLINE static void set_right(node_ptr n, node_ptr r)
{ n->node_ptr_3 = r; }
BOOST_INTRUSIVE_FORCEINLINE static balance get_balance(const_node_ptr n)
{ return n->size_t_1; }
BOOST_INTRUSIVE_FORCEINLINE static void set_balance(node_ptr n, balance b)
{ n->size_t_1 = b; }
BOOST_INTRUSIVE_FORCEINLINE static balance negative()
{ return 0u; }
BOOST_INTRUSIVE_FORCEINLINE static balance zero()
{ return 1u; }
BOOST_INTRUSIVE_FORCEINLINE static balance positive()
{ return 2u; }
};
template<class VoidPointer>
struct any_tree_node_traits
{
typedef any_node<VoidPointer> node;
typedef typename node::node_ptr node_ptr;
typedef typename node::const_node_ptr const_node_ptr;
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_parent(const_node_ptr n)
{ return n->node_ptr_1; }
BOOST_INTRUSIVE_FORCEINLINE static void set_parent(node_ptr n, node_ptr p)
{ n->node_ptr_1 = p; }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_left(const_node_ptr n)
{ return n->node_ptr_2; }
BOOST_INTRUSIVE_FORCEINLINE static void set_left(node_ptr n, node_ptr l)
{ n->node_ptr_2 = l; }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_right(const_node_ptr n)
{ return n->node_ptr_3; }
BOOST_INTRUSIVE_FORCEINLINE static void set_right(node_ptr n, node_ptr r)
{ n->node_ptr_3 = r; }
};
template<class VoidPointer>
class any_node_traits
{
public:
typedef any_node<VoidPointer> node;
typedef typename node::node_ptr node_ptr;
typedef typename node::const_node_ptr const_node_ptr;
};
template<class VoidPointer>
class any_algorithms
{
template <class T>
static void function_not_available_for_any_hooks(typename detail::enable_if<detail::is_same<T, bool> >::type)
{}
public:
typedef any_node<VoidPointer> node;
typedef typename node::node_ptr node_ptr;
typedef typename node::const_node_ptr const_node_ptr;
typedef any_node_traits<VoidPointer> node_traits;
//! <b>Requires</b>: node must not be part of any tree.
//!
//! <b>Effects</b>: After the function unique(node) == true.
//!
//! <b>Complexity</b>: Constant.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree.
BOOST_INTRUSIVE_FORCEINLINE static void init(node_ptr node) BOOST_NOEXCEPT
{ node->node_ptr_1 = node_ptr(); };
//! <b>Effects</b>: Returns true if node is in the same state as if called init(node)
//!
//! <b>Complexity</b>: Constant.
//!
//! <b>Throws</b>: Nothing.
BOOST_INTRUSIVE_FORCEINLINE static bool inited(const_node_ptr node)
{ return !node->node_ptr_1; };
BOOST_INTRUSIVE_FORCEINLINE static bool unique(const_node_ptr node) BOOST_NOEXCEPT
{ return !node->node_ptr_1; }
static void unlink(node_ptr)
{
//Auto-unlink hooks and unlink() are not available for any hooks
any_algorithms<VoidPointer>::template function_not_available_for_any_hooks<node_ptr>();
}
static void swap_nodes(node_ptr, node_ptr)
{
//Any nodes have no swap_nodes capability because they don't know
//what algorithm they must use to unlink the node from the container
any_algorithms<VoidPointer>::template function_not_available_for_any_hooks<node_ptr>();
}
};
///@cond
template<class NodeTraits>
struct get_algo<AnyAlgorithm, NodeTraits>
{
typedef typename pointer_rebind<typename NodeTraits::node_ptr, void>::type void_pointer;
typedef any_algorithms<void_pointer> type;
};
///@endcond
} //namespace intrusive
} //namespace boost
#endif //BOOST_INTRUSIVE_ANY_NODE_HPP

View File

@@ -0,0 +1,97 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2014-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_ARRAY_INITIALIZER_HPP
#define BOOST_INTRUSIVE_DETAIL_ARRAY_INITIALIZER_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/config.hpp>
#include <boost/core/no_exceptions_support.hpp>
#include <boost/move/detail/placement_new.hpp>
#include <boost/move/detail/force_ptr.hpp>
namespace boost {
namespace intrusive {
namespace detail {
//This is not standard, but should work with all compilers
union max_align
{
char char_;
short short_;
int int_;
long long_;
#ifdef BOOST_HAS_LONG_LONG
::boost::long_long_type long_long_;
#endif
float float_;
double double_;
long double long_double_;
void * void_ptr_;
};
template<class T, std::size_t N>
class array_initializer
{
public:
template<class CommonInitializer>
array_initializer(const CommonInitializer &init)
{
char *init_buf = (char*)rawbuf;
std::size_t i = 0;
BOOST_TRY{
for(; i != N; ++i){
::new(init_buf, boost_move_new_t()) T(init);
init_buf += sizeof(T);
}
}
BOOST_CATCH(...){
while(i--){
init_buf -= sizeof(T);
move_detail::force_ptr<T*>(init_buf)->~T();
}
BOOST_RETHROW;
}
BOOST_CATCH_END
}
operator T* ()
{ return (T*)(rawbuf); }
operator const T*() const
{ return (const T*)(rawbuf); }
~array_initializer()
{
char *init_buf = (char*)rawbuf + N*sizeof(T);
for(std::size_t i = 0; i != N; ++i){
init_buf -= sizeof(T);
move_detail::force_ptr<T*>(init_buf)->~T();
}
}
private:
detail::max_align rawbuf[(N*sizeof(T)-1)/sizeof(detail::max_align)+1];
};
} //namespace detail{
} //namespace intrusive{
} //namespace boost{
#endif //BOOST_INTRUSIVE_DETAIL_ARRAY_INITIALIZER_HPP

View File

@@ -0,0 +1,45 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_ASSERT_HPP
#define BOOST_INTRUSIVE_DETAIL_ASSERT_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
#pragma once
#endif
#if !defined(BOOST_INTRUSIVE_INVARIANT_ASSERT)
#include <boost/assert.hpp>
#define BOOST_INTRUSIVE_INVARIANT_ASSERT BOOST_ASSERT
#elif defined(BOOST_INTRUSIVE_INVARIANT_ASSERT_INCLUDE)
#include BOOST_INTRUSIVE_INVARIANT_ASSERT_INCLUDE
#endif
#if !defined(BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT)
#include <boost/assert.hpp>
#define BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT BOOST_ASSERT
#elif defined(BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT_INCLUDE)
#include BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT_INCLUDE
#endif
#if !defined(BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT)
#include <boost/assert.hpp>
#define BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT BOOST_ASSERT
#elif defined(BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT_INCLUDE)
#include BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT_INCLUDE
#endif
#endif //BOOST_INTRUSIVE_DETAIL_ASSERT_HPP

View File

@@ -0,0 +1,193 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2007-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_AVLTREE_NODE_HPP
#define BOOST_INTRUSIVE_AVLTREE_NODE_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/intrusive/detail/config_begin.hpp>
#include <boost/intrusive/detail/workaround.hpp>
#include <boost/intrusive/pointer_rebind.hpp>
#include <boost/intrusive/avltree_algorithms.hpp>
#include <boost/intrusive/pointer_plus_bits.hpp>
#include <boost/intrusive/detail/mpl.hpp>
namespace boost {
namespace intrusive {
/////////////////////////////////////////////////////////////////////////////
// //
// Generic node_traits for any pointer type //
// //
/////////////////////////////////////////////////////////////////////////////
//This is the compact representation: 3 pointers
template<class VoidPointer>
struct compact_avltree_node
{
typedef typename pointer_rebind<VoidPointer, compact_avltree_node<VoidPointer> >::type node_ptr;
typedef typename pointer_rebind<VoidPointer, const compact_avltree_node<VoidPointer> >::type const_node_ptr;
enum balance { negative_t, zero_t, positive_t };
node_ptr parent_, left_, right_;
};
//This is the normal representation: 3 pointers + enum
template<class VoidPointer>
struct avltree_node
{
typedef typename pointer_rebind<VoidPointer, avltree_node<VoidPointer> >::type node_ptr;
typedef typename pointer_rebind<VoidPointer, const avltree_node<VoidPointer> >::type const_node_ptr;
enum balance { negative_t, zero_t, positive_t };
node_ptr parent_, left_, right_;
balance balance_;
};
//This is the default node traits implementation
//using a node with 3 generic pointers plus an enum
template<class VoidPointer>
struct default_avltree_node_traits_impl
{
typedef avltree_node<VoidPointer> node;
typedef typename node::node_ptr node_ptr;
typedef typename node::const_node_ptr const_node_ptr;
typedef typename node::balance balance;
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_parent(const_node_ptr n)
{ return n->parent_; }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_parent(node_ptr n)
{ return n->parent_; }
BOOST_INTRUSIVE_FORCEINLINE static void set_parent(node_ptr n, node_ptr p)
{ n->parent_ = p; }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_left(const_node_ptr n)
{ return n->left_; }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_left(node_ptr n)
{ return n->left_; }
BOOST_INTRUSIVE_FORCEINLINE static void set_left(node_ptr n, node_ptr l)
{ n->left_ = l; }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_right(const_node_ptr n)
{ return n->right_; }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_right(node_ptr n)
{ return n->right_; }
BOOST_INTRUSIVE_FORCEINLINE static void set_right(node_ptr n, node_ptr r)
{ n->right_ = r; }
BOOST_INTRUSIVE_FORCEINLINE static balance get_balance(const_node_ptr n)
{ return n->balance_; }
BOOST_INTRUSIVE_FORCEINLINE static balance get_balance(node_ptr n)
{ return n->balance_; }
BOOST_INTRUSIVE_FORCEINLINE static void set_balance(node_ptr n, balance b)
{ n->balance_ = b; }
BOOST_INTRUSIVE_FORCEINLINE static balance negative()
{ return node::negative_t; }
BOOST_INTRUSIVE_FORCEINLINE static balance zero()
{ return node::zero_t; }
BOOST_INTRUSIVE_FORCEINLINE static balance positive()
{ return node::positive_t; }
};
//This is the compact node traits implementation
//using a node with 3 generic pointers
template<class VoidPointer>
struct compact_avltree_node_traits_impl
{
typedef compact_avltree_node<VoidPointer> node;
typedef typename node::node_ptr node_ptr;
typedef typename node::const_node_ptr const_node_ptr;
typedef typename node::balance balance;
typedef pointer_plus_bits<node_ptr, 2> ptr_bit;
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_parent(const_node_ptr n)
{ return ptr_bit::get_pointer(n->parent_); }
BOOST_INTRUSIVE_FORCEINLINE static void set_parent(node_ptr n, node_ptr p)
{ ptr_bit::set_pointer(n->parent_, p); }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_left(const_node_ptr n)
{ return n->left_; }
BOOST_INTRUSIVE_FORCEINLINE static void set_left(node_ptr n, node_ptr l)
{ n->left_ = l; }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_right(const_node_ptr n)
{ return n->right_; }
BOOST_INTRUSIVE_FORCEINLINE static void set_right(node_ptr n, node_ptr r)
{ n->right_ = r; }
BOOST_INTRUSIVE_FORCEINLINE static balance get_balance(const_node_ptr n)
{ return (balance)ptr_bit::get_bits(n->parent_); }
BOOST_INTRUSIVE_FORCEINLINE static void set_balance(node_ptr n, balance b)
{ ptr_bit::set_bits(n->parent_, (std::size_t)b); }
BOOST_INTRUSIVE_FORCEINLINE static balance negative()
{ return node::negative_t; }
BOOST_INTRUSIVE_FORCEINLINE static balance zero()
{ return node::zero_t; }
BOOST_INTRUSIVE_FORCEINLINE static balance positive()
{ return node::positive_t; }
};
//Dispatches the implementation based on the boolean
template<class VoidPointer, bool Compact>
struct avltree_node_traits_dispatch
: public default_avltree_node_traits_impl<VoidPointer>
{};
template<class VoidPointer>
struct avltree_node_traits_dispatch<VoidPointer, true>
: public compact_avltree_node_traits_impl<VoidPointer>
{};
//Inherit from rbtree_node_traits_dispatch depending on the embedding capabilities
template<class VoidPointer, bool OptimizeSize = false>
struct avltree_node_traits
: public avltree_node_traits_dispatch
< VoidPointer
, OptimizeSize &&
max_pointer_plus_bits
< VoidPointer
, detail::alignment_of<compact_avltree_node<VoidPointer> >::value
>::value >= 2u
>
{};
} //namespace intrusive
} //namespace boost
#include <boost/intrusive/detail/config_end.hpp>
#endif //BOOST_INTRUSIVE_AVLTREE_NODE_HPP

View File

@@ -0,0 +1,183 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2014-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_BSTREE_ALGORITHMS_BASE_HPP
#define BOOST_INTRUSIVE_BSTREE_ALGORITHMS_BASE_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/intrusive/detail/uncast.hpp>
namespace boost {
namespace intrusive {
template<class NodeTraits>
class bstree_algorithms_base
{
public:
typedef typename NodeTraits::node node;
typedef NodeTraits node_traits;
typedef typename NodeTraits::node_ptr node_ptr;
typedef typename NodeTraits::const_node_ptr const_node_ptr;
//! <b>Requires</b>: 'node' is a node from the tree except the header.
//!
//! <b>Effects</b>: Returns the next node of the tree.
//!
//! <b>Complexity</b>: Average constant time.
//!
//! <b>Throws</b>: Nothing.
static node_ptr next_node(node_ptr node) BOOST_NOEXCEPT
{
node_ptr const n_right(NodeTraits::get_right(node));
if(n_right){
return minimum(n_right);
}
else {
node_ptr n(node);
node_ptr p(NodeTraits::get_parent(n));
while(n == NodeTraits::get_right(p)){
n = p;
p = NodeTraits::get_parent(p);
}
return NodeTraits::get_right(n) != p ? p : n;
}
}
//! <b>Requires</b>: 'node' is a node from the tree except the leftmost node.
//!
//! <b>Effects</b>: Returns the previous node of the tree.
//!
//! <b>Complexity</b>: Average constant time.
//!
//! <b>Throws</b>: Nothing.
static node_ptr prev_node(node_ptr node) BOOST_NOEXCEPT
{
if(is_header(node)){
return NodeTraits::get_right(node);
}
else if(NodeTraits::get_left(node)){
return maximum(NodeTraits::get_left(node));
}
else {
node_ptr p(node);
node_ptr x = NodeTraits::get_parent(p);
while(p == NodeTraits::get_left(x)){
p = x;
x = NodeTraits::get_parent(x);
}
return x;
}
}
//! <b>Requires</b>: 'node' is a node of a tree but not the header.
//!
//! <b>Effects</b>: Returns the minimum node of the subtree starting at p.
//!
//! <b>Complexity</b>: Logarithmic to the size of the subtree.
//!
//! <b>Throws</b>: Nothing.
static node_ptr minimum(node_ptr node)
{
for(node_ptr p_left = NodeTraits::get_left(node)
;p_left
;p_left = NodeTraits::get_left(node)){
node = p_left;
}
return node;
}
//! <b>Requires</b>: 'node' is a node of a tree but not the header.
//!
//! <b>Effects</b>: Returns the maximum node of the subtree starting at p.
//!
//! <b>Complexity</b>: Logarithmic to the size of the subtree.
//!
//! <b>Throws</b>: Nothing.
static node_ptr maximum(node_ptr node)
{
for(node_ptr p_right = NodeTraits::get_right(node)
;p_right
;p_right = NodeTraits::get_right(node)){
node = p_right;
}
return node;
}
//! <b>Requires</b>: p is a node of a tree.
//!
//! <b>Effects</b>: Returns true if p is the header of the tree.
//!
//! <b>Complexity</b>: Constant.
//!
//! <b>Throws</b>: Nothing.
static bool is_header(const_node_ptr p) BOOST_NOEXCEPT
{
node_ptr p_left (NodeTraits::get_left(p));
node_ptr p_right(NodeTraits::get_right(p));
if(!NodeTraits::get_parent(p) || //Header condition when empty tree
(p_left && p_right && //Header always has leftmost and rightmost
(p_left == p_right || //Header condition when only node
(NodeTraits::get_parent(p_left) != p ||
NodeTraits::get_parent(p_right) != p ))
//When tree size > 1 headers can't be leftmost's
//and rightmost's parent
)){
return true;
}
return false;
}
//! <b>Requires</b>: 'node' is a node of the tree or a header node.
//!
//! <b>Effects</b>: Returns the header of the tree.
//!
//! <b>Complexity</b>: Logarithmic.
//!
//! <b>Throws</b>: Nothing.
static node_ptr get_header(const_node_ptr node)
{
node_ptr n(detail::uncast(node));
node_ptr p(NodeTraits::get_parent(node));
//If p is null, then n is the header of an empty tree
if(p){
//Non-empty tree, check if n is neither root nor header
node_ptr pp(NodeTraits::get_parent(p));
//If granparent is not equal to n, then n is neither root nor header,
//the try the fast path
if(n != pp){
do{
n = p;
p = pp;
pp = NodeTraits::get_parent(pp);
}while(n != pp);
n = p;
}
//Check if n is root or header when size() > 0
else if(!bstree_algorithms_base::is_header(n)){
n = p;
}
}
return n;
}
};
} //namespace intrusive
} //namespace boost
#endif //BOOST_INTRUSIVE_BSTREE_ALGORITHMS_BASE_HPP

View File

@@ -0,0 +1,198 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2007-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_COMMON_SLIST_ALGORITHMS_HPP
#define BOOST_INTRUSIVE_COMMON_SLIST_ALGORITHMS_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/intrusive/intrusive_fwd.hpp>
#include <boost/intrusive/detail/assert.hpp>
#include <boost/intrusive/detail/algo_type.hpp>
#include <boost/core/no_exceptions_support.hpp>
#include <cstddef>
namespace boost {
namespace intrusive {
namespace detail {
template<class NodeTraits>
class common_slist_algorithms
{
public:
typedef typename NodeTraits::node node;
typedef typename NodeTraits::node_ptr node_ptr;
typedef typename NodeTraits::const_node_ptr const_node_ptr;
typedef NodeTraits node_traits;
static node_ptr get_previous_node(node_ptr p, node_ptr this_node)
{
for( node_ptr p_next
; this_node != (p_next = NodeTraits::get_next(p))
; p = p_next){
//Logic error: possible use of linear lists with
//operations only permitted with circular lists
BOOST_INTRUSIVE_INVARIANT_ASSERT(p);
}
return p;
}
BOOST_INTRUSIVE_FORCEINLINE static void init(node_ptr this_node) BOOST_NOEXCEPT
{ NodeTraits::set_next(this_node, node_ptr()); }
static bool unique(const_node_ptr this_node) BOOST_NOEXCEPT
{
node_ptr next = NodeTraits::get_next(this_node);
return !next || next == this_node;
}
BOOST_INTRUSIVE_FORCEINLINE static bool inited(const_node_ptr this_node) BOOST_NOEXCEPT
{ return !NodeTraits::get_next(this_node); }
static void unlink_after(node_ptr prev_node) BOOST_NOEXCEPT
{
const_node_ptr this_node(NodeTraits::get_next(prev_node));
NodeTraits::set_next(prev_node, NodeTraits::get_next(this_node));
}
BOOST_INTRUSIVE_FORCEINLINE static void unlink_after(node_ptr prev_node, node_ptr last_node) BOOST_NOEXCEPT
{ NodeTraits::set_next(prev_node, last_node); }
static void link_after(node_ptr prev_node, node_ptr this_node) BOOST_NOEXCEPT
{
NodeTraits::set_next(this_node, NodeTraits::get_next(prev_node));
NodeTraits::set_next(prev_node, this_node);
}
static void incorporate_after(node_ptr bp, node_ptr b, node_ptr be) BOOST_NOEXCEPT
{
node_ptr p(NodeTraits::get_next(bp));
NodeTraits::set_next(bp, b);
NodeTraits::set_next(be, p);
}
static void transfer_after(node_ptr bp, node_ptr bb, node_ptr be) BOOST_NOEXCEPT
{
if (bp != bb && bp != be && bb != be) {
node_ptr next_b = NodeTraits::get_next(bb);
node_ptr next_e = NodeTraits::get_next(be);
node_ptr next_p = NodeTraits::get_next(bp);
NodeTraits::set_next(bb, next_e);
NodeTraits::set_next(be, next_p);
NodeTraits::set_next(bp, next_b);
}
}
struct stable_partition_info
{
std::size_t num_1st_partition;
std::size_t num_2nd_partition;
node_ptr beg_2st_partition;
node_ptr new_last_node;
};
template<class Pred>
static void stable_partition(node_ptr before_beg, node_ptr end, Pred pred, stable_partition_info &info)
{
node_ptr bcur = before_beg;
node_ptr cur = node_traits::get_next(bcur);
node_ptr new_f = end;
std::size_t num1 = 0, num2 = 0;
while(cur != end){
if(pred(cur)){
++num1;
bcur = cur;
cur = node_traits::get_next(cur);
}
else{
++num2;
node_ptr last_to_remove = bcur;
new_f = cur;
bcur = cur;
cur = node_traits::get_next(cur);
BOOST_TRY{
//Main loop
while(cur != end){
if(pred(cur)){ //Might throw
++num1;
//Process current node
node_traits::set_next(last_to_remove, cur);
last_to_remove = cur;
node_ptr nxt = node_traits::get_next(cur);
node_traits::set_next(bcur, nxt);
cur = nxt;
}
else{
++num2;
bcur = cur;
cur = node_traits::get_next(cur);
}
}
}
BOOST_CATCH(...){
node_traits::set_next(last_to_remove, new_f);
BOOST_RETHROW;
}
BOOST_CATCH_END
node_traits::set_next(last_to_remove, new_f);
break;
}
}
info.num_1st_partition = num1;
info.num_2nd_partition = num2;
info.beg_2st_partition = new_f;
info.new_last_node = bcur;
}
//! <b>Requires</b>: f and l must be in a circular list.
//!
//! <b>Effects</b>: Returns the number of nodes in the range [f, l).
//!
//! <b>Complexity</b>: Linear
//!
//! <b>Throws</b>: Nothing.
static std::size_t distance(const_node_ptr f, const_node_ptr l) BOOST_NOEXCEPT
{
const_node_ptr i(f);
std::size_t result = 0;
while(i != l){
i = NodeTraits::get_next(i);
++result;
}
return result;
}
};
/// @endcond
} //namespace detail
/// @cond
template<class NodeTraits>
struct get_algo<CommonSListAlgorithms, NodeTraits>
{
typedef detail::common_slist_algorithms<NodeTraits> type;
};
} //namespace intrusive
} //namespace boost
#endif //BOOST_INTRUSIVE_COMMON_SLIST_ALGORITHMS_HPP

View File

@@ -0,0 +1,44 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_CONFIG_HPP
#include <boost/config.hpp>
#endif
#ifdef BOOST_MSVC
#pragma warning (push)
#pragma warning (disable : 4619) // there is no warning number 'XXXX'
#pragma warning (disable : 4275) // non DLL-interface classkey "identifier" used as base for DLL-interface classkey "identifier"
#pragma warning (disable : 4251) // "identifier" : class "type" needs to have dll-interface to be used by clients of class "type2"
#pragma warning (disable : 4675) // "method" should be declared "static" and have exactly one parameter
#pragma warning (disable : 4996) // "function": was declared deprecated
#pragma warning (disable : 4503) // "identifier" : decorated name length exceeded, name was truncated
#pragma warning (disable : 4284) // odd return type for operator->
#pragma warning (disable : 4244) // possible loss of data
#pragma warning (disable : 4521) ////Disable "multiple copy constructors specified"
#pragma warning (disable : 4127) //conditional expression is constant
#pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned
#pragma warning (disable : 4267) //conversion from 'X' to 'Y', possible loss of data
#pragma warning (disable : 4541) //'typeid' used on polymorphic type 'boost::exception' with /GR-
#pragma warning (disable : 4512) //'typeid' used on polymorphic type 'boost::exception' with /GR-
#pragma warning (disable : 4522) // "class" : multiple assignment operators specified
#pragma warning (disable : 4706) //assignment within conditional expression
#pragma warning (disable : 4710) // function not inlined
#pragma warning (disable : 4714) // "function": marked as __forceinline not inlined
#pragma warning (disable : 4711) // function selected for automatic inline expansion
#pragma warning (disable : 4786) // identifier truncated in debug info
#pragma warning (disable : 4996) // "function": was declared deprecated
#endif
//#define BOOST_INTRUSIVE_USE_ITERATOR_FACADE
//#define BOOST_INTRUSIVE_USE_ITERATOR_ENABLE_IF_CONVERTIBLE

View File

@@ -0,0 +1,15 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#if defined BOOST_MSVC
#pragma warning (pop)
#endif

View File

@@ -0,0 +1,70 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2014-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_DEFAULT_HEADER_HOLDER_HPP
#define BOOST_INTRUSIVE_DETAIL_DEFAULT_HEADER_HOLDER_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/intrusive/detail/workaround.hpp>
#include <boost/intrusive/pointer_traits.hpp>
#include <boost/move/detail/to_raw_pointer.hpp>
namespace boost {
namespace intrusive {
namespace detail {
// trivial header node holder
template < typename NodeTraits >
struct default_header_holder : public NodeTraits::node
{
typedef NodeTraits node_traits;
typedef typename node_traits::node node;
typedef typename node_traits::node_ptr node_ptr;
typedef typename node_traits::const_node_ptr const_node_ptr;
default_header_holder() : node() {}
BOOST_INTRUSIVE_FORCEINLINE const_node_ptr get_node() const
{ return pointer_traits< const_node_ptr >::pointer_to(*static_cast< const node* >(this)); }
BOOST_INTRUSIVE_FORCEINLINE node_ptr get_node()
{ return pointer_traits< node_ptr >::pointer_to(*static_cast< node* >(this)); }
// (unsafe) downcast used to implement container-from-iterator
BOOST_INTRUSIVE_FORCEINLINE static default_header_holder* get_holder(node_ptr p)
{ return static_cast< default_header_holder* >(boost::movelib::to_raw_pointer(p)); }
};
// type function producing the header node holder
template < typename ValueTraits, typename HeaderHolder >
struct get_header_holder_type
{
typedef HeaderHolder type;
};
template < typename ValueTraits >
struct get_header_holder_type< ValueTraits, void >
{
typedef default_header_holder< typename ValueTraits::node_traits > type;
};
} //namespace detail
} //namespace intrusive
} //namespace boost
#endif //BOOST_INTRUSIVE_DETAIL_DEFAULT_HEADER_HOLDER_HPP

View File

@@ -0,0 +1,292 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Joaquin M Lopez Munoz 2006-2013
// (C) Copyright Ion Gaztanaga 2014-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_EBO_HOLDER_HPP
#define BOOST_INTRUSIVE_DETAIL_EBO_HOLDER_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/intrusive/detail/workaround.hpp>
#include <boost/move/utility_core.hpp>
namespace boost {
namespace intrusive {
namespace detail {
#if defined(BOOST_MSVC) || defined(__BORLANDC_)
#define BOOST_INTRUSIVE_TT_DECL __cdecl
#else
#define BOOST_INTRUSIVE_TT_DECL
#endif
#if defined(_MSC_EXTENSIONS) && !defined(__BORLAND__) && !defined(_WIN64) && !defined(_M_ARM) && !defined(_M_ARM64) && !defined(UNDER_CE)
#define BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
#endif
template <typename T>
struct is_unary_or_binary_function_impl
{ static const bool value = false; };
// see boost ticket #4094
// avoid duplicate definitions of is_unary_or_binary_function_impl
#ifndef BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
template <typename R>
struct is_unary_or_binary_function_impl<R (*)()>
{ static const bool value = true; };
template <typename R>
struct is_unary_or_binary_function_impl<R (*)(...)>
{ static const bool value = true; };
#else // BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
template <typename R>
struct is_unary_or_binary_function_impl<R (__stdcall*)()>
{ static const bool value = true; };
#ifndef _MANAGED
template <typename R>
struct is_unary_or_binary_function_impl<R (__fastcall*)()>
{ static const bool value = true; };
#endif
template <typename R>
struct is_unary_or_binary_function_impl<R (__cdecl*)()>
{ static const bool value = true; };
template <typename R>
struct is_unary_or_binary_function_impl<R (__cdecl*)(...)>
{ static const bool value = true; };
#endif
// see boost ticket #4094
// avoid duplicate definitions of is_unary_or_binary_function_impl
#ifndef BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
template <typename R, class T0>
struct is_unary_or_binary_function_impl<R (*)(T0)>
{ static const bool value = true; };
template <typename R, class T0>
struct is_unary_or_binary_function_impl<R (*)(T0...)>
{ static const bool value = true; };
#else // BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
template <typename R, class T0>
struct is_unary_or_binary_function_impl<R (__stdcall*)(T0)>
{ static const bool value = true; };
#ifndef _MANAGED
template <typename R, class T0>
struct is_unary_or_binary_function_impl<R (__fastcall*)(T0)>
{ static const bool value = true; };
#endif
template <typename R, class T0>
struct is_unary_or_binary_function_impl<R (__cdecl*)(T0)>
{ static const bool value = true; };
template <typename R, class T0>
struct is_unary_or_binary_function_impl<R (__cdecl*)(T0...)>
{ static const bool value = true; };
#endif
// see boost ticket #4094
// avoid duplicate definitions of is_unary_or_binary_function_impl
#ifndef BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
template <typename R, class T0, class T1>
struct is_unary_or_binary_function_impl<R (*)(T0, T1)>
{ static const bool value = true; };
template <typename R, class T0, class T1>
struct is_unary_or_binary_function_impl<R (*)(T0, T1...)>
{ static const bool value = true; };
#else // BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
template <typename R, class T0, class T1>
struct is_unary_or_binary_function_impl<R (__stdcall*)(T0, T1)>
{ static const bool value = true; };
#ifndef _MANAGED
template <typename R, class T0, class T1>
struct is_unary_or_binary_function_impl<R (__fastcall*)(T0, T1)>
{ static const bool value = true; };
#endif
template <typename R, class T0, class T1>
struct is_unary_or_binary_function_impl<R (__cdecl*)(T0, T1)>
{ static const bool value = true; };
template <typename R, class T0, class T1>
struct is_unary_or_binary_function_impl<R (__cdecl*)(T0, T1...)>
{ static const bool value = true; };
#endif
template <typename T>
struct is_unary_or_binary_function_impl<T&>
{ static const bool value = false; };
template<typename T>
struct is_unary_or_binary_function : is_unary_or_binary_function_impl<T>
{};
template<typename T, typename Tag = void, bool = is_unary_or_binary_function<T>::value>
class ebo_functor_holder
{
BOOST_COPYABLE_AND_MOVABLE(ebo_functor_holder)
public:
typedef T functor_type;
BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder()
: t_()
{}
BOOST_INTRUSIVE_FORCEINLINE explicit ebo_functor_holder(const T &t)
: t_(t)
{}
BOOST_INTRUSIVE_FORCEINLINE explicit ebo_functor_holder(BOOST_RV_REF(T) t)
: t_(::boost::move(t))
{}
template<class Arg1, class Arg2>
BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder(BOOST_FWD_REF(Arg1) arg1, BOOST_FWD_REF(Arg2) arg2)
: t_(::boost::forward<Arg1>(arg1), ::boost::forward<Arg2>(arg2))
{}
BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder(const ebo_functor_holder &x)
: t_(x.t_)
{}
BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder(BOOST_RV_REF(ebo_functor_holder) x)
: t_(x.t_)
{}
BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder& operator=(BOOST_COPY_ASSIGN_REF(ebo_functor_holder) x)
{
this->get() = x.get();
return *this;
}
BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder& operator=(BOOST_RV_REF(ebo_functor_holder) x)
{
this->get() = ::boost::move(x.get());
return *this;
}
BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder& operator=(const T &x)
{
this->get() = x;
return *this;
}
BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder& operator=(BOOST_RV_REF(T) x)
{
this->get() = ::boost::move(x);
return *this;
}
BOOST_INTRUSIVE_FORCEINLINE T& get(){return t_;}
BOOST_INTRUSIVE_FORCEINLINE const T& get()const{return t_;}
private:
T t_;
};
template<typename T, typename Tag>
class ebo_functor_holder<T, Tag, false>
: public T
{
BOOST_COPYABLE_AND_MOVABLE(ebo_functor_holder)
public:
typedef T functor_type;
BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder()
: T()
{}
BOOST_INTRUSIVE_FORCEINLINE explicit ebo_functor_holder(const T &t)
: T(t)
{}
BOOST_INTRUSIVE_FORCEINLINE explicit ebo_functor_holder(BOOST_RV_REF(T) t)
: T(::boost::move(t))
{}
template<class Arg1, class Arg2>
BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder(BOOST_FWD_REF(Arg1) arg1, BOOST_FWD_REF(Arg2) arg2)
: T(::boost::forward<Arg1>(arg1), ::boost::forward<Arg2>(arg2))
{}
BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder(const ebo_functor_holder &x)
: T(static_cast<const T&>(x))
{}
BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder(BOOST_RV_REF(ebo_functor_holder) x)
: T(BOOST_MOVE_BASE(T, x))
{}
BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder& operator=(BOOST_COPY_ASSIGN_REF(ebo_functor_holder) x)
{
const ebo_functor_holder&r = x;
this->get() = r;
return *this;
}
BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder& operator=(BOOST_RV_REF(ebo_functor_holder) x)
{
this->get() = ::boost::move(x.get());
return *this;
}
BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder& operator=(const T &x)
{
this->get() = x;
return *this;
}
BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder& operator=(BOOST_RV_REF(T) x)
{
this->get() = ::boost::move(x);
return *this;
}
BOOST_INTRUSIVE_FORCEINLINE T& get(){return *this;}
BOOST_INTRUSIVE_FORCEINLINE const T& get()const{return *this;}
};
} //namespace detail {
} //namespace intrusive {
} //namespace boost {
#endif //#ifndef BOOST_INTRUSIVE_DETAIL_EBO_HOLDER_HPP

View File

@@ -0,0 +1,44 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2014-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_EMPTY_NODE_CHECKER_HPP
#define BOOST_INTRUSIVE_DETAIL_EMPTY_NODE_CHECKER_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
namespace boost {
namespace intrusive {
namespace detail {
template<class ValueTraits>
struct empty_node_checker
{
typedef ValueTraits value_traits;
typedef typename value_traits::node_traits node_traits;
typedef typename node_traits::const_node_ptr const_node_ptr;
struct return_type {};
void operator () (const_node_ptr, const return_type&, const return_type&, return_type&) {}
};
} //namespace detail{
} //namespace intrusive{
} //namespace boost{
#endif //BOOST_INTRUSIVE_DETAIL_EMPTY_NODE_CHECKER_HPP

View File

@@ -0,0 +1,50 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2014-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_EQUAL_TO_VALUE_HPP
#define BOOST_INTRUSIVE_DETAIL_EQUAL_TO_VALUE_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/intrusive/detail/workaround.hpp>
namespace boost {
namespace intrusive {
namespace detail {
//This functor compares a stored value
//and the one passed as an argument
template<class ConstReference>
class equal_to_value
{
ConstReference t_;
public:
equal_to_value(ConstReference t)
: t_(t)
{}
BOOST_INTRUSIVE_FORCEINLINE bool operator()(ConstReference t)const
{ return t_ == t; }
};
} //namespace detail{
} //namespace intrusive{
} //namespace boost{
#endif //BOOST_INTRUSIVE_DETAIL_EQUAL_TO_VALUE_HPP

View File

@@ -0,0 +1,90 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2014-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_EXCEPTION_DISPOSER_HPP
#define BOOST_INTRUSIVE_DETAIL_EXCEPTION_DISPOSER_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/intrusive/detail/workaround.hpp>
namespace boost {
namespace intrusive {
namespace detail {
template<class Container, class Disposer>
class exception_disposer
{
Container *cont_;
Disposer &disp_;
exception_disposer(const exception_disposer&);
exception_disposer &operator=(const exception_disposer&);
public:
exception_disposer(Container &cont, Disposer &disp)
: cont_(&cont), disp_(disp)
{}
BOOST_INTRUSIVE_FORCEINLINE void release()
{ cont_ = 0; }
~exception_disposer()
{
if(cont_){
cont_->clear_and_dispose(disp_);
}
}
};
template<class Container, class Disposer, class SizeType>
class exception_array_disposer
{
Container *cont_;
Disposer &disp_;
SizeType &constructed_;
exception_array_disposer(const exception_array_disposer&);
exception_array_disposer &operator=(const exception_array_disposer&);
public:
exception_array_disposer
(Container &cont, Disposer &disp, SizeType &constructed)
: cont_(&cont), disp_(disp), constructed_(constructed)
{}
BOOST_INTRUSIVE_FORCEINLINE void release()
{ cont_ = 0; }
~exception_array_disposer()
{
SizeType n = constructed_;
if(cont_){
while(n--){
cont_[n].clear_and_dispose(disp_);
}
}
}
};
} //namespace detail{
} //namespace intrusive{
} //namespace boost{
#endif //BOOST_INTRUSIVE_DETAIL_EXCEPTION_DISPOSER_HPP

View File

@@ -0,0 +1,92 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2009-2013.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
// This code was modified from the code posted by Alexandre Courpron in his
// article "Interface Detection" in The Code Project:
// http://www.codeproject.com/KB/architecture/Detector.aspx
///////////////////////////////////////////////////////////////////////////////
// Copyright 2007 Alexandre Courpron
//
// Permission to use, copy, modify, redistribute and sell this software,
// provided that this copyright notice appears on all copies of the software.
///////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_FUNCTION_DETECTOR_HPP
#define BOOST_INTRUSIVE_DETAIL_FUNCTION_DETECTOR_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
namespace boost {
namespace intrusive {
namespace function_detector {
typedef char NotFoundType;
struct StaticFunctionType { NotFoundType x [2]; };
struct NonStaticFunctionType { NotFoundType x [3]; };
enum
{ NotFound = 0,
StaticFunction = sizeof( StaticFunctionType ) - sizeof( NotFoundType ),
NonStaticFunction = sizeof( NonStaticFunctionType ) - sizeof( NotFoundType )
};
} //namespace boost {
} //namespace intrusive {
} //namespace function_detector {
#define BOOST_INTRUSIVE_CREATE_FUNCTION_DETECTOR(Identifier, InstantiationKey) \
namespace boost { \
namespace intrusive { \
namespace function_detector { \
template < class T, \
class NonStaticType, \
class NonStaticConstType, \
class StaticType > \
class DetectMember_##InstantiationKey_##Identifier { \
template < NonStaticType > \
struct TestNonStaticNonConst ; \
\
template < NonStaticConstType > \
struct TestNonStaticConst ; \
\
template < StaticType > \
struct TestStatic ; \
\
template <class U > \
static NonStaticFunctionType Test( TestNonStaticNonConst<&U::Identifier>*, int ); \
\
template <class U > \
static NonStaticFunctionType Test( TestNonStaticConst<&U::Identifier>*, int ); \
\
template <class U> \
static StaticFunctionType Test( TestStatic<&U::Identifier>*, int ); \
\
template <class U> \
static NotFoundType Test( ... ); \
public : \
static const int check = NotFound + (sizeof(Test<T>(0, 0)) - sizeof(NotFoundType));\
};\
}}} //namespace boost::intrusive::function_detector {
#define BOOST_INTRUSIVE_DETECT_FUNCTION(Class, InstantiationKey, ReturnType, Identifier, Params) \
::boost::intrusive::function_detector::DetectMember_##InstantiationKey_##Identifier< Class,\
ReturnType (Class::*)Params,\
ReturnType (Class::*)Params const,\
ReturnType (*)Params \
>::check
#endif //@ifndef BOOST_INTRUSIVE_DETAIL_FUNCTION_DETECTOR_HPP

View File

@@ -0,0 +1,223 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2007-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_GENERIC_HOOK_HPP
#define BOOST_INTRUSIVE_GENERIC_HOOK_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/intrusive/pointer_traits.hpp>
#include <boost/intrusive/link_mode.hpp>
#include <boost/intrusive/detail/mpl.hpp>
#include <boost/intrusive/detail/assert.hpp>
#include <boost/intrusive/detail/node_holder.hpp>
#include <boost/intrusive/detail/algo_type.hpp>
#include <boost/static_assert.hpp>
namespace boost {
namespace intrusive {
/// @cond
namespace detail {
template <link_mode_type LinkMode>
struct link_dispatch
{};
template<class Hook>
BOOST_INTRUSIVE_FORCEINLINE void destructor_impl(Hook &hook, detail::link_dispatch<safe_link>)
{ //If this assertion raises, you might have destroyed an object
//while it was still inserted in a container that is alive.
//If so, remove the object from the container before destroying it.
(void)hook; BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT(!hook.is_linked());
}
template<class Hook>
BOOST_INTRUSIVE_FORCEINLINE void destructor_impl(Hook &hook, detail::link_dispatch<auto_unlink>)
{ hook.unlink(); }
template<class Hook>
BOOST_INTRUSIVE_FORCEINLINE void destructor_impl(Hook &, detail::link_dispatch<normal_link>)
{}
} //namespace detail {
enum base_hook_type
{ NoBaseHookId
, ListBaseHookId
, SlistBaseHookId
, RbTreeBaseHookId
, HashBaseHookId
, AvlTreeBaseHookId
, BsTreeBaseHookId
, TreapTreeBaseHookId
, AnyBaseHookId
};
template <class HookTags, unsigned int>
struct hook_tags_definer{};
template <class HookTags>
struct hook_tags_definer<HookTags, ListBaseHookId>
{ typedef HookTags default_list_hook; };
template <class HookTags>
struct hook_tags_definer<HookTags, SlistBaseHookId>
{ typedef HookTags default_slist_hook; };
template <class HookTags>
struct hook_tags_definer<HookTags, RbTreeBaseHookId>
{ typedef HookTags default_rbtree_hook; };
template <class HookTags>
struct hook_tags_definer<HookTags, HashBaseHookId>
{ typedef HookTags default_hashtable_hook; };
template <class HookTags>
struct hook_tags_definer<HookTags, AvlTreeBaseHookId>
{ typedef HookTags default_avltree_hook; };
template <class HookTags>
struct hook_tags_definer<HookTags, BsTreeBaseHookId>
{ typedef HookTags default_bstree_hook; };
template <class HookTags>
struct hook_tags_definer<HookTags, AnyBaseHookId>
{ typedef HookTags default_any_hook; };
template
< class NodeTraits
, class Tag
, link_mode_type LinkMode
, base_hook_type BaseHookType
>
struct hooktags_impl
{
static const link_mode_type link_mode = LinkMode;
typedef Tag tag;
typedef NodeTraits node_traits;
static const bool is_base_hook = !detail::is_same<Tag, member_tag>::value;
static const bool safemode_or_autounlink = is_safe_autounlink<link_mode>::value;
static const unsigned int type = BaseHookType;
};
/// @endcond
template
< boost::intrusive::algo_types Algo
, class NodeTraits
, class Tag
, link_mode_type LinkMode
, base_hook_type BaseHookType
>
class generic_hook
/// @cond
//If the hook is a base hook, derive generic hook from node_holder
//so that a unique base class is created to convert from the node
//to the type. This mechanism will be used by bhtraits.
//
//If the hook is a member hook, generic hook will directly derive
//from the hook.
: public detail::if_c
< detail::is_same<Tag, member_tag>::value
, typename NodeTraits::node
, node_holder<typename NodeTraits::node, Tag, BaseHookType>
>::type
//If this is the a default-tagged base hook derive from a class that
//will define an special internal typedef. Containers will be able to detect this
//special typedef and obtain generic_hook's internal types in order to deduce
//value_traits for this hook.
, public hook_tags_definer
< generic_hook<Algo, NodeTraits, Tag, LinkMode, BaseHookType>
, detail::is_same<Tag, dft_tag>::value ? BaseHookType : NoBaseHookId>
/// @endcond
{
/// @cond
typedef typename get_algo<Algo, NodeTraits>::type node_algorithms;
typedef typename node_algorithms::node node;
typedef typename node_algorithms::node_ptr node_ptr;
typedef typename node_algorithms::const_node_ptr const_node_ptr;
public:
typedef hooktags_impl
< NodeTraits
, Tag, LinkMode, BaseHookType> hooktags;
BOOST_INTRUSIVE_FORCEINLINE node_ptr this_ptr() BOOST_NOEXCEPT
{ return pointer_traits<node_ptr>::pointer_to(static_cast<node&>(*this)); }
BOOST_INTRUSIVE_FORCEINLINE const_node_ptr this_ptr() const BOOST_NOEXCEPT
{ return pointer_traits<const_node_ptr>::pointer_to(static_cast<const node&>(*this)); }
public:
/// @endcond
BOOST_INTRUSIVE_FORCEINLINE generic_hook() BOOST_NOEXCEPT
{
if(hooktags::safemode_or_autounlink){
node_algorithms::init(this->this_ptr());
}
}
BOOST_INTRUSIVE_FORCEINLINE generic_hook(const generic_hook& ) BOOST_NOEXCEPT
{
if(hooktags::safemode_or_autounlink){
node_algorithms::init(this->this_ptr());
}
}
BOOST_INTRUSIVE_FORCEINLINE generic_hook& operator=(const generic_hook& ) BOOST_NOEXCEPT
{ return *this; }
BOOST_INTRUSIVE_FORCEINLINE ~generic_hook()
{
destructor_impl
(*this, detail::link_dispatch<hooktags::link_mode>());
}
BOOST_INTRUSIVE_FORCEINLINE void swap_nodes(generic_hook &other) BOOST_NOEXCEPT
{
node_algorithms::swap_nodes
(this->this_ptr(), other.this_ptr());
}
BOOST_INTRUSIVE_FORCEINLINE bool is_linked() const BOOST_NOEXCEPT
{
//is_linked() can be only used in safe-mode or auto-unlink
BOOST_STATIC_ASSERT(( hooktags::safemode_or_autounlink ));
return !node_algorithms::unique(this->this_ptr());
}
BOOST_INTRUSIVE_FORCEINLINE void unlink() BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT(( (int)hooktags::link_mode == (int)auto_unlink ));
node_ptr n(this->this_ptr());
if(!node_algorithms::inited(n)){
node_algorithms::unlink(n);
node_algorithms::init(n);
}
}
};
} //namespace intrusive
} //namespace boost
#endif //BOOST_INTRUSIVE_GENERIC_HOOK_HPP

View File

@@ -0,0 +1,222 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2014-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_GET_VALUE_TRAITS_HPP
#define BOOST_INTRUSIVE_DETAIL_GET_VALUE_TRAITS_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/intrusive/detail/config_begin.hpp>
#include <boost/intrusive/detail/mpl.hpp>
#include <boost/intrusive/detail/hook_traits.hpp>
namespace boost {
namespace intrusive {
#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
template<class SupposedValueTraits>
struct is_default_hook_tag
{ static const bool value = false; };
namespace detail{
template <class T, class BaseHook>
struct concrete_hook_base_value_traits
{
typedef typename BaseHook::hooktags tags;
typedef bhtraits
< T
, typename tags::node_traits
, tags::link_mode
, typename tags::tag
, tags::type> type;
};
template <class BaseHook>
struct concrete_hook_base_value_traits<void, BaseHook>
{
typedef typename BaseHook::hooktags type;
};
template <class T, class AnyToSomeHook_ProtoValueTraits>
struct any_hook_base_value_traits
{
//AnyToSomeHook value_traits derive from a generic_hook
//The generic_hook is configured with any_node_traits
//and AnyToSomeHook::value_traits with the correct
//node traits for the container, so use node_traits
//from AnyToSomeHook_ProtoValueTraits and the rest of
//elements from the hooktags member of the generic_hook
typedef typename AnyToSomeHook_ProtoValueTraits::basic_hook_t basic_hook_t;
typedef typename pointer_rebind
< typename basic_hook_t::hooktags::node_traits::node_ptr
, void>::type void_pointer;
typedef typename AnyToSomeHook_ProtoValueTraits::template
node_traits_from_voidptr<void_pointer>::type node_traits;
typedef bhtraits
< T
, node_traits
, basic_hook_t::hooktags::link_mode
, typename basic_hook_t::hooktags::tag
, basic_hook_t::hooktags::type
> type;
};
template <class AnyToSomeHook_ProtoValueTraits>
struct any_hook_base_value_traits<void, AnyToSomeHook_ProtoValueTraits>
{
typedef typename AnyToSomeHook_ProtoValueTraits::basic_hook_t basic_hook_t;
typedef typename pointer_rebind
< typename basic_hook_t::hooktags::node_traits::node_ptr
, void>::type void_pointer;
struct type
{
typedef typename AnyToSomeHook_ProtoValueTraits::template
node_traits_from_voidptr<void_pointer>::type node_traits;
};
};
template<class MemberHook>
struct get_member_value_traits
{
typedef typename MemberHook::member_value_traits type;
};
BOOST_INTRUSIVE_INTERNAL_STATIC_BOOL_IS_TRUE(internal_any_hook, is_any_hook)
BOOST_INTRUSIVE_INTERNAL_STATIC_BOOL_IS_TRUE(internal_base_hook, hooktags::is_base_hook)
template <class T>
struct internal_member_value_traits
{
template <class U> static yes_type test(...);
template <class U> static no_type test(typename U::member_value_traits* = 0);
static const bool value = sizeof(test<T>(0)) == sizeof(no_type);
};
template<class SupposedValueTraits, class T, bool = is_default_hook_tag<SupposedValueTraits>::value>
struct supposed_value_traits;
template<class T, class BaseHook, bool = internal_any_hook_bool_is_true<BaseHook>::value>
struct get_base_value_traits;
template<class SupposedValueTraits, class T, bool = internal_base_hook_bool_is_true<SupposedValueTraits>::value>
struct supposed_base_value_traits;
template<class SupposedValueTraits, bool = internal_member_value_traits<SupposedValueTraits>::value>
struct supposed_member_value_traits;
template<class SupposedValueTraits, bool = internal_any_hook_bool_is_true<SupposedValueTraits>::value>
struct any_or_concrete_value_traits;
//Base any hook
template<class T, class BaseHook>
struct get_base_value_traits<T, BaseHook, true>
: any_hook_base_value_traits<T, BaseHook>
{};
//Non-any base hook
template<class T, class BaseHook>
struct get_base_value_traits<T, BaseHook, false>
: concrete_hook_base_value_traits<T, BaseHook>
{};
//...It's a default hook
template<class SupposedValueTraits, class T>
struct supposed_value_traits<SupposedValueTraits, T, true>
{ typedef typename SupposedValueTraits::template apply<T>::type type; };
//...Not a default hook
template<class SupposedValueTraits, class T>
struct supposed_value_traits<SupposedValueTraits, T, false>
{ typedef SupposedValueTraits type; };
//...It's a base hook
template<class BaseHook, class T>
struct supposed_base_value_traits<BaseHook, T, true>
: get_base_value_traits<T, BaseHook>
{};
//...Not a base hook, try if it's a member or value_traits
template<class SupposedValueTraits, class T>
struct supposed_base_value_traits<SupposedValueTraits, T, false>
: supposed_member_value_traits<SupposedValueTraits>
{};
//...It's a member hook
template<class MemberHook>
struct supposed_member_value_traits<MemberHook, true>
: get_member_value_traits<MemberHook>
{};
//...Not a member hook
template<class SupposedValueTraits>
struct supposed_member_value_traits<SupposedValueTraits, false>
: any_or_concrete_value_traits<SupposedValueTraits>
{};
template<class AnyToSomeHook_ProtoValueTraits>
struct any_or_concrete_value_traits<AnyToSomeHook_ProtoValueTraits, true>
{
//A hook node (non-base, e.g.: member or other value traits
typedef typename AnyToSomeHook_ProtoValueTraits::basic_hook_t basic_hook_t;
typedef typename pointer_rebind
<typename basic_hook_t::node_ptr, void>::type void_pointer;
typedef typename AnyToSomeHook_ProtoValueTraits::template
node_traits_from_voidptr<void_pointer>::type any_node_traits;
struct type : basic_hook_t
{
typedef any_node_traits node_traits;
};
};
template<class SupposedValueTraits>
struct any_or_concrete_value_traits<SupposedValueTraits, false>
{
typedef SupposedValueTraits type;
};
////////////////////////////////////////
// get_value_traits / get_node_traits
////////////////////////////////////////
template<class T, class SupposedValueTraits>
struct get_value_traits
: supposed_base_value_traits<typename supposed_value_traits<SupposedValueTraits, T>::type, T>
{};
template<class SupposedValueTraits>
struct get_node_traits
{
typedef typename get_value_traits<void, SupposedValueTraits>::type::node_traits type;
};
} //namespace detail{
#endif //BOOST_INTRUSIVE_DOXYGEN_INVOKED
} //namespace intrusive {
} //namespace boost {
#include <boost/intrusive/detail/config_end.hpp>
#endif //#ifndef BOOST_INTRUSIVE_DETAIL_GET_VALUE_TRAITS_HPP

View File

@@ -0,0 +1,366 @@
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2014-2014. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/container for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_CALLABLE_WITH_HPP
#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_CALLABLE_WITH_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
//In case no decltype and no variadics, mark that we don't support 0 arg calls due to
//compiler ICE in GCC 3.4/4.0/4.1 and, wrong SFINAE for GCC 4.2/4.3/MSVC10/MSVC11
#if defined(BOOST_NO_CXX11_DECLTYPE) && defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
# if defined(BOOST_GCC) && (BOOST_GCC < 40400)
# define BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED
# elif defined(BOOST_INTEL) && (BOOST_INTEL < 1200)
# define BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED
# elif defined(BOOST_MSVC) && (BOOST_MSVC < 1800)
# define BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED
# endif
#endif //#if defined(BOOST_NO_CXX11_DECLTYPE) && defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
#include <cstddef>
#include <boost/move/utility_core.hpp>
#include <boost/move/detail/fwd_macros.hpp>
namespace boost_intrusive_hmfcw {
typedef char yes_type;
struct no_type{ char dummy[2]; };
struct dont_care
{
dont_care(...);
};
#if defined(BOOST_NO_CXX11_DECLTYPE)
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template<class T>
struct make_dontcare
{
typedef dont_care type;
};
#endif
struct private_type
{
static private_type p;
private_type const &operator,(int) const;
};
template<typename T>
no_type is_private_type(T const &);
yes_type is_private_type(private_type const &);
#endif //#if defined(BOOST_NO_CXX11_DECLTYPE)
#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_DECLTYPE)
template<typename T> struct remove_cv { typedef T type; };
template<typename T> struct remove_cv<const T> { typedef T type; };
template<typename T> struct remove_cv<const volatile T> { typedef T type; };
template<typename T> struct remove_cv<volatile T> { typedef T type; };
#endif
} //namespace boost_intrusive_hmfcw {
#endif //BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_CALLABLE_WITH_HPP
#ifndef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME
#error "You MUST define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME before including this header!"
#endif
#ifndef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN
#error "You MUST define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN before including this header!"
#endif
#ifndef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX
#error "You MUST define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX before including this header!"
#endif
#if BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX < BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN
#error "BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX value MUST be greater or equal than BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN!"
#endif
#if BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX == 0
#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_COMMA_IF
#else
#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_COMMA_IF ,
#endif
#ifndef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG
#error "BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG not defined!"
#endif
#ifndef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END
#error "BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END not defined!"
#endif
BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_DECLTYPE)
//With decltype and variadic templaes, things are pretty easy
template<typename Fun, class ...Args>
struct BOOST_MOVE_CAT(has_member_function_callable_with_,BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)
{
template<class U>
static decltype(boost::move_detail::declval<U>().
BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME(::boost::move_detail::declval<Args>()...)
, boost_intrusive_hmfcw::yes_type()) Test(U* f);
template<class U>
static boost_intrusive_hmfcw::no_type Test(...);
static const bool value = sizeof(Test<Fun>((Fun*)0)) == sizeof(boost_intrusive_hmfcw::yes_type);
};
#else //defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_DECLTYPE)
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
//
// has_member_function_callable_with_impl_XXX
// declaration, special case and 0 arg specializaton
//
/////////////////////////////////////////////////////////
template <typename Type>
class BOOST_MOVE_CAT(has_member_function_named_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)
{
struct BaseMixin
{
void BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME()
{} //Some compilers require the definition or linker errors happen
};
struct Base
: public boost_intrusive_hmfcw::remove_cv<Type>::type, public BaseMixin
{ //Declare the unneeded default constructor as some old compilers wrongly require it with is_convertible
Base(){}
};
template <typename T, T t> class Helper{};
template <typename U>
static boost_intrusive_hmfcw::no_type deduce
(U*, Helper<void (BaseMixin::*)(), &U::BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME>* = 0);
static boost_intrusive_hmfcw::yes_type deduce(...);
public:
static const bool value = sizeof(boost_intrusive_hmfcw::yes_type) == sizeof(deduce((Base*)0));
};
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
//
// has_member_function_callable_with_impl_XXX for 1 to N arguments
//
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
//defined(BOOST_NO_CXX11_DECLTYPE) must be true
template<class Fun>
struct FunWrapTmpl : Fun
{
using Fun::BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME;
FunWrapTmpl();
template<class ...DontCares>
boost_intrusive_hmfcw::private_type BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME(DontCares...) const;
};
template<typename Fun, bool HasFunc, class ...Args>
struct BOOST_MOVE_CAT(has_member_function_callable_with_impl_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME);
//No BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME member specialization
template<typename Fun, class ...Args>
struct BOOST_MOVE_CAT(has_member_function_callable_with_impl_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)
<Fun, false, Args...>
{
static const bool value = false;
};
template<typename Fun, class ...Args>
struct BOOST_MOVE_CAT(has_member_function_callable_with_impl_,BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<Fun, true, Args...>
{
static bool const value = (sizeof(boost_intrusive_hmfcw::no_type) == sizeof(boost_intrusive_hmfcw::is_private_type
( (::boost::move_detail::declval
< FunWrapTmpl<Fun> >().
BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME(::boost::move_detail::declval<Args>()...), 0) )
)
);
};
template<typename Fun, class ...Args>
struct BOOST_MOVE_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)
: public BOOST_MOVE_CAT(has_member_function_callable_with_impl_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)
<Fun
, BOOST_MOVE_CAT(has_member_function_named_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<Fun>::value
, Args...>
{};
#else //defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
//
// has_member_function_callable_with_impl_XXX specializations
//
/////////////////////////////////////////////////////////
template<typename Fun, bool HasFunc BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_COMMA_IF BOOST_MOVE_CAT(BOOST_MOVE_CLASSDFLT,BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX)>
struct BOOST_MOVE_CAT(has_member_function_callable_with_impl_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME);
//No BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME member specialization
template<typename Fun BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_COMMA_IF BOOST_MOVE_CAT(BOOST_MOVE_CLASS,BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX)>
struct BOOST_MOVE_CAT(has_member_function_callable_with_impl_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)
<Fun, false BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_COMMA_IF BOOST_MOVE_CAT(BOOST_MOVE_TARG,BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX)>
{
static const bool value = false;
};
#if BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN == 0
//0 arg specialization when BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME is present
#if !defined(BOOST_NO_CXX11_DECLTYPE)
template<typename Fun>
struct BOOST_MOVE_CAT(has_member_function_callable_with_impl_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<Fun, true>
{
template<class U>
static decltype(boost::move_detail::declval<U>().BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME()
, boost_intrusive_hmfcw::yes_type()) Test(U* f);
template<class U>
static boost_intrusive_hmfcw::no_type Test(...);
static const bool value = sizeof(Test<Fun>((Fun*)0)) == sizeof(boost_intrusive_hmfcw::yes_type);
};
#else //defined(BOOST_NO_CXX11_DECLTYPE)
#if !defined(BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED)
template<class F, std::size_t N = sizeof(boost::move_detail::declval<F>().BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME(), 0)>
struct BOOST_MOVE_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)
{ boost_intrusive_hmfcw::yes_type dummy[N ? 1 : 2]; };
template<typename Fun>
struct BOOST_MOVE_CAT(has_member_function_callable_with_impl_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<Fun, true>
{
template<class U> static BOOST_MOVE_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<U>
Test(BOOST_MOVE_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<U>*);
template<class U> static boost_intrusive_hmfcw::no_type Test(...);
static const bool value = sizeof(Test< Fun >(0)) == sizeof(boost_intrusive_hmfcw::yes_type);
};
#else //defined(BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED)
template<typename Fun>
struct BOOST_MOVE_CAT(has_member_function_callable_with_impl_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<Fun, true>
{ //Some compilers gives ICE when instantiating the 0 arg version so it is not supported.
static const bool value = true;
};
#endif//!defined(BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED)
#endif //!defined(BOOST_NO_CXX11_DECLTYPE)
#endif //#if BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN == 0
#if BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX > 0
//1 to N arg specialization when BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME is present
//Declare some unneeded default constructor as some old compilers wrongly require it with is_convertible
#if defined(BOOST_NO_CXX11_DECLTYPE)
#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_ITERATION(N)\
\
template<class Fun>\
struct BOOST_MOVE_CAT(FunWrap##N, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)\
: Fun\
{\
using Fun::BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME;\
BOOST_MOVE_CAT(FunWrap##N, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)();\
boost_intrusive_hmfcw::private_type BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME\
(BOOST_MOVE_REPEAT##N(boost_intrusive_hmfcw::dont_care)) const;\
};\
\
template<typename Fun, BOOST_MOVE_CLASS##N>\
struct BOOST_MOVE_CAT(has_member_function_callable_with_impl_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<Fun, true, BOOST_MOVE_TARG##N>\
{\
static bool const value = (sizeof(boost_intrusive_hmfcw::no_type) == sizeof(boost_intrusive_hmfcw::is_private_type\
( (::boost::move_detail::declval\
< BOOST_MOVE_CAT(FunWrap##N, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<Fun> >().\
BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME(BOOST_MOVE_DECLVAL##N), 0) )\
)\
);\
};\
//
#else
#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_ITERATION(N)\
template<typename Fun, BOOST_MOVE_CLASS##N>\
struct BOOST_MOVE_CAT(has_member_function_callable_with_impl_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)\
<Fun, true, BOOST_MOVE_TARG##N>\
{\
template<class U>\
static decltype(boost::move_detail::declval<U>().\
BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME(BOOST_MOVE_DECLVAL##N)\
, boost_intrusive_hmfcw::yes_type()) Test(U* f);\
template<class U>\
static boost_intrusive_hmfcw::no_type Test(...);\
static const bool value = sizeof(Test<Fun>((Fun*)0)) == sizeof(boost_intrusive_hmfcw::yes_type);\
};\
//
#endif
////////////////////////////////////
// Build and invoke BOOST_MOVE_ITERATE_NTOM macrofunction, note that N has to be at least 1
////////////////////////////////////
#if BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN == 0
#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_ITERATE_MIN 1
#else
#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_ITERATE_MIN BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN
#endif
BOOST_MOVE_CAT
(BOOST_MOVE_CAT(BOOST_MOVE_CAT(BOOST_MOVE_ITERATE_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_ITERATE_MIN), TO)
,BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX)
(BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_ITERATION)
#undef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_ITERATION
#undef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_ITERATE_MIN
////////////////////////////////////
// End of BOOST_MOVE_ITERATE_NTOM
////////////////////////////////////
#endif //BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX > 0
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
//
// has_member_function_callable_with_FUNC
//
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
//Otherwise use the preprocessor
template<typename Fun BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_COMMA_IF BOOST_MOVE_CAT(BOOST_MOVE_CLASSDFLT,BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX)>
struct BOOST_MOVE_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)
: public BOOST_MOVE_CAT(has_member_function_callable_with_impl_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)
<Fun
, BOOST_MOVE_CAT(has_member_function_named_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<Fun>::value
BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_COMMA_IF BOOST_MOVE_CAT(BOOST_MOVE_TARG,BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX)>
{};
#endif //defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
#endif
BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END
//Undef local macros
#undef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_COMMA_IF
//Undef user defined macros
#undef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME
#undef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN
#undef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX
#undef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG
#undef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END

View File

@@ -0,0 +1,92 @@
// Copyright 2005-2014 Daniel James.
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Based on Peter Dimov's proposal
// http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1756.pdf
// issue 6.18.
//
// This also contains public domain code from MurmurHash. From the
// MurmurHash header:
//
// MurmurHash3 was written by Austin Appleby, and is placed in the public
// domain. The author hereby disclaims copyright to this source code.
//
// Copyright 2021 Ion Gaztanaga
// Refactored the original boost/container_hash/hash.hpp to avoid
// any heavy std header dependencies to just combine two hash
// values represented in a std::size_t type.
#ifndef BOOST_INTRUSIVE_DETAIL_HASH_COMBINE_HPP
#define BOOST_INTRUSIVE_DETAIL_HASH_COMBINE_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/cstdint.hpp>
#if defined(_MSC_VER)
# include <stdlib.h>
# define BOOST_INTRUSIVE_HASH_ROTL32(x, r) _rotl(x,r)
#else
# define BOOST_INTRUSIVE_HASH_ROTL32(x, r) (x << r) | (x >> (32 - r))
#endif
namespace boost {
namespace intrusive {
namespace detail {
template <typename SizeT>
inline void hash_combine_size_t(SizeT& seed, SizeT value)
{
seed ^= value + 0x9e3779b9 + (seed<<6) + (seed>>2);
}
inline void hash_combine_size_t(boost::uint32_t& h1, boost::uint32_t k1)
{
const uint32_t c1 = 0xcc9e2d51;
const uint32_t c2 = 0x1b873593;
k1 *= c1;
k1 = BOOST_INTRUSIVE_HASH_ROTL32(k1,15);
k1 *= c2;
h1 ^= k1;
h1 = BOOST_INTRUSIVE_HASH_ROTL32(h1,13);
h1 = h1*5+0xe6546b64;
}
// Don't define 64-bit hash combine on platforms without 64 bit integers,
// and also not for 32-bit gcc as it warns about the 64-bit constant.
#if !defined(BOOST_NO_INT64_T) && \
!(defined(__GNUC__) && ULONG_MAX == 0xffffffff)
inline void hash_combine_size_t(boost::uint64_t& h, boost::uint64_t k)
{
const boost::uint64_t m = UINT64_C(0xc6a4a7935bd1e995);
const int r = 47;
k *= m;
k ^= k >> r;
k *= m;
h ^= k;
h *= m;
// Completely arbitrary number, to prevent 0's
// from hashing to 0.
h += 0xe6546b64;
}
#endif // BOOST_NO_INT64_T
} //namespace detail {
} //namespace intrusive {
} //namespace boost {
#endif //BOOST_INTRUSIVE_DETAIL_HASH_COMBINE_HPP

View File

@@ -0,0 +1,295 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2007-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_HASHTABLE_NODE_HPP
#define BOOST_INTRUSIVE_HASHTABLE_NODE_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/intrusive/detail/workaround.hpp>
#include <boost/intrusive/detail/assert.hpp>
#include <boost/intrusive/pointer_traits.hpp>
#include <boost/intrusive/detail/mpl.hpp>
#include <boost/intrusive/trivial_value_traits.hpp>
#include <boost/intrusive/slist.hpp> //make_slist
#include <cstddef>
#include <climits>
#include <boost/move/core.hpp>
namespace boost {
namespace intrusive {
template <class Slist>
struct bucket_impl : public Slist
{
typedef Slist slist_type;
BOOST_INTRUSIVE_FORCEINLINE bucket_impl()
{}
BOOST_INTRUSIVE_FORCEINLINE bucket_impl(const bucket_impl &)
{}
BOOST_INTRUSIVE_FORCEINLINE ~bucket_impl()
{
//This bucket is still being used!
BOOST_INTRUSIVE_INVARIANT_ASSERT(Slist::empty());
}
BOOST_INTRUSIVE_FORCEINLINE bucket_impl &operator=(const bucket_impl&)
{
//This bucket is still in use!
BOOST_INTRUSIVE_INVARIANT_ASSERT(Slist::empty());
return *this;
}
};
template<class Slist>
struct bucket_traits_impl
{
private:
BOOST_COPYABLE_AND_MOVABLE(bucket_traits_impl)
public:
/// @cond
typedef typename pointer_traits
<typename Slist::pointer>::template rebind_pointer
< bucket_impl<Slist> >::type bucket_ptr;
typedef Slist slist;
typedef typename Slist::size_type size_type;
/// @endcond
BOOST_INTRUSIVE_FORCEINLINE bucket_traits_impl(bucket_ptr buckets, size_type len)
: buckets_(buckets), buckets_len_(len)
{}
BOOST_INTRUSIVE_FORCEINLINE bucket_traits_impl(const bucket_traits_impl &x)
: buckets_(x.buckets_), buckets_len_(x.buckets_len_)
{}
BOOST_INTRUSIVE_FORCEINLINE bucket_traits_impl(BOOST_RV_REF(bucket_traits_impl) x)
: buckets_(x.buckets_), buckets_len_(x.buckets_len_)
{ x.buckets_ = bucket_ptr(); x.buckets_len_ = 0; }
BOOST_INTRUSIVE_FORCEINLINE bucket_traits_impl& operator=(BOOST_RV_REF(bucket_traits_impl) x)
{
buckets_ = x.buckets_; buckets_len_ = x.buckets_len_;
x.buckets_ = bucket_ptr(); x.buckets_len_ = 0; return *this;
}
BOOST_INTRUSIVE_FORCEINLINE bucket_traits_impl& operator=(BOOST_COPY_ASSIGN_REF(bucket_traits_impl) x)
{
buckets_ = x.buckets_; buckets_len_ = x.buckets_len_; return *this;
}
BOOST_INTRUSIVE_FORCEINLINE bucket_ptr bucket_begin() const
{ return buckets_; }
BOOST_INTRUSIVE_FORCEINLINE size_type bucket_count() const BOOST_NOEXCEPT
{ return buckets_len_; }
private:
bucket_ptr buckets_;
size_type buckets_len_;
};
template <class NodeTraits>
struct hash_reduced_slist_node_traits
{
template <class U> static detail::no_type test(...);
template <class U> static detail::yes_type test(typename U::reduced_slist_node_traits*);
static const bool value = sizeof(test<NodeTraits>(0)) == sizeof(detail::yes_type);
};
template <class NodeTraits>
struct apply_reduced_slist_node_traits
{
typedef typename NodeTraits::reduced_slist_node_traits type;
};
template <class NodeTraits>
struct reduced_slist_node_traits
{
typedef typename detail::eval_if_c
< hash_reduced_slist_node_traits<NodeTraits>::value
, apply_reduced_slist_node_traits<NodeTraits>
, detail::identity<NodeTraits>
>::type type;
};
template<class NodeTraits>
struct get_slist_impl
{
typedef trivial_value_traits<NodeTraits, normal_link> trivial_traits;
//Reducing symbol length
struct type : make_slist
< typename NodeTraits::node
, boost::intrusive::value_traits<trivial_traits>
, boost::intrusive::constant_time_size<false>
, boost::intrusive::size_type<std::size_t>
>::type
{};
};
template<class BucketValueTraits, bool IsConst>
class hashtable_iterator
{
typedef typename BucketValueTraits::value_traits value_traits;
typedef typename BucketValueTraits::bucket_traits bucket_traits;
typedef iiterator< value_traits, IsConst
, std::forward_iterator_tag> types_t;
public:
typedef typename types_t::iterator_type::difference_type difference_type;
typedef typename types_t::iterator_type::value_type value_type;
typedef typename types_t::iterator_type::pointer pointer;
typedef typename types_t::iterator_type::reference reference;
typedef typename types_t::iterator_type::iterator_category iterator_category;
private:
typedef typename value_traits::node_traits node_traits;
typedef typename node_traits::node_ptr node_ptr;
typedef typename get_slist_impl
< typename reduced_slist_node_traits
<node_traits>::type >::type slist_impl;
typedef typename slist_impl::iterator siterator;
typedef typename slist_impl::const_iterator const_siterator;
typedef bucket_impl<slist_impl> bucket_type;
typedef typename pointer_traits
<pointer>::template rebind_pointer
< const BucketValueTraits >::type const_bucketvaltraits_ptr;
typedef typename slist_impl::size_type size_type;
class nat;
typedef typename
detail::if_c< IsConst
, hashtable_iterator<BucketValueTraits, false>
, nat>::type nonconst_iterator;
BOOST_INTRUSIVE_FORCEINLINE static node_ptr downcast_bucket(typename bucket_type::node_ptr p)
{
return pointer_traits<node_ptr>::
pointer_to(static_cast<typename node_traits::node&>(*p));
}
public:
BOOST_INTRUSIVE_FORCEINLINE hashtable_iterator ()
: slist_it_() //Value initialization to achieve "null iterators" (N3644)
{}
BOOST_INTRUSIVE_FORCEINLINE explicit hashtable_iterator(siterator ptr, const BucketValueTraits *cont)
: slist_it_ (ptr)
, traitsptr_ (cont ? pointer_traits<const_bucketvaltraits_ptr>::pointer_to(*cont) : const_bucketvaltraits_ptr() )
{}
BOOST_INTRUSIVE_FORCEINLINE hashtable_iterator(const hashtable_iterator &other)
: slist_it_(other.slist_it()), traitsptr_(other.get_bucket_value_traits())
{}
BOOST_INTRUSIVE_FORCEINLINE hashtable_iterator(const nonconst_iterator &other)
: slist_it_(other.slist_it()), traitsptr_(other.get_bucket_value_traits())
{}
BOOST_INTRUSIVE_FORCEINLINE const siterator &slist_it() const
{ return slist_it_; }
BOOST_INTRUSIVE_FORCEINLINE hashtable_iterator<BucketValueTraits, false> unconst() const
{ return hashtable_iterator<BucketValueTraits, false>(this->slist_it(), this->get_bucket_value_traits()); }
BOOST_INTRUSIVE_FORCEINLINE hashtable_iterator& operator++()
{ this->increment(); return *this; }
BOOST_INTRUSIVE_FORCEINLINE hashtable_iterator &operator=(const hashtable_iterator &other)
{ slist_it_ = other.slist_it(); traitsptr_ = other.get_bucket_value_traits(); return *this; }
BOOST_INTRUSIVE_FORCEINLINE hashtable_iterator operator++(int)
{
hashtable_iterator result (*this);
this->increment();
return result;
}
BOOST_INTRUSIVE_FORCEINLINE friend bool operator== (const hashtable_iterator& i, const hashtable_iterator& i2)
{ return i.slist_it_ == i2.slist_it_; }
BOOST_INTRUSIVE_FORCEINLINE friend bool operator!= (const hashtable_iterator& i, const hashtable_iterator& i2)
{ return !(i == i2); }
BOOST_INTRUSIVE_FORCEINLINE reference operator*() const
{ return *this->operator ->(); }
BOOST_INTRUSIVE_FORCEINLINE pointer operator->() const
{
return this->priv_value_traits().to_value_ptr
(downcast_bucket(slist_it_.pointed_node()));
}
BOOST_INTRUSIVE_FORCEINLINE const_bucketvaltraits_ptr get_bucket_value_traits() const
{ return traitsptr_; }
BOOST_INTRUSIVE_FORCEINLINE const value_traits &priv_value_traits() const
{ return traitsptr_->priv_value_traits(); }
BOOST_INTRUSIVE_FORCEINLINE const bucket_traits &priv_bucket_traits() const
{ return traitsptr_->priv_bucket_traits(); }
private:
void increment()
{
const bucket_traits &rbuck_traits = this->priv_bucket_traits();
bucket_type* const buckets = boost::movelib::to_raw_pointer(rbuck_traits.bucket_begin());
const size_type buckets_len = rbuck_traits.bucket_count();
++slist_it_;
const typename slist_impl::node_ptr n = slist_it_.pointed_node();
const siterator first_bucket_bbegin = buckets->end();
if(first_bucket_bbegin.pointed_node() <= n && n <= buckets[buckets_len-1].cend().pointed_node()){
//If one-past the node is inside the bucket then look for the next non-empty bucket
//1. get the bucket_impl from the iterator
const bucket_type &b = static_cast<const bucket_type&>
(bucket_type::slist_type::container_from_end_iterator(slist_it_));
//2. Now just calculate the index b has in the bucket array
size_type n_bucket = static_cast<size_type>(&b - buckets);
//3. Iterate until a non-empty bucket is found
do{
if (++n_bucket >= buckets_len){ //bucket overflow, return end() iterator
slist_it_ = buckets->before_begin();
return;
}
}
while (buckets[n_bucket].empty());
slist_it_ = buckets[n_bucket].begin();
}
else{
//++slist_it_ yield to a valid object
}
}
siterator slist_it_;
const_bucketvaltraits_ptr traitsptr_;
};
} //namespace intrusive {
} //namespace boost {
#endif

View File

@@ -0,0 +1,195 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_HOOK_TRAITS_HPP
#define BOOST_INTRUSIVE_DETAIL_HOOK_TRAITS_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/intrusive/detail/workaround.hpp>
#include <boost/intrusive/pointer_traits.hpp>
#include <boost/intrusive/detail/parent_from_member.hpp>
#include <boost/intrusive/link_mode.hpp>
#include <boost/intrusive/detail/mpl.hpp>
#include <boost/move/detail/to_raw_pointer.hpp>
#include <boost/intrusive/detail/node_holder.hpp>
namespace boost {
namespace intrusive {
template<class T, class NodePtr, class Tag, unsigned int Type>
struct bhtraits_base
{
public:
typedef NodePtr node_ptr;
typedef typename pointer_traits<node_ptr>::element_type node;
typedef node_holder<node, Tag, Type> node_holder_type;
typedef T value_type;
typedef typename pointer_traits<node_ptr>::
template rebind_pointer<const node>::type const_node_ptr;
typedef typename pointer_traits<node_ptr>::
template rebind_pointer<T>::type pointer;
typedef typename pointer_traits<node_ptr>::
template rebind_pointer<const T>::type const_pointer;
//typedef typename pointer_traits<pointer>::reference reference;
//typedef typename pointer_traits<const_pointer>::reference const_reference;
typedef T & reference;
typedef const T & const_reference;
typedef node_holder_type & node_holder_reference;
typedef const node_holder_type & const_node_holder_reference;
typedef node& node_reference;
typedef const node & const_node_reference;
BOOST_INTRUSIVE_FORCEINLINE static pointer to_value_ptr(node_ptr n)
{
pointer p = pointer_traits<pointer>::pointer_to
(static_cast<reference>(static_cast<node_holder_reference>(*n)));
BOOST_ASSERT(!!p);
return p;
}
BOOST_INTRUSIVE_FORCEINLINE static const_pointer to_value_ptr(const_node_ptr n)
{
const_pointer p = pointer_traits<const_pointer>::pointer_to
(static_cast<const_reference>(static_cast<const_node_holder_reference>(*n)));
BOOST_ASSERT(!!p);
return p;
}
BOOST_INTRUSIVE_FORCEINLINE static node_ptr to_node_ptr(reference value)
{
node_ptr p = pointer_traits<node_ptr>::pointer_to
(static_cast<node_reference>(static_cast<node_holder_reference>(value)));
BOOST_ASSERT(!!p);
return p;
}
BOOST_INTRUSIVE_FORCEINLINE static const_node_ptr to_node_ptr(const_reference value)
{
const_node_ptr p = pointer_traits<const_node_ptr>::pointer_to
(static_cast<const_node_reference>(static_cast<const_node_holder_reference>(value)));
BOOST_ASSERT(!!p);
return p;
}
};
template<class T, class NodeTraits, link_mode_type LinkMode, class Tag, unsigned int Type>
struct bhtraits
: public bhtraits_base<T, typename NodeTraits::node_ptr, Tag, Type>
{
static const link_mode_type link_mode = LinkMode;
typedef NodeTraits node_traits;
};
template<class T, class Hook, Hook T::* P>
struct mhtraits
{
public:
typedef Hook hook_type;
typedef typename hook_type::hooktags::node_traits node_traits;
typedef typename node_traits::node node;
typedef T value_type;
typedef typename node_traits::node_ptr node_ptr;
typedef typename node_traits::const_node_ptr const_node_ptr;
typedef typename pointer_traits<node_ptr>::
template rebind_pointer<T>::type pointer;
typedef typename pointer_traits<node_ptr>::
template rebind_pointer<const T>::type const_pointer;
typedef T & reference;
typedef const T & const_reference;
typedef node& node_reference;
typedef const node & const_node_reference;
typedef hook_type& hook_reference;
typedef const hook_type & const_hook_reference;
static const link_mode_type link_mode = Hook::hooktags::link_mode;
BOOST_INTRUSIVE_FORCEINLINE static node_ptr to_node_ptr(reference value)
{
return pointer_traits<node_ptr>::pointer_to
(static_cast<node_reference>(static_cast<hook_reference>(value.*P)));
}
BOOST_INTRUSIVE_FORCEINLINE static const_node_ptr to_node_ptr(const_reference value)
{
return pointer_traits<const_node_ptr>::pointer_to
(static_cast<const_node_reference>(static_cast<const_hook_reference>(value.*P)));
}
BOOST_INTRUSIVE_FORCEINLINE static pointer to_value_ptr(node_ptr n)
{
return pointer_traits<pointer>::pointer_to
(*detail::parent_from_member<T, Hook>
(static_cast<Hook*>(boost::movelib::to_raw_pointer(n)), P));
}
BOOST_INTRUSIVE_FORCEINLINE static const_pointer to_value_ptr(const_node_ptr n)
{
return pointer_traits<const_pointer>::pointer_to
(*detail::parent_from_member<T, Hook>
(static_cast<const Hook*>(boost::movelib::to_raw_pointer(n)), P));
}
};
template<class Functor>
struct fhtraits
{
public:
typedef typename Functor::hook_type hook_type;
typedef typename Functor::hook_ptr hook_ptr;
typedef typename Functor::const_hook_ptr const_hook_ptr;
typedef typename hook_type::hooktags::node_traits node_traits;
typedef typename node_traits::node node;
typedef typename Functor::value_type value_type;
typedef typename node_traits::node_ptr node_ptr;
typedef typename node_traits::const_node_ptr const_node_ptr;
typedef typename pointer_traits<node_ptr>::
template rebind_pointer<value_type>::type pointer;
typedef typename pointer_traits<node_ptr>::
template rebind_pointer<const value_type>::type const_pointer;
typedef value_type & reference;
typedef const value_type & const_reference;
static const link_mode_type link_mode = hook_type::hooktags::link_mode;
static node_ptr to_node_ptr(reference value)
{ return static_cast<node*>(boost::movelib::to_raw_pointer(Functor::to_hook_ptr(value))); }
static const_node_ptr to_node_ptr(const_reference value)
{ return static_cast<const node*>(boost::movelib::to_raw_pointer(Functor::to_hook_ptr(value))); }
static pointer to_value_ptr(node_ptr n)
{ return Functor::to_value_ptr(to_hook_ptr(n)); }
static const_pointer to_value_ptr(const_node_ptr n)
{ return Functor::to_value_ptr(to_hook_ptr(n)); }
private:
static hook_ptr to_hook_ptr(node_ptr n)
{ return hook_ptr(&*static_cast<hook_type*>(&*n)); }
static const_hook_ptr to_hook_ptr(const_node_ptr n)
{ return const_hook_ptr(&*static_cast<const hook_type*>(&*n)); }
};
} //namespace intrusive
} //namespace boost
#endif //BOOST_INTRUSIVE_DETAIL_HOOK_TRAITS_HPP

View File

@@ -0,0 +1,122 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_IITERATOR_HPP
#define BOOST_INTRUSIVE_DETAIL_IITERATOR_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/intrusive/detail/workaround.hpp>
#include <boost/intrusive/detail/iterator.hpp>
#include <boost/intrusive/pointer_traits.hpp>
#include <boost/intrusive/detail/mpl.hpp>
#include <boost/intrusive/detail/is_stateful_value_traits.hpp>
namespace boost {
namespace intrusive {
template<class ValueTraits>
struct value_traits_pointers
{
typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT
(boost::intrusive::detail::
, ValueTraits, value_traits_ptr
, typename boost::intrusive::pointer_traits<typename ValueTraits::node_traits::node_ptr>::template
rebind_pointer<ValueTraits>::type) value_traits_ptr;
typedef typename boost::intrusive::pointer_traits<value_traits_ptr>::template
rebind_pointer<ValueTraits const>::type const_value_traits_ptr;
};
template<class ValueTraits, bool IsConst, class Category>
struct iiterator
{
typedef ValueTraits value_traits;
typedef typename value_traits::node_traits node_traits;
typedef typename node_traits::node node;
typedef typename node_traits::node_ptr node_ptr;
typedef ::boost::intrusive::pointer_traits<node_ptr> nodepointer_traits_t;
typedef typename nodepointer_traits_t::template
rebind_pointer<void>::type void_pointer;
typedef typename ValueTraits::value_type value_type;
typedef typename ValueTraits::pointer nonconst_pointer;
typedef typename ValueTraits::const_pointer yesconst_pointer;
typedef typename ::boost::intrusive::pointer_traits
<nonconst_pointer>::reference nonconst_reference;
typedef typename ::boost::intrusive::pointer_traits
<yesconst_pointer>::reference yesconst_reference;
typedef typename nodepointer_traits_t::difference_type difference_type;
typedef typename detail::if_c
<IsConst, yesconst_pointer, nonconst_pointer>::type pointer;
typedef typename detail::if_c
<IsConst, yesconst_reference, nonconst_reference>::type reference;
typedef iterator
< Category
, value_type
, difference_type
, pointer
, reference
> iterator_type;
typedef typename value_traits_pointers
<ValueTraits>::value_traits_ptr value_traits_ptr;
typedef typename value_traits_pointers
<ValueTraits>::const_value_traits_ptr const_value_traits_ptr;
static const bool stateful_value_traits =
detail::is_stateful_value_traits<value_traits>::value;
};
template<class NodePtr, class StoredPointer, bool StatefulValueTraits = true>
struct iiterator_members
{
BOOST_INTRUSIVE_FORCEINLINE iiterator_members()
: nodeptr_()//Value initialization to achieve "null iterators" (N3644)
{}
BOOST_INTRUSIVE_FORCEINLINE iiterator_members(const NodePtr &n_ptr, const StoredPointer &data)
: nodeptr_(n_ptr), ptr_(data)
{}
BOOST_INTRUSIVE_FORCEINLINE StoredPointer get_ptr() const
{ return ptr_; }
NodePtr nodeptr_;
StoredPointer ptr_;
};
template<class NodePtr, class StoredPointer>
struct iiterator_members<NodePtr, StoredPointer, false>
{
BOOST_INTRUSIVE_FORCEINLINE iiterator_members()
: nodeptr_()//Value initialization to achieve "null iterators" (N3644)
{}
BOOST_INTRUSIVE_FORCEINLINE iiterator_members(const NodePtr &n_ptr, const StoredPointer &)
: nodeptr_(n_ptr)
{}
BOOST_INTRUSIVE_FORCEINLINE StoredPointer get_ptr() const
{ return StoredPointer(); }
NodePtr nodeptr_;
};
} //namespace intrusive
} //namespace boost
#endif //BOOST_INTRUSIVE_DETAIL_IITERATOR_HPP

View File

@@ -0,0 +1,81 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2009-2013.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_IS_STATEFUL_VALUE_TRAITS_HPP
#define BOOST_INTRUSIVE_DETAIL_IS_STATEFUL_VALUE_TRAITS_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#if defined(_MSC_VER) && (_MSC_VER <= 1310)
#include <boost/intrusive/detail/mpl.hpp>
namespace boost {
namespace intrusive {
namespace detail {
template<class ValueTraits>
struct is_stateful_value_traits
{
static const bool value = !detail::is_empty<ValueTraits>::value;
};
}}}
#else
#include <boost/intrusive/detail/function_detector.hpp>
BOOST_INTRUSIVE_CREATE_FUNCTION_DETECTOR(to_node_ptr, boost_intrusive)
BOOST_INTRUSIVE_CREATE_FUNCTION_DETECTOR(to_value_ptr, boost_intrusive)
namespace boost {
namespace intrusive {
namespace detail {
template<class ValueTraits>
struct is_stateful_value_traits
{
typedef typename ValueTraits::node_ptr node_ptr;
typedef typename ValueTraits::pointer pointer;
typedef typename ValueTraits::value_type value_type;
typedef typename ValueTraits::const_node_ptr const_node_ptr;
typedef typename ValueTraits::const_pointer const_pointer;
typedef ValueTraits value_traits;
static const bool value =
(boost::intrusive::function_detector::NonStaticFunction ==
(BOOST_INTRUSIVE_DETECT_FUNCTION(ValueTraits, boost_intrusive, node_ptr, to_node_ptr, (value_type&) )))
||
(boost::intrusive::function_detector::NonStaticFunction ==
(BOOST_INTRUSIVE_DETECT_FUNCTION(ValueTraits, boost_intrusive, pointer, to_value_ptr, (node_ptr) )))
||
(boost::intrusive::function_detector::NonStaticFunction ==
(BOOST_INTRUSIVE_DETECT_FUNCTION(ValueTraits, boost_intrusive, const_node_ptr, to_node_ptr, (const value_type&) )))
||
(boost::intrusive::function_detector::NonStaticFunction ==
(BOOST_INTRUSIVE_DETECT_FUNCTION(ValueTraits, boost_intrusive, const_pointer, to_value_ptr, (const_node_ptr) )))
;
};
}}}
#endif
#endif //@ifndef BOOST_INTRUSIVE_DETAIL_IS_STATEFUL_VALUE_TRAITS_HPP

View File

@@ -0,0 +1,292 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2014-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_ITERATOR_HPP
#define BOOST_INTRUSIVE_DETAIL_ITERATOR_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <cstddef>
#include <boost/intrusive/detail/std_fwd.hpp>
#include <boost/intrusive/detail/workaround.hpp>
#include <boost/move/detail/iterator_traits.hpp>
#include <boost/move/detail/meta_utils_core.hpp>
namespace boost{
namespace iterators{
struct incrementable_traversal_tag;
struct single_pass_traversal_tag;
struct forward_traversal_tag;
struct bidirectional_traversal_tag;
struct random_access_traversal_tag;
namespace detail{
template <class Category, class Traversal>
struct iterator_category_with_traversal;
} //namespace boost{
} //namespace iterators{
} //namespace detail{
namespace boost {
namespace intrusive {
using boost::movelib::iterator_traits;
using boost::movelib::iter_difference;
using boost::movelib::iter_value;
using boost::movelib::iter_category;
using boost::movelib::iter_size;
////////////////////
// iterator
////////////////////
template<class Category, class T, class Difference, class Pointer, class Reference>
struct iterator
{
typedef Category iterator_category;
typedef T value_type;
typedef Difference difference_type;
typedef Pointer pointer;
typedef Reference reference;
};
////////////////////////////////////////////////////////////////////////////////
// Conversion from boost::iterator traversals to std tags
////////////////////////////////////////////////////////////////////////////////
template<class Tag>
struct get_std_category_from_tag
{
typedef Tag type;
};
template <class Category>
struct get_std_category_from_tag
<boost::iterators::detail::iterator_category_with_traversal
<Category, boost::iterators::incrementable_traversal_tag> >
{
typedef std::input_iterator_tag type;
};
template <class Category>
struct get_std_category_from_tag
<boost::iterators::detail::iterator_category_with_traversal
<Category, boost::iterators::single_pass_traversal_tag> >
{
typedef std::input_iterator_tag type;
};
template <class Category>
struct get_std_category_from_tag
<boost::iterators::detail::iterator_category_with_traversal
<Category, boost::iterators::forward_traversal_tag> >
{
typedef std::input_iterator_tag type;
};
template <class Category>
struct get_std_category_from_tag
<boost::iterators::detail::iterator_category_with_traversal
<Category, boost::iterators::bidirectional_traversal_tag> >
{
typedef std::bidirectional_iterator_tag type;
};
template <class Category>
struct get_std_category_from_tag
<boost::iterators::detail::iterator_category_with_traversal
<Category, boost::iterators::random_access_traversal_tag> >
{
typedef std::random_access_iterator_tag type;
};
template<class It>
struct get_std_category_from_it
: get_std_category_from_tag< typename boost::intrusive::iter_category<It>::type >
{};
////////////////////////////////////////
// iterator_[dis|en]able_if_tag
////////////////////////////////////////
template<class I, class Tag, class R = void>
struct iterator_enable_if_tag
: ::boost::move_detail::enable_if_c
< ::boost::move_detail::is_same
< typename get_std_category_from_it<I>::type
, Tag
>::value
, R>
{};
template<class I, class Tag, class R = void>
struct iterator_disable_if_tag
: ::boost::move_detail::enable_if_c
< !::boost::move_detail::is_same
< typename get_std_category_from_it<I>::type
, Tag
>::value
, R>
{};
////////////////////////////////////////
// iterator_[dis|en]able_if_tag
////////////////////////////////////////
template<class I, class Tag, class Tag2, class R = void>
struct iterator_enable_if_convertible_tag
: ::boost::move_detail::enable_if_c
< ::boost::move_detail::is_same_or_convertible
< typename get_std_category_from_it<I>::type
, Tag
>::value &&
!::boost::move_detail::is_same_or_convertible
< typename get_std_category_from_it<I>::type
, Tag2
>::value
, R>
{};
////////////////////////////////////////
// iterator_[dis|en]able_if_tag_difference_type
////////////////////////////////////////
template<class I, class Tag>
struct iterator_enable_if_tag_difference_type
: iterator_enable_if_tag<I, Tag, typename boost::intrusive::iter_difference<I>::type>
{};
template<class I, class Tag>
struct iterator_disable_if_tag_difference_type
: iterator_disable_if_tag<I, Tag, typename boost::intrusive::iter_difference<I>::type>
{};
////////////////////
// advance
////////////////////
template<class InputIt>
BOOST_INTRUSIVE_FORCEINLINE typename iterator_enable_if_tag<InputIt, std::input_iterator_tag>::type
iterator_advance(InputIt& it, typename iter_difference<InputIt>::type n)
{
while(n--)
++it;
}
template<class InputIt>
typename iterator_enable_if_tag<InputIt, std::forward_iterator_tag>::type
iterator_advance(InputIt& it, typename iter_difference<InputIt>::type n)
{
while(n--)
++it;
}
template<class InputIt>
BOOST_INTRUSIVE_FORCEINLINE typename iterator_enable_if_tag<InputIt, std::bidirectional_iterator_tag>::type
iterator_advance(InputIt& it, typename iter_difference<InputIt>::type n)
{
for (; 0 < n; --n)
++it;
for (; n < 0; ++n)
--it;
}
template<class InputIt, class Distance>
BOOST_INTRUSIVE_FORCEINLINE typename iterator_enable_if_tag<InputIt, std::random_access_iterator_tag>::type
iterator_advance(InputIt& it, Distance n)
{
it += n;
}
template<class It>
BOOST_INTRUSIVE_FORCEINLINE
void iterator_uadvance(It& it, typename iter_size<It>::type n)
{
(iterator_advance)(it, (typename iterator_traits<It>::difference_type)n);
}
////////////////////////////////////////
// iterator_distance
////////////////////////////////////////
template<class InputIt> inline
typename iterator_disable_if_tag_difference_type
<InputIt, std::random_access_iterator_tag>::type
iterator_distance(InputIt first, InputIt last)
{
typename iter_difference<InputIt>::type off = 0;
while(first != last){
++off;
++first;
}
return off;
}
template<class InputIt>
BOOST_INTRUSIVE_FORCEINLINE typename iterator_enable_if_tag_difference_type
<InputIt, std::random_access_iterator_tag>::type
iterator_distance(InputIt first, InputIt last)
{
typename iter_difference<InputIt>::type off = last - first;
return off;
}
////////////////////////////////////////
// iterator_udistance
////////////////////////////////////////
template<class It>
BOOST_INTRUSIVE_FORCEINLINE typename iter_size<It>::type
iterator_udistance(It first, It last)
{
return (typename iter_size<It>::type)(iterator_distance)(first, last);
}
////////////////////////////////////////
// iterator_next
////////////////////////////////////////
template<class InputIt>
BOOST_INTRUSIVE_FORCEINLINE InputIt iterator_next(InputIt it, typename iter_difference<InputIt>::type n)
{
(iterator_advance)(it, n);
return it;
}
template<class InputIt>
BOOST_INTRUSIVE_FORCEINLINE InputIt iterator_unext(InputIt it, typename iterator_traits<InputIt>::size_type n)
{
(iterator_uadvance)(it, n);
return it;
}
////////////////////////////////////////
// iterator_arrow_result
////////////////////////////////////////
template<class I>
BOOST_INTRUSIVE_FORCEINLINE typename iterator_traits<I>::pointer iterator_arrow_result(const I &i)
{ return i.operator->(); }
template<class T>
BOOST_INTRUSIVE_FORCEINLINE T * iterator_arrow_result(T *p)
{ return p; }
} //namespace intrusive
} //namespace boost
#endif //BOOST_INTRUSIVE_DETAIL_ITERATOR_HPP

View File

@@ -0,0 +1,125 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2014-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_KEY_NODEPTR_COMP_HPP
#define BOOST_INTRUSIVE_DETAIL_KEY_NODEPTR_COMP_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/intrusive/detail/mpl.hpp>
#include <boost/intrusive/detail/ebo_functor_holder.hpp>
#include <boost/intrusive/detail/tree_value_compare.hpp>
namespace boost {
namespace intrusive {
namespace detail {
template < class KeyTypeKeyCompare
, class ValueTraits
, class KeyOfValue
>
struct key_nodeptr_comp_types
{
typedef ValueTraits value_traits;
typedef typename value_traits::value_type value_type;
typedef typename value_traits::node_ptr node_ptr;
typedef typename value_traits::const_node_ptr const_node_ptr;
typedef typename detail::if_c
< detail::is_same<KeyOfValue, void>::value
, detail::identity<value_type>
, KeyOfValue
>::type key_of_value;
typedef tree_value_compare
<typename ValueTraits::pointer, KeyTypeKeyCompare, key_of_value> base_t;
};
//This function object transforms a key comparison type to
//a function that can compare nodes or nodes with nodes or keys.
template < class KeyTypeKeyCompare
, class ValueTraits
, class KeyOfValue = void
>
struct key_nodeptr_comp
//Use public inheritance to avoid MSVC bugs with closures
: public key_nodeptr_comp_types<KeyTypeKeyCompare, ValueTraits, KeyOfValue>::base_t
{
private:
struct sfinae_type;
public:
typedef key_nodeptr_comp_types<KeyTypeKeyCompare, ValueTraits, KeyOfValue> types_t;
typedef typename types_t::value_traits value_traits;
typedef typename types_t::value_type value_type;
typedef typename types_t::node_ptr node_ptr;
typedef typename types_t::const_node_ptr const_node_ptr;
typedef typename types_t::base_t base_t;
typedef typename types_t::key_of_value key_of_value;
template <class P1>
struct is_same_or_nodeptr_convertible
{
static const bool same_type = is_same<P1,const_node_ptr>::value || is_same<P1,node_ptr>::value;
static const bool value = same_type || is_convertible<P1, const_node_ptr>::value;
};
BOOST_INTRUSIVE_FORCEINLINE base_t base() const
{ return static_cast<const base_t&>(*this); }
BOOST_INTRUSIVE_FORCEINLINE key_nodeptr_comp(KeyTypeKeyCompare kcomp, const ValueTraits *traits)
: base_t(kcomp), traits_(traits)
{}
//pred(pnode)
template<class T1>
BOOST_INTRUSIVE_FORCEINLINE bool operator()(const T1 &t1, typename enable_if_c< is_same_or_nodeptr_convertible<T1>::value, sfinae_type* >::type = 0) const
{ return base().get()(key_of_value()(*traits_->to_value_ptr(t1))); }
//operator() 2 arg
//pred(pnode, pnode)
template<class T1, class T2>
BOOST_INTRUSIVE_FORCEINLINE bool operator()
(const T1 &t1, const T2 &t2, typename enable_if_c< is_same_or_nodeptr_convertible<T1>::value && is_same_or_nodeptr_convertible<T2>::value, sfinae_type* >::type = 0) const
{ return base()(*traits_->to_value_ptr(t1), *traits_->to_value_ptr(t2)); }
//pred(pnode, key)
template<class T1, class T2>
BOOST_INTRUSIVE_FORCEINLINE bool operator()
(const T1 &t1, const T2 &t2, typename enable_if_c< is_same_or_nodeptr_convertible<T1>::value && !is_same_or_nodeptr_convertible<T2>::value, sfinae_type* >::type = 0) const
{ return base()(*traits_->to_value_ptr(t1), t2); }
//pred(key, pnode)
template<class T1, class T2>
BOOST_INTRUSIVE_FORCEINLINE bool operator()
(const T1 &t1, const T2 &t2, typename enable_if_c< !is_same_or_nodeptr_convertible<T1>::value && is_same_or_nodeptr_convertible<T2>::value, sfinae_type* >::type = 0) const
{ return base()(t1, *traits_->to_value_ptr(t2)); }
//pred(key, key)
template<class T1, class T2>
BOOST_INTRUSIVE_FORCEINLINE bool operator()
(const T1 &t1, const T2 &t2, typename enable_if_c< !is_same_or_nodeptr_convertible<T1>::value && !is_same_or_nodeptr_convertible<T2>::value, sfinae_type* >::type = 0) const
{ return base()(t1, t2); }
const ValueTraits *const traits_;
};
} //namespace detail{
} //namespace intrusive{
} //namespace boost{
#endif //BOOST_INTRUSIVE_DETAIL_KEY_NODEPTR_COMP_HPP

View File

@@ -0,0 +1,146 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Olaf Krzikalla 2004-2006.
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_LIST_ITERATOR_HPP
#define BOOST_INTRUSIVE_LIST_ITERATOR_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/intrusive/detail/workaround.hpp>
#include <boost/intrusive/detail/std_fwd.hpp>
#include <boost/intrusive/detail/iiterator.hpp>
#include <boost/intrusive/detail/mpl.hpp>
namespace boost {
namespace intrusive {
// list_iterator provides some basic functions for a
// node oriented bidirectional iterator:
template<class ValueTraits, bool IsConst>
class list_iterator
{
private:
typedef iiterator
<ValueTraits, IsConst, std::bidirectional_iterator_tag> types_t;
static const bool stateful_value_traits = types_t::stateful_value_traits;
typedef ValueTraits value_traits;
typedef typename types_t::node_traits node_traits;
typedef typename types_t::node node;
typedef typename types_t::node_ptr node_ptr;
typedef typename types_t::const_value_traits_ptr const_value_traits_ptr;
class nat;
typedef typename
detail::if_c< IsConst
, list_iterator<value_traits, false>
, nat>::type nonconst_iterator;
public:
typedef typename types_t::iterator_type::difference_type difference_type;
typedef typename types_t::iterator_type::value_type value_type;
typedef typename types_t::iterator_type::pointer pointer;
typedef typename types_t::iterator_type::reference reference;
typedef typename types_t::iterator_type::iterator_category iterator_category;
BOOST_INTRUSIVE_FORCEINLINE list_iterator()
{}
BOOST_INTRUSIVE_FORCEINLINE explicit list_iterator(node_ptr nodeptr, const_value_traits_ptr traits_ptr)
: members_(nodeptr, traits_ptr)
{}
BOOST_INTRUSIVE_FORCEINLINE list_iterator(const list_iterator &other)
: members_(other.pointed_node(), other.get_value_traits())
{}
BOOST_INTRUSIVE_FORCEINLINE list_iterator(const nonconst_iterator &other)
: members_(other.pointed_node(), other.get_value_traits())
{}
BOOST_INTRUSIVE_FORCEINLINE list_iterator &operator=(const list_iterator &other)
{ members_.nodeptr_ = other.members_.nodeptr_; return *this; }
BOOST_INTRUSIVE_FORCEINLINE node_ptr pointed_node() const
{ return members_.nodeptr_; }
BOOST_INTRUSIVE_FORCEINLINE list_iterator &operator=(node_ptr nodeptr)
{ members_.nodeptr_ = nodeptr; return *this; }
BOOST_INTRUSIVE_FORCEINLINE const_value_traits_ptr get_value_traits() const
{ return members_.get_ptr(); }
public:
BOOST_INTRUSIVE_FORCEINLINE list_iterator& operator++()
{
node_ptr p = node_traits::get_next(members_.nodeptr_);
members_.nodeptr_ = p;
return static_cast<list_iterator&> (*this);
}
BOOST_INTRUSIVE_FORCEINLINE list_iterator operator++(int)
{
list_iterator result (*this);
members_.nodeptr_ = node_traits::get_next(members_.nodeptr_);
return result;
}
BOOST_INTRUSIVE_FORCEINLINE list_iterator& operator--()
{
members_.nodeptr_ = node_traits::get_previous(members_.nodeptr_);
return static_cast<list_iterator&> (*this);
}
BOOST_INTRUSIVE_FORCEINLINE list_iterator operator--(int)
{
list_iterator result (*this);
members_.nodeptr_ = node_traits::get_previous(members_.nodeptr_);
return result;
}
BOOST_INTRUSIVE_FORCEINLINE friend bool operator== (const list_iterator& l, const list_iterator& r)
{ return l.pointed_node() == r.pointed_node(); }
BOOST_INTRUSIVE_FORCEINLINE friend bool operator!= (const list_iterator& l, const list_iterator& r)
{ return !(l == r); }
BOOST_INTRUSIVE_FORCEINLINE reference operator*() const
{ return *operator->(); }
BOOST_INTRUSIVE_FORCEINLINE pointer operator->() const
{ return this->operator_arrow(detail::bool_<stateful_value_traits>()); }
BOOST_INTRUSIVE_FORCEINLINE list_iterator<ValueTraits, false> unconst() const
{ return list_iterator<ValueTraits, false>(this->pointed_node(), this->get_value_traits()); }
private:
BOOST_INTRUSIVE_FORCEINLINE pointer operator_arrow(detail::false_) const
{ return ValueTraits::to_value_ptr(members_.nodeptr_); }
BOOST_INTRUSIVE_FORCEINLINE pointer operator_arrow(detail::true_) const
{ return this->get_value_traits()->to_value_ptr(members_.nodeptr_); }
iiterator_members<node_ptr, const_value_traits_ptr, stateful_value_traits> members_;
};
} //namespace intrusive
} //namespace boost
#endif //BOOST_INTRUSIVE_LIST_ITERATOR_HPP

View File

@@ -0,0 +1,72 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Olaf Krzikalla 2004-2006.
// (C) Copyright Ion Gaztanaga 2006-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_LIST_NODE_HPP
#define BOOST_INTRUSIVE_LIST_NODE_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/intrusive/detail/workaround.hpp>
#include <boost/intrusive/pointer_rebind.hpp>
namespace boost {
namespace intrusive {
// list_node_traits can be used with circular_list_algorithms and supplies
// a list_node holding the pointers needed for a double-linked list
// it is used by list_derived_node and list_member_node
template<class VoidPointer>
struct list_node
{
typedef typename pointer_rebind<VoidPointer, list_node>::type node_ptr;
node_ptr next_;
node_ptr prev_;
};
template<class VoidPointer>
struct list_node_traits
{
typedef list_node<VoidPointer> node;
typedef typename node::node_ptr node_ptr;
typedef typename pointer_rebind<VoidPointer, const node>::type const_node_ptr;
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_previous(const_node_ptr n)
{ return n->prev_; }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_previous(node_ptr n)
{ return n->prev_; }
BOOST_INTRUSIVE_FORCEINLINE static void set_previous(node_ptr n, node_ptr prev)
{ n->prev_ = prev; }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_next(const_node_ptr n)
{ return n->next_; }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_next(node_ptr n)
{ return n->next_; }
BOOST_INTRUSIVE_FORCEINLINE static void set_next(node_ptr n, node_ptr next)
{ n->next_ = next; }
};
} //namespace intrusive
} //namespace boost
#endif //BOOST_INTRUSIVE_LIST_NODE_HPP

View File

@@ -0,0 +1,242 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2014-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_MATH_HPP
#define BOOST_INTRUSIVE_DETAIL_MATH_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <cstddef>
#include <climits>
#include <boost/intrusive/detail/mpl.hpp>
#include <cstring>
namespace boost {
namespace intrusive {
namespace detail {
///////////////////////////
// floor_log2 Dispatcher
////////////////////////////
#if defined(_MSC_VER) && (_MSC_VER >= 1300)
}}} //namespace boost::intrusive::detail
//Use _BitScanReverseXX intrinsics
#if defined(_M_X64) || defined(_M_AMD64) || defined(_M_IA64) //64 bit target
#define BOOST_INTRUSIVE_BSR_INTRINSIC_64_BIT
#endif
#ifndef __INTRIN_H_ // Avoid including any windows system header
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
#if defined(BOOST_INTRUSIVE_BSR_INTRINSIC_64_BIT) //64 bit target
unsigned char _BitScanReverse64(unsigned long *index, unsigned __int64 mask);
#pragma intrinsic(_BitScanReverse64)
#else //32 bit target
unsigned char _BitScanReverse(unsigned long *index, unsigned long mask);
#pragma intrinsic(_BitScanReverse)
#endif
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // __INTRIN_H_
#ifdef BOOST_INTRUSIVE_BSR_INTRINSIC_64_BIT
#define BOOST_INTRUSIVE_BSR_INTRINSIC _BitScanReverse64
#undef BOOST_INTRUSIVE_BSR_INTRINSIC_64_BIT
#else
#define BOOST_INTRUSIVE_BSR_INTRINSIC _BitScanReverse
#endif
namespace boost {
namespace intrusive {
namespace detail {
inline std::size_t floor_log2 (std::size_t x)
{
unsigned long log2;
BOOST_INTRUSIVE_BSR_INTRINSIC( &log2, x );
return static_cast<std::size_t>(log2);
}
#undef BOOST_INTRUSIVE_BSR_INTRINSIC
#elif defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) //GCC >=3.4
//Compile-time error in case of missing specialization
template<class Uint>
struct builtin_clz_dispatch;
#if defined(BOOST_HAS_LONG_LONG)
template<>
struct builtin_clz_dispatch< ::boost::ulong_long_type >
{
static ::boost::ulong_long_type call(::boost::ulong_long_type n)
{ return (::boost::ulong_long_type)__builtin_clzll(n); }
};
#endif
template<>
struct builtin_clz_dispatch<unsigned long>
{
static unsigned long call(unsigned long n)
{ return (unsigned long)__builtin_clzl(n); }
};
template<>
struct builtin_clz_dispatch<unsigned int>
{
static unsigned int call(unsigned int n)
{ return (unsigned int)__builtin_clz(n); }
};
inline std::size_t floor_log2(std::size_t n)
{
return sizeof(std::size_t)*CHAR_BIT - std::size_t(1) - builtin_clz_dispatch<std::size_t>::call(n);
}
#else //Portable methods
////////////////////////////
// Generic method
////////////////////////////
inline std::size_t floor_log2_get_shift(std::size_t n, true_ )//power of two size_t
{ return n >> 1; }
inline std::size_t floor_log2_get_shift(std::size_t n, false_ )//non-power of two size_t
{ return (n >> 1) + ((n & 1u) & (n != 1)); }
template<std::size_t N>
inline std::size_t floor_log2 (std::size_t x, integral_constant<std::size_t, N>)
{
const std::size_t Bits = N;
const bool Size_t_Bits_Power_2= !(Bits & (Bits-1));
std::size_t n = x;
std::size_t log2 = 0;
std::size_t remaining_bits = Bits;
std::size_t shift = floor_log2_get_shift(remaining_bits, bool_<Size_t_Bits_Power_2>());
while(shift){
std::size_t tmp = n >> shift;
if (tmp){
log2 += shift, n = tmp;
}
shift = floor_log2_get_shift(shift, bool_<Size_t_Bits_Power_2>());
}
return log2;
}
inline std::size_t floor_log2 (std::size_t x)
{
const std::size_t Bits = sizeof(std::size_t)*CHAR_BIT;
return floor_log2(x, integral_constant<std::size_t, Bits>());
}
#endif
//Thanks to Laurent de Soras in
//http://www.flipcode.com/archives/Fast_log_Function.shtml
inline float fast_log2 (float val)
{
unsigned x;
std::memcpy(&x, &val, sizeof(float));
const int log_2 = int((x >> 23) & 255) - 128;
x &= ~(unsigned(255u) << 23u);
x += unsigned(127) << 23u;
std::memcpy(&val, &x, sizeof(float));
//1+log2(m), m ranging from 1 to 2
//3rd degree polynomial keeping first derivate continuity.
//For less precision the line can be commented out
val = ((-1.f/3.f) * val + 2.f) * val - (2.f/3.f);
return val + static_cast<float>(log_2);
}
inline bool is_pow2(std::size_t x)
{ return (x & (x-1)) == 0; }
template<std::size_t N>
struct static_is_pow2
{
static const bool value = (N & (N-1)) == 0;
};
inline std::size_t ceil_log2 (std::size_t x)
{
return static_cast<std::size_t>(!(is_pow2)(x)) + floor_log2(x);
}
inline std::size_t ceil_pow2 (std::size_t x)
{
return std::size_t(1u) << (ceil_log2)(x);
}
inline std::size_t previous_or_equal_pow2(std::size_t x)
{
return std::size_t(1u) << floor_log2(x);
}
template<class SizeType, std::size_t N>
struct numbits_eq
{
static const bool value = sizeof(SizeType)*CHAR_BIT == N;
};
template<class SizeType, class Enabler = void >
struct sqrt2_pow_max;
template <class SizeType>
struct sqrt2_pow_max<SizeType, typename voider<typename enable_if< numbits_eq<SizeType, 32> >::type>::type>
{
static const SizeType value = 0xb504f334;
static const std::size_t pow = 31;
};
#ifndef BOOST_NO_INT64_T
template <class SizeType>
struct sqrt2_pow_max<SizeType, typename voider<typename enable_if< numbits_eq<SizeType, 64> >::type>::type>
{
static const SizeType value = 0xb504f333f9de6484ull;
static const std::size_t pow = 63;
};
#endif //BOOST_NO_INT64_T
// Returns floor(pow(sqrt(2), x * 2 + 1)).
// Defined for X from 0 up to the number of bits in size_t minus 1.
inline std::size_t sqrt2_pow_2xplus1 (std::size_t x)
{
const std::size_t value = (std::size_t)sqrt2_pow_max<std::size_t>::value;
const std::size_t pow = (std::size_t)sqrt2_pow_max<std::size_t>::pow;
return (value >> (pow - x)) + 1;
}
} //namespace detail
} //namespace intrusive
} //namespace boost
#endif //BOOST_INTRUSIVE_DETAIL_MATH_HPP

View File

@@ -0,0 +1,30 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2014-2015
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_MINIMAL_LESS_EQUAL_HEADER_HPP
#define BOOST_INTRUSIVE_DETAIL_MINIMAL_LESS_EQUAL_HEADER_HPP
#
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#
#//Try to avoid including <functional>, as it's quite big in C++11
#if defined(BOOST_GNU_STDLIB)
# include <bits/stl_function.h>
#else
# include <functional> //Fallback
#endif
#
#endif //BOOST_INTRUSIVE_DETAIL_MINIMAL_LESS_EQUAL_HEADER_HPP

View File

@@ -0,0 +1,30 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2014-2015
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_MINIMAL_PAIR_HEADER_HPP
#define BOOST_INTRUSIVE_DETAIL_MINIMAL_PAIR_HEADER_HPP
#
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#
#//Try to avoid including <utility>, as it's quite big in C++11
#if defined(BOOST_GNU_STDLIB)
# include <bits/stl_pair.h>
#else
# include <utility> //Fallback
#endif
#
#endif //BOOST_INTRUSIVE_DETAIL_MINIMAL_PAIR_HEADER_HPP

View File

@@ -0,0 +1,217 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2014
// (C) Copyright Microsoft Corporation 2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_MPL_HPP
#define BOOST_INTRUSIVE_DETAIL_MPL_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/intrusive/detail/config_begin.hpp>
#include <boost/move/detail/type_traits.hpp>
#include <cstddef>
namespace boost {
namespace intrusive {
namespace detail {
using boost::move_detail::is_same;
using boost::move_detail::add_const;
using boost::move_detail::remove_const;
using boost::move_detail::remove_cv;
using boost::move_detail::remove_reference;
using boost::move_detail::add_reference;
using boost::move_detail::remove_pointer;
using boost::move_detail::add_pointer;
using boost::move_detail::true_type;
using boost::move_detail::false_type;
using boost::move_detail::voider;
using boost::move_detail::enable_if_c;
using boost::move_detail::enable_if;
using boost::move_detail::disable_if_c;
using boost::move_detail::disable_if;
using boost::move_detail::is_convertible;
using boost::move_detail::if_c;
using boost::move_detail::if_;
using boost::move_detail::is_const;
using boost::move_detail::identity;
using boost::move_detail::alignment_of;
using boost::move_detail::is_empty;
using boost::move_detail::addressof;
using boost::move_detail::integral_constant;
using boost::move_detail::enable_if_convertible;
using boost::move_detail::disable_if_convertible;
using boost::move_detail::bool_;
using boost::move_detail::true_;
using boost::move_detail::false_;
using boost::move_detail::yes_type;
using boost::move_detail::no_type;
using boost::move_detail::apply;
using boost::move_detail::eval_if_c;
using boost::move_detail::eval_if;
using boost::move_detail::unvoid_ref;
using boost::move_detail::add_const_if_c;
template<std::size_t S>
struct ls_zeros
{
static const std::size_t value = (S & std::size_t(1)) ? 0 : (1 + ls_zeros<(S>>1u)>::value);
};
template<>
struct ls_zeros<0>
{
static const std::size_t value = 0;
};
template<>
struct ls_zeros<1>
{
static const std::size_t value = 0;
};
// Infrastructure for providing a default type for T::TNAME if absent.
#define BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(TNAME) \
template <typename T> \
struct boost_intrusive_has_type_ ## TNAME \
{ \
template <typename X> \
static char test(int, typename X::TNAME*); \
\
template <typename X> \
static int test(...); \
\
static const bool value = (1 == sizeof(test<T>(0, 0))); \
}; \
\
template <typename T, typename DefaultType> \
struct boost_intrusive_default_type_ ## TNAME \
{ \
struct DefaultWrap { typedef DefaultType TNAME; }; \
\
typedef typename \
::boost::intrusive::detail::if_c \
< boost_intrusive_has_type_ ## TNAME<T>::value \
, T, DefaultWrap>::type::TNAME type; \
}; \
//
#define BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(INSTANTIATION_NS_PREFIX, T, TNAME, TIMPL) \
typename INSTANTIATION_NS_PREFIX \
boost_intrusive_default_type_ ## TNAME< T, TIMPL >::type \
//
#define BOOST_INTRUSIVE_HAS_TYPE(INSTANTIATION_NS_PREFIX, T, TNAME) \
INSTANTIATION_NS_PREFIX \
boost_intrusive_has_type_ ## TNAME< T >::value \
//
#define BOOST_INTRUSIVE_INSTANTIATE_EVAL_DEFAULT_TYPE_TMPLT(TNAME)\
template <typename T, typename DefaultType> \
struct boost_intrusive_eval_default_type_ ## TNAME \
{ \
template <typename X> \
static char test(int, typename X::TNAME*); \
\
template <typename X> \
static int test(...); \
\
struct DefaultWrap \
{ typedef typename DefaultType::type TNAME; }; \
\
static const bool value = (1 == sizeof(test<T>(0, 0))); \
\
typedef typename \
::boost::intrusive::detail::eval_if_c \
< value \
, ::boost::intrusive::detail::identity<T> \
, ::boost::intrusive::detail::identity<DefaultWrap> \
>::type::TNAME type; \
}; \
//
#define BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_EVAL_DEFAULT(INSTANTIATION_NS_PREFIX, T, TNAME, TIMPL) \
typename INSTANTIATION_NS_PREFIX \
boost_intrusive_eval_default_type_ ## TNAME< T, TIMPL >::type \
//
#define BOOST_INTRUSIVE_INTERNAL_STATIC_BOOL_IS_TRUE(TRAITS_PREFIX, TYPEDEF_TO_FIND) \
template <class T>\
struct TRAITS_PREFIX##_bool\
{\
template<bool Add>\
struct two_or_three {yes_type _[2u + (unsigned)Add];};\
template <class U> static yes_type test(...);\
template <class U> static two_or_three<U::TYPEDEF_TO_FIND> test (int);\
static const std::size_t value = sizeof(test<T>(0));\
};\
\
template <class T>\
struct TRAITS_PREFIX##_bool_is_true\
{\
static const bool value = TRAITS_PREFIX##_bool<T>::value > sizeof(yes_type)*2;\
};\
//
#define BOOST_INTRUSIVE_HAS_STATIC_MEMBER_FUNC_SIGNATURE(TRAITS_NAME, FUNC_NAME) \
template <typename U, typename Signature> \
class TRAITS_NAME \
{ \
private: \
template<Signature> struct helper;\
template<typename T> \
static ::boost::intrusive::detail::yes_type test(helper<&T::FUNC_NAME>*); \
template<typename T> static ::boost::intrusive::detail::no_type test(...); \
public: \
static const bool value = sizeof(test<U>(0)) == sizeof(::boost::intrusive::detail::yes_type); \
}; \
//
#define BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED(TRAITS_NAME, FUNC_NAME) \
template <typename Type> \
struct TRAITS_NAME \
{ \
struct BaseMixin \
{ \
void FUNC_NAME(); \
}; \
struct Base : public Type, public BaseMixin { Base(); }; \
template <typename T, T t> class Helper{}; \
template <typename U> \
static ::boost::intrusive::detail::no_type test(U*, Helper<void (BaseMixin::*)(), &U::FUNC_NAME>* = 0); \
static ::boost::intrusive::detail::yes_type test(...); \
static const bool value = sizeof(::boost::intrusive::detail::yes_type) == sizeof(test((Base*)(0))); \
};\
//
#define BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED_IGNORE_SIGNATURE(TRAITS_NAME, FUNC_NAME) \
BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED(TRAITS_NAME##_ignore_signature, FUNC_NAME) \
\
template <typename Type, class> \
struct TRAITS_NAME \
: public TRAITS_NAME##_ignore_signature<Type> \
{};\
//
} //namespace detail
} //namespace intrusive
} //namespace boost
#include <boost/intrusive/detail/config_end.hpp>
#endif //BOOST_INTRUSIVE_DETAIL_MPL_HPP

View File

@@ -0,0 +1,105 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2014-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_NODE_CLONER_DISPOSER_HPP
#define BOOST_INTRUSIVE_DETAIL_NODE_CLONER_DISPOSER_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/intrusive/link_mode.hpp>
#include <boost/intrusive/detail/mpl.hpp>
#include <boost/intrusive/detail/ebo_functor_holder.hpp>
#include <boost/intrusive/detail/algo_type.hpp>
#include <boost/intrusive/detail/assert.hpp>
namespace boost {
namespace intrusive {
namespace detail {
template<class F, class ValueTraits, algo_types AlgoType, bool IsConst = true>
struct node_cloner
//Use public inheritance to avoid MSVC bugs with closures
: public ebo_functor_holder<F>
{
typedef ValueTraits value_traits;
typedef typename value_traits::node_traits node_traits;
typedef typename node_traits::node_ptr node_ptr;
typedef ebo_functor_holder<F> base_t;
typedef typename get_algo< AlgoType
, node_traits>::type node_algorithms;
static const bool safemode_or_autounlink =
is_safe_autounlink<value_traits::link_mode>::value;
typedef typename value_traits::value_type value_type;
typedef typename value_traits::pointer pointer;
typedef typename value_traits::const_pointer const_pointer;
typedef typename node_traits::node node;
typedef typename value_traits::const_node_ptr const_node_ptr;
typedef typename pointer_traits<pointer>::reference reference;
typedef typename pointer_traits
<const_pointer>::reference const_reference;
typedef typename if_c<IsConst, const_reference, reference>::type reference_type;
node_cloner(F f, const ValueTraits *traits)
: base_t(f), traits_(traits)
{}
// tree-based containers use this method, which is proxy-reference friendly
BOOST_INTRUSIVE_FORCEINLINE node_ptr operator()(node_ptr p)
{
reference_type v = *traits_->to_value_ptr(p);
node_ptr n = traits_->to_node_ptr(*base_t::get()(v));
//Cloned node must be in default mode if the linking mode requires it
BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::unique(n));
return n;
}
const ValueTraits * const traits_;
};
template<class F, class ValueTraits, algo_types AlgoType>
struct node_disposer
//Use public inheritance to avoid MSVC bugs with closures
: public ebo_functor_holder<F>
{
typedef ValueTraits value_traits;
typedef typename value_traits::node_traits node_traits;
typedef typename node_traits::node_ptr node_ptr;
typedef ebo_functor_holder<F> base_t;
typedef typename get_algo< AlgoType
, node_traits>::type node_algorithms;
static const bool safemode_or_autounlink =
is_safe_autounlink<value_traits::link_mode>::value;
node_disposer(F f, const ValueTraits *cont)
: base_t(f), traits_(cont)
{}
BOOST_INTRUSIVE_FORCEINLINE void operator()(node_ptr p)
{
BOOST_IF_CONSTEXPR(safemode_or_autounlink)
node_algorithms::init(p);
base_t::get()(traits_->to_value_ptr(p));
}
const ValueTraits * const traits_;
};
} //namespace detail{
} //namespace intrusive{
} //namespace boost{
#endif //BOOST_INTRUSIVE_DETAIL_NODE_CLONER_DISPOSER_HPP

View File

@@ -0,0 +1,35 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2014-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_NODE_HOLDER_HPP
#define BOOST_INTRUSIVE_DETAIL_NODE_HOLDER_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
namespace boost {
namespace intrusive {
template<class Node, class Tag, unsigned int>
struct node_holder
: public Node
{};
} //namespace intrusive{
} //namespace boost{
#endif //BOOST_INTRUSIVE_DETAIL_NODE_HOLDER_HPP

View File

@@ -0,0 +1,130 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2014-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_NODE_TO_VALUE_HPP
#define BOOST_INTRUSIVE_DETAIL_NODE_TO_VALUE_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/intrusive/pointer_traits.hpp>
#include <boost/intrusive/detail/mpl.hpp>
#include <boost/intrusive/detail/is_stateful_value_traits.hpp>
namespace boost {
namespace intrusive {
namespace detail {
template<class VoidPointer>
struct dummy_constptr
{
typedef typename boost::intrusive::pointer_traits<VoidPointer>::
template rebind_pointer<const void>::type ConstVoidPtr;
explicit dummy_constptr(ConstVoidPtr)
{}
dummy_constptr()
{}
ConstVoidPtr get_ptr() const
{ return ConstVoidPtr(); }
};
template<class VoidPointer>
struct constptr
{
typedef typename boost::intrusive::pointer_traits<VoidPointer>::
template rebind_pointer<const void>::type ConstVoidPtr;
constptr()
{}
explicit constptr(const ConstVoidPtr &ptr)
: const_void_ptr_(ptr)
{}
const void *get_ptr() const
{ return boost::movelib::to_raw_pointer(const_void_ptr_); }
ConstVoidPtr const_void_ptr_;
};
template <class VoidPointer, bool store_ptr>
struct select_constptr
{
typedef typename if_c
< store_ptr
, constptr<VoidPointer>
, dummy_constptr<VoidPointer>
>::type type;
};
template<class ValueTraits, bool IsConst>
struct node_to_value
: public select_constptr
< typename pointer_traits
<typename ValueTraits::pointer>::template rebind_pointer<void>::type
, is_stateful_value_traits<ValueTraits>::value
>::type
{
static const bool stateful_value_traits = is_stateful_value_traits<ValueTraits>::value;
typedef typename select_constptr
< typename pointer_traits
<typename ValueTraits::pointer>::
template rebind_pointer<void>::type
, stateful_value_traits >::type Base;
typedef ValueTraits value_traits;
typedef typename value_traits::value_type value_type;
typedef typename value_traits::node_traits::node node;
typedef typename add_const_if_c
<value_type, IsConst>::type vtype;
typedef typename add_const_if_c
<node, IsConst>::type ntype;
typedef typename pointer_traits
<typename ValueTraits::pointer>::
template rebind_pointer<ntype>::type npointer;
typedef typename pointer_traits<npointer>::
template rebind_pointer<const ValueTraits>::type const_value_traits_ptr;
node_to_value(const_value_traits_ptr ptr)
: Base(ptr)
{}
typedef vtype & result_type;
typedef ntype & first_argument_type;
const_value_traits_ptr get_value_traits() const
{ return pointer_traits<const_value_traits_ptr>::static_cast_from(Base::get_ptr()); }
result_type to_value(first_argument_type arg, false_) const
{ return *(value_traits::to_value_ptr(pointer_traits<npointer>::pointer_to(arg))); }
result_type to_value(first_argument_type arg, true_) const
{ return *(this->get_value_traits()->to_value_ptr(pointer_traits<npointer>::pointer_to(arg))); }
result_type operator()(first_argument_type arg) const
{ return this->to_value(arg, bool_<stateful_value_traits>()); }
};
} //namespace detail{
} //namespace intrusive{
} //namespace boost{
#endif //BOOST_INTRUSIVE_DETAIL_NODE_TO_VALUE_HPP

View File

@@ -0,0 +1,121 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2007-2013
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_PARENT_FROM_MEMBER_HPP
#define BOOST_INTRUSIVE_DETAIL_PARENT_FROM_MEMBER_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/intrusive/detail/config_begin.hpp>
#include <boost/intrusive/detail/workaround.hpp>
#include <cstddef>
#if defined(_MSC_VER)
#define BOOST_INTRUSIVE_MSVC_ABI_PTR_TO_MEMBER
#include <boost/static_assert.hpp>
#endif
namespace boost {
namespace intrusive {
namespace detail {
template<class Parent, class Member>
BOOST_INTRUSIVE_FORCEINLINE std::ptrdiff_t offset_from_pointer_to_member(const Member Parent::* ptr_to_member)
{
//The implementation of a pointer to member is compiler dependent.
#if defined(BOOST_INTRUSIVE_MSVC_ABI_PTR_TO_MEMBER)
//MSVC compliant compilers use their the first 32 bits as offset (even in 64 bit mode)
union caster_union
{
const Member Parent::* ptr_to_member;
int offset;
} caster;
//MSVC ABI can use up to 3 int32 to represent pointer to member data
//with virtual base classes, in those cases there is no simple to
//obtain the address of the parent. So static assert to avoid runtime errors
BOOST_STATIC_ASSERT( sizeof(caster) == sizeof(int) );
caster.ptr_to_member = ptr_to_member;
return std::ptrdiff_t(caster.offset);
//Additional info on MSVC behaviour for the future. For 2/3 int ptr-to-member
//types dereference seems to be:
//
// vboffset = [compile_time_offset if 2-int ptr2memb] /
// [ptr2memb.i32[2] if 3-int ptr2memb].
// vbtable = *(this + vboffset);
// adj = vbtable[ptr2memb.i32[1]];
// var = adj + (this + vboffset) + ptr2memb.i32[0];
//
//To reverse the operation we need to
// - obtain vboffset (in 2-int ptr2memb implementation only)
// - Go to Parent's vbtable and obtain adjustment at index ptr2memb.i32[1]
// - parent = member - adj - vboffset - ptr2memb.i32[0]
//
//Even accessing to RTTI we might not be able to obtain this information
//so anyone who thinks it's possible, please send a patch.
//This works with gcc, msvc, ac++, ibmcpp
#elif defined(__GNUC__) || defined(__HP_aCC) || defined(BOOST_INTEL) || \
defined(__IBMCPP__) || defined(__DECCXX)
const Parent * const parent = 0;
const char *const member = static_cast<const char*>(static_cast<const void*>(&(parent->*ptr_to_member)));
return std::ptrdiff_t(member - static_cast<const char*>(static_cast<const void*>(parent)));
#else
//This is the traditional C-front approach: __MWERKS__, __DMC__, __SUNPRO_CC
union caster_union
{
const Member Parent::* ptr_to_member;
std::ptrdiff_t offset;
} caster;
caster.ptr_to_member = ptr_to_member;
return caster.offset - 1;
#endif
}
template<class Parent, class Member>
BOOST_INTRUSIVE_FORCEINLINE Parent *parent_from_member(Member *member, const Member Parent::* ptr_to_member)
{
return static_cast<Parent*>
(
static_cast<void*>
(
static_cast<char*>(static_cast<void*>(member)) - offset_from_pointer_to_member(ptr_to_member)
)
);
}
template<class Parent, class Member>
BOOST_INTRUSIVE_FORCEINLINE const Parent *parent_from_member(const Member *member, const Member Parent::* ptr_to_member)
{
return static_cast<const Parent*>
(
static_cast<const void*>
(
static_cast<const char*>(static_cast<const void*>(member)) - offset_from_pointer_to_member(ptr_to_member)
)
);
}
} //namespace detail {
} //namespace intrusive {
} //namespace boost {
#include <boost/intrusive/detail/config_end.hpp>
#endif //#ifndef BOOST_INTRUSIVE_DETAIL_PARENT_FROM_MEMBER_HPP

View File

@@ -0,0 +1,205 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Olaf Krzikalla 2004-2006.
// (C) Copyright Ion Gaztanaga 2006-2013.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_RBTREE_NODE_HPP
#define BOOST_INTRUSIVE_RBTREE_NODE_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/intrusive/detail/config_begin.hpp>
#include <boost/intrusive/detail/workaround.hpp>
#include <boost/intrusive/pointer_rebind.hpp>
#include <boost/intrusive/rbtree_algorithms.hpp>
#include <boost/intrusive/pointer_plus_bits.hpp>
#include <boost/intrusive/detail/mpl.hpp>
#include <boost/intrusive/detail/tree_node.hpp>
namespace boost {
namespace intrusive {
/////////////////////////////////////////////////////////////////////////////
// //
// Generic node_traits for any pointer type //
// //
/////////////////////////////////////////////////////////////////////////////
//This is the compact representation: 3 pointers
template<class VoidPointer>
struct compact_rbtree_node
{
typedef compact_rbtree_node<VoidPointer> node;
typedef typename pointer_rebind<VoidPointer, node >::type node_ptr;
typedef typename pointer_rebind<VoidPointer, const node >::type const_node_ptr;
enum color { red_t, black_t };
node_ptr parent_, left_, right_;
};
//This is the normal representation: 3 pointers + enum
template<class VoidPointer>
struct rbtree_node
{
typedef rbtree_node<VoidPointer> node;
typedef typename pointer_rebind<VoidPointer, node >::type node_ptr;
typedef typename pointer_rebind<VoidPointer, const node >::type const_node_ptr;
enum color { red_t, black_t };
node_ptr parent_, left_, right_;
color color_;
};
//This is the default node traits implementation
//using a node with 3 generic pointers plus an enum
template<class VoidPointer>
struct default_rbtree_node_traits_impl
{
typedef rbtree_node<VoidPointer> node;
typedef typename node::node_ptr node_ptr;
typedef typename node::const_node_ptr const_node_ptr;
typedef typename node::color color;
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_parent(const_node_ptr n)
{ return n->parent_; }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_parent(node_ptr n)
{ return n->parent_; }
BOOST_INTRUSIVE_FORCEINLINE static void set_parent(node_ptr n, node_ptr p)
{ n->parent_ = p; }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_left(const_node_ptr n)
{ return n->left_; }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_left(node_ptr n)
{ return n->left_; }
BOOST_INTRUSIVE_FORCEINLINE static void set_left(node_ptr n, node_ptr l)
{ n->left_ = l; }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_right(const_node_ptr n)
{ return n->right_; }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_right(node_ptr n)
{ return n->right_; }
BOOST_INTRUSIVE_FORCEINLINE static void set_right(node_ptr n, node_ptr r)
{ n->right_ = r; }
BOOST_INTRUSIVE_FORCEINLINE static color get_color(const_node_ptr n)
{ return n->color_; }
BOOST_INTRUSIVE_FORCEINLINE static color get_color(node_ptr n)
{ return n->color_; }
BOOST_INTRUSIVE_FORCEINLINE static void set_color(node_ptr n, color c)
{ n->color_ = c; }
BOOST_INTRUSIVE_FORCEINLINE static color black()
{ return node::black_t; }
BOOST_INTRUSIVE_FORCEINLINE static color red()
{ return node::red_t; }
};
//This is the compact node traits implementation
//using a node with 3 generic pointers
template<class VoidPointer>
struct compact_rbtree_node_traits_impl
{
typedef compact_rbtree_node<VoidPointer> node;
typedef typename node::node_ptr node_ptr;
typedef typename node::const_node_ptr const_node_ptr;
typedef pointer_plus_bits<node_ptr, 1> ptr_bit;
typedef typename node::color color;
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_parent(const_node_ptr n)
{ return ptr_bit::get_pointer(n->parent_); }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_parent(node_ptr n)
{ return ptr_bit::get_pointer(n->parent_); }
BOOST_INTRUSIVE_FORCEINLINE static void set_parent(node_ptr n, node_ptr p)
{ ptr_bit::set_pointer(n->parent_, p); }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_left(const_node_ptr n)
{ return n->left_; }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_left(node_ptr n)
{ return n->left_; }
BOOST_INTRUSIVE_FORCEINLINE static void set_left(node_ptr n, node_ptr l)
{ n->left_ = l; }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_right(const_node_ptr n)
{ return n->right_; }
BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_right(node_ptr n)
{ return n->right_; }
BOOST_INTRUSIVE_FORCEINLINE static void set_right(node_ptr n, node_ptr r)
{ n->right_ = r; }
BOOST_INTRUSIVE_FORCEINLINE static color get_color(const_node_ptr n)
{ return (color)ptr_bit::get_bits(n->parent_); }
BOOST_INTRUSIVE_FORCEINLINE static color get_color(node_ptr n)
{ return (color)ptr_bit::get_bits(n->parent_); }
BOOST_INTRUSIVE_FORCEINLINE static void set_color(node_ptr n, color c)
{ ptr_bit::set_bits(n->parent_, c != 0); }
BOOST_INTRUSIVE_FORCEINLINE static color black()
{ return node::black_t; }
BOOST_INTRUSIVE_FORCEINLINE static color red()
{ return node::red_t; }
};
//Dispatches the implementation based on the boolean
template<class VoidPointer, bool Compact>
struct rbtree_node_traits_dispatch
: public default_rbtree_node_traits_impl<VoidPointer>
{};
template<class VoidPointer>
struct rbtree_node_traits_dispatch<VoidPointer, true>
: public compact_rbtree_node_traits_impl<VoidPointer>
{};
//Inherit from rbtree_node_traits_dispatch depending on the embedding capabilities
template<class VoidPointer, bool OptimizeSize = false>
struct rbtree_node_traits
: public rbtree_node_traits_dispatch
< VoidPointer
, OptimizeSize &&
(max_pointer_plus_bits
< VoidPointer
, detail::alignment_of<compact_rbtree_node<VoidPointer> >::value
>::value >= 1)
>
{};
} //namespace intrusive
} //namespace boost
#include <boost/intrusive/detail/config_end.hpp>
#endif //BOOST_INTRUSIVE_RBTREE_NODE_HPP

View File

@@ -0,0 +1,28 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2014-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_REVERSE_ITERATOR_HPP
#define BOOST_INTRUSIVE_DETAIL_REVERSE_ITERATOR_HPP
#include <boost/move/detail/reverse_iterator.hpp>
namespace boost {
namespace intrusive {
using boost::movelib::reverse_iterator;
using boost::movelib::make_reverse_iterator;
} //namespace intrusive {
} //namespace boost {
#endif //BOOST_INTRUSIVE_DETAIL_REVERSE_ITERATOR_HPP

Some files were not shown because too many files have changed in this diff Show More