- Timestamp:
- Feb 17, 2012, 3:24:18 PM (13 years ago)
- Branches:
- 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
- Children:
- 7d46e3
- Parents:
- 3867a7
- git-author:
- Frederik Heber <heber@…> (01/06/12 14:37:36)
- git-committer:
- Frederik Heber <heber@…> (02/17/12 15:24:18)
- Location:
- src
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/IdPool.hpp
r3867a7 rb97a60 26 26 * that stores the id). 27 27 * 28 * Note that the external class \a idpolicy decides upon how the next id is 29 * produced, \sa IdPool_policy.hpp. 28 30 */ 29 template <class T> 30 class IdPool { 31 template <class T, class idpolicy> 32 class IdPool : public idpolicy { 33 // when trait is not of correct type this will produce an error 34 typedef typename idpolicy::is_IdPool_policy check_for_IdPool_trait; 31 35 public: 32 36 /** Constructor for class IdPool. … … 43 47 ~IdPool(); 44 48 45 /** Returns the next available id.46 *47 * @return free id that is reserved48 */49 T getNextId();50 51 49 /** Reserves a specific \a id. 52 50 * … … 61 59 */ 62 60 void releaseId(T id); 61 62 /** Returns the next available id. 63 * 64 * @return free id that is reserved 65 */ 66 T getNextId(); 63 67 64 68 private: -
src/IdPool_impl.hpp
r3867a7 rb97a60 18 18 #include "CodePatterns/Log.hpp" 19 19 20 template <class T >21 IdPool<T >::IdPool(const T _currId, const unsigned int _max_skips, const unsigned int _max_size) :20 template <class T, class idpolicy> 21 IdPool<T,idpolicy>::IdPool(const T _currId, const unsigned int _max_skips, const unsigned int _max_size) : 22 22 lastAction(NoAction), 23 23 currId(_currId), … … 28 28 {} 29 29 30 template <class T >31 IdPool<T >::~IdPool()30 template <class T, class idpolicy> 31 IdPool<T,idpolicy>::~IdPool() 32 32 {} 33 33 34 template <class T >35 T IdPool<T >::getNextId()34 template <class T, class idpolicy> 35 T IdPool<T,idpolicy>::getNextId() 36 36 { 37 37 setLastAction(reserve); 38 // try to find an Id in the pool; 39 if(!pool.empty()) { 40 typename IdPool_t::iterator iter=pool.begin(); 41 T id = iter->first; 42 range<T> newRange = makeRange(id+1,iter->last); 43 // we wont use this iterator anymore, so we don't care about invalidating 44 pool.erase(iter); 45 if(newRange.first<newRange.last) 46 pool.insert(newRange); 47 return id; 48 } 49 // Nothing in the pool... we are out of luck 50 return currId++; 38 return idpolicy::getNextId_impl(pool, currId); 51 39 } 52 40 53 template <class T >54 void IdPool<T >::releaseId(T id)41 template <class T, class idpolicy> 42 void IdPool<T,idpolicy>::releaseId(T id) 55 43 { 56 44 setLastAction(release); … … 59 47 } 60 48 61 template <class T >62 bool IdPool<T >::reserveId(T id)49 template <class T, class idpolicy> 50 bool IdPool<T,idpolicy>::reserveId(T id) 63 51 { 64 52 setLastAction(reserve); … … 100 88 } 101 89 102 template <class T >103 void IdPool<T >::defragIdPool()90 template <class T, class idpolicy> 91 void IdPool<T,idpolicy>::defragIdPool() 104 92 { 105 93 // check if the situation is bad enough to make defragging neccessary … … 142 130 * at a chosen place. 143 131 */ 144 #define CONSTRUCT_IDPOOL(name ) \145 template name IdPool< name >::getNextId(); \146 template bool IdPool< name >::reserveId( name ); \147 template void IdPool< name >::releaseId( name ); \148 template void IdPool< name >::setLastAction(const enum Actions _action); \149 template void IdPool< name >::defragIdPool() ;132 #define CONSTRUCT_IDPOOL(name, idpolicy) \ 133 template name IdPool< name, idpolicy >::getNextId(); \ 134 template bool IdPool< name, idpolicy >::reserveId( name ); \ 135 template void IdPool< name, idpolicy >::releaseId( name ); \ 136 template void IdPool< name, idpolicy >::setLastAction(const enum Actions _action); \ 137 template void IdPool< name, idpolicy >::defragIdPool() ; 150 138 151 139 #endif /* IDPOOL_IMPL_HPP_ */ -
src/World.cpp
r3867a7 rb97a60 693 693 694 694 // moleculeId_t und atomId_t sind gleicher Basistyp, deswegen nur einen von beiden konstruieren 695 CONSTRUCT_IDPOOL(moleculeId_t) 695 CONSTRUCT_IDPOOL(atomId_t, uniqueId) 696 CONSTRUCT_IDPOOL(moleculeId_t, continuousId) 696 697 697 698 CONSTRUCT_SINGLETON(World) -
src/World.hpp
r3867a7 rb97a60 32 32 #include "CodePatterns/Observer/ObservedContainer.hpp" 33 33 #include "CodePatterns/Range.hpp" 34 #include "IdPool_policy.hpp" 34 35 #include "IdPool.hpp" 35 36 #include "LinkedCell/LinkedCell_View.hpp" … … 465 466 * The pool contains ranges of free ids in the form [bottom,top). 466 467 */ 467 IdPool<atomId_t > atomIdPool;468 IdPool<atomId_t, uniqueId> atomIdPool; 468 469 469 470 MoleculeSet molecules; … … 474 475 * The pool contains ranges of free ids in the form [bottom,top). 475 476 */ 476 IdPool<moleculeId_t > moleculeIdPool;477 IdPool<moleculeId_t, continuousId> moleculeIdPool; 477 478 478 479 private: -
src/documentation/constructs/world.dox
r3867a7 rb97a60 112 112 * \paragraph world-internals-notes-idpool 113 113 * 114 * The World has an idpool to manage the ids of atoms and molecules, i.e. such 115 * that they are: 116 * -# unique 117 * -# not loosely spread over the whole range of possible, but tightly packed 114 * The World has an idpool to manage the ids of atoms and molecules. The IdPool 115 * inherits policies, such that ids are given in a unique (uniqueId) or 116 * continuous (continousId) fashion. 117 * The id of an atom is the sole identifier for which we can guarantee 118 * uniqueness. Due to undo and redo actions the memory address is not a good 119 * identifier. This is however required for FormatParser's that need 120 * to store their additionalAtomData at program exit and have to safely identify 121 * the data with its atoms. This can only be accomplished via the id. Hence, 122 * we use the unique policy there. 123 * The id of a molecule however is more of a convenience, to distinguish it from 124 * the currently present others. A molecule may change very often and it is also 125 * a compound structure that may change slightly (when a new bond to another atom 126 * occurs). Thus, the concept of the id as a unique identifier does not make 127 * sense. Hence, we use the continuous policy here. 118 128 * 119 * For the latter to work we have a class IdPool that manages the ids and 129 * Note that IdPool::reserveId() has to ascertain that we may sweep through ids 130 * available to (undone) AtomRemoveAction or (redone) AtomAddAction in sublinear 131 * time. For this to work we have a class IdPool that manages the ids and 120 132 * defragments the pool from time to time by combining ranges of released ids. 121 133 * 122 * \date 201 1-10-31134 * \date 2012-01-06 123 135 * 124 136 */
Note:
See TracChangeset
for help on using the changeset viewer.