Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O OpenFOAM-plus
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 339
    • Issues 339
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • Deployments
    • Deployments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • Repository
  • Wiki
    • Wiki
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • Development
  • OpenFOAM-plus
  • Issues
  • #595
Closed
Open
Issue created Sep 20, 2017 by Mark OLESEN@markMaintainer

simplify/extend List, DynamicList

Inspired by some of Franjo's @Juretic work, I've started looking into how to incorporate the short list optimization into the standard DynamicList as well as other methods and possible optimizations. I'd like some feedback on some of these ideas @andy @Mattijs

The static allocation size needs to be templated but the number of parameters for DynamicList is growing too much. My current thought is to remove the SizeInc,SizeMult,SizeDiv from templates and replace with a run-time sizing policy that we can combine with templated factory methods for some compile-time safety.

Eg,

template<class T, unsigned StaticSize = 16>
class DynamicList
{
...
    //-
    inline void setSizingPolicy(const sizingPolicy& policy);

};

In use this would mean something like this:

DynamicList<label>  lst;

lst.setSizingPolicy(sizingPolicy::increment<10>());
lst.setSizingPolicy(sizingPolicy::factor<2>());
lst.setSizingPolicy(sizingPolicy::factor<3,2>());
lst.setSizingPolicy(sizingPolicy::general<10,3,2>());

This is still a long way from handling allocations with an allocator, but I think it is an improvement.

To accommodate some other routines, I've tentatively added in these methods:

UList
    //- Find index of the first occurence of the value.
    //  Linear search.
    //  \return -1 if not found.
    label find(const T& val, const label start=0) const;

    //- True if the value if found in the list. Linear search.
    inline bool found(const T& val, const label start=0) const;

    //- Move element to the first position.
    void moveFirst(const label i);

    //- Move element to the last position.
    void moveLast(const label i);

    //- Swap with the first element. Fatal on an empty list.
    void swapFirst(const label i);

    //- Swap with the last element. Fatal on an empty list.
    void swapLast(const label i);

DynamicList
    //- Remove and return the last element. Fatal on an empty list.
    inline T remove();

    //- Remove and return the specified element. Fatal on an empty list.
    //  With fast=true (default), the removed element is replaced with
    //  the last one in the list.
    //  With fast=false, the elements are copied down in the list.
    inline T remove(const label i, const bool fast=true);
Edited Sep 20, 2017 by Mark OLESEN
Assignee
Assign to
Time tracking