Skip to content

cenxuantian/t_standard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

t_standard

Data structures and algorithms based on C++ 20 standard

!!! Code that is contained in the README.md may not be the latest version

Features

  • Head-only
  • All classes are designed non-copyable
  • Contains lock-free atomic classes for multi-threading programming (unfinished)

Menu

Meta functions & structs & constexprs

Algorithms

Classes

NonMoveable

Definition (NonMoveable)

interface for non-moveable classes

class NonMoveable;

NonCopyable

interface for non-copyable classes

Definition (NonCopyable)

class NonCopyable;

AtomicRingQueue

Thread Safe ring buffer, which can only be modified in the head and tail. If the buffer is full, the data in the head will be overwritten.

Definition (AtomicRingQueue)

template<typename _Type,size_t _Size>
class AtomicRingQueue: public NonCopyble;

Public functions (AtomicRingQueue)

void push(_Type const& _in_ldata);

size_t safe_pop_pos() noexcept;
_Type safe_pop(size_t pos) noexcept;

// this function can only get the current size
// If other thread has called "push" or "safe_pop_pos" function
// The size could be different
size_t size()const noexcept;

size_t capacity()const noexcept;

void clear() noexcept;

// This function will not really clear the data.
// It will just change the marks of the head and tail position
// So this function is fast
void clear() noexcept;

Examples (AtomicRingQueue)

// create the object
AtomicRingQueue<int,100> q;
// Push something into the queue
q.push(1);

// try to pop
auto pos = q.safe_pop_pos();
// Check if the pos is right
if(pos!=0ULL){
    // Read the data out
    int front = q.safe_pop(pos);
}else{
    // The queue is empty currently
}

License

MIT License

Copyright (c) 2024 Cenxuan

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Contact

If you have any questions or suggestions, feel free to contact me at my email:
[email protected]

About

Data structures and algorithms

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published