source: src/IdPool.hpp@ b49568

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since b49568 was 3e4fb6, checked in by Frederik Heber <heber@…>, 13 years ago

Added template class IdPool used by World to manage defragmentable id pool.

  • this is stuff from World factored into own class (was doubly present in World anyway).
  • added short documentation to constructs/world.
  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 * IdPool.hpp
3 *
4 * This is completely based on the work of Till Crueger, factored out from
5 * World.cpp/hpp.
6 *
7 * Created on: Dec 23, 2011
8 * Author: heber
9 */
10
11#ifndef IDPOOL_HPP_
12#define IDPOOL_HPP_
13
14// include config.h
15#ifdef HAVE_CONFIG_H
16#include <config.h>
17#endif
18
19#include <set>
20
21#include "CodePatterns/Range.hpp"
22
23/** This class represents a pool of id that can be defragmented.
24 *
25 * This is templated to have whatever pool size (depending on the variable
26 * that stores the id).
27 *
28 */
29template <class T>
30class IdPool {
31public:
32 /** Constructor for class IdPool.
33 *
34 * @param _currId initial id
35 * @param _max_skips max skips before we really defragment
36 * @param _max_size max size of distinct id ranges before we really defragment
37 */
38 IdPool(const T _currId, const unsigned int _max_skips, const unsigned int _max_size);
39
40 /** Destructor for class IdPool.
41 *
42 */
43 ~IdPool();
44
45 /** Returns the next available id.
46 *
47 * @return free id that is reserved
48 */
49 T getNextId();
50
51 /** Reserves a specific \a id.
52 *
53 * @param id which id to reserve
54 * @return true - \a id is reserved, false - \a id is already taken
55 */
56 bool reserveId(T id);
57
58 /** Release a reserved \a id.
59 *
60 * @param id id to release
61 */
62 void releaseId(T id);
63
64private:
65 enum Actions {
66 release,
67 reserve,
68 NoAction
69 };
70
71 /** Sets the last action.
72 *
73 * This also increases IdPool::numAtomDefragSkips when we switch from one
74 * Action to another.
75 *
76 * @param _action new last action to set
77 */
78 void setLastAction(const enum Actions _action)
79 {
80 if (_action != lastAction)
81 ++numDefragSkips;
82 lastAction = _action;
83 }
84
85 //!> contains the last action such that skip counter is only increased when we switch
86 enum Actions lastAction;
87
88private:
89 /** Defragment the id pool.
90 *
91 * It is up to this function whether we really defrag or not.
92 *
93 */
94 void defragIdPool();
95
96private:
97 //!> internal typedef for the pool
98 typedef std::set<range<T> > IdPool_t;
99
100 //!> the id pool
101 IdPool_t pool;
102
103 //!> stores the next highest Id for atoms. This is the last resort of there is no pool.
104 T currId;
105
106 //!> size of the pool after last defrag, to skip some defrags
107 size_t lastPoolSize;
108
109 //!> current number of skips
110 unsigned int numDefragSkips;
111
112 //!> threshold after how many skips we reall defrag
113 const unsigned int MAX_FRAGMENTATION_SKIPS;
114
115 //!> threshold of how large the number of distinct ranges is before we defrag
116 const unsigned int MAX_POOL_FRAGMENTATION;
117
118};
119
120#endif /* IDPOOL_HPP_ */
Note: See TracBrowser for help on using the repository browser.