Skip to content

Commit

Permalink
Som devel (#33)
Browse files Browse the repository at this point in the history
* list -> TransEvent

* devel comments / TODO

* StackArray refactor; StackArray tests

* more protection, comments

* details

* spelling

* typos

* typos
  • Loading branch information
sorgom authored Jan 25, 2024
1 parent b77a5dc commit c67997b
Show file tree
Hide file tree
Showing 25 changed files with 312 additions and 251 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ html
_*.*

# depracated gen
transitions_*.mod
transitions_*.md
*_states.md
10 changes: 5 additions & 5 deletions CLOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
C++ 16 100 5 909
C/C++ Header 23 243 190 801
C++ 16 100 5 914
C/C++ Header 23 248 197 806
-------------------------------------------------------------------------------
SUM: 39 343 195 1710
SUM: 39 348 202 1720
-------------------------------------------------------------------------------
```
**testenv**
Expand All @@ -26,9 +26,9 @@ SUM: 34 267 193 1242
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
C++ 15 208 213 1813
C++ 15 214 217 1841
-------------------------------------------------------------------------------
SUM: 15 208 213 1813
SUM: 15 214 217 1841
-------------------------------------------------------------------------------
```
**systemtests**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
// ============================================================
// defintion of interface I_Searchable to apply:
// defintion of interface I_Array to apply:
// - bubble sort
// - b-tree search
// - uniqueness check / duplicates count
// ============================================================
#pragma once
#ifndef I_SEARCHABLE_H
#define I_SEARCHABLE_H
#ifndef I_ARRAY_H
#define I_ARRAY_H

#include <BAS/BaseTypes.h>
#include <BAS/coding.h>

template <class T>
class I_Searchable
class I_Array
{
public:
// current number of objects
virtual UINT32 size() const = 0;

// object access by position
virtual const T& at(UINT32 pos) const = 0;

// definition object a is greater than object b
virtual bool isGreater(const T& a, const T& b) const = 0;
inline virtual bool isGreater(const T& a, const T& b) const
{
return false;
}

// swap content of position a and b
virtual void swap(UINT32 posA, UINT32 posB) = 0;
inline virtual void swap(UINT32 posA, UINT32 posB)
{}
};

template <class T>
void bSort(I_Searchable<T>& src)
void bSort(I_Array<T>& src)
{
for (UINT32 n = src.size(); n > 1; --n)
{
Expand All @@ -47,7 +54,7 @@ void bSort(I_Searchable<T>& src)
}

template <class T>
INT32 bSearch(const I_Searchable<T>& src, const T& obj)
INT32 bSearch(const I_Array<T>& src, const T& obj)
{
INT32 pMin = 0;
INT32 pMax = src.size() - 1;
Expand All @@ -74,15 +81,15 @@ INT32 bSearch(const I_Searchable<T>& src, const T& obj)
return res;
}

// apply duplicates count to I_Searchable
// apply duplicates count to I_Array
// precondition: bSort applied before
template <class T>
UINT32 dupCnt(const I_Searchable<T>& src)
UINT32 dupCnt(const I_Array<T>& src)
{
UINT32 ndups = 0;
for (UINT32 p = 0; p < src.size() - 1; ++p)
for (UINT32 p = 1; p < src.size(); ++p)
{
if (not src.isGreater(src.at(p + 1), src.at(p)))
if (not src.isGreater(src.at(p), src.at(p - 1)))
{
++ndups;
}
Expand Down
36 changes: 28 additions & 8 deletions application/components/BAS/NtpArray.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
// ============================================================
// Storage of Name Type Position
// name, type, position
// ============================================================
// created by Manfred Sorgo

#pragma once
#ifndef NTPARRAY_H
#define NTPARRAY_H

#include <ifs/DataTypes.h>
#include <BAS/StackArray.h>
#include <BAS/coding.h>
#include <BAS/Mem.h>
#include <BAS/StackArray.h>
#include <ifs/DataTypes.h>

// name, type, position
struct Ntp
{
ElementName name;
INT32 type;
UINT32 pos;
};

// generates Ntp struct from name [, type, position]
class GenNtp
{
protected:
Expand All @@ -26,20 +29,34 @@ class GenNtp
INT32 type = 0,
UINT32 pos = 0
);

inline GenNtp() {}

NOCOPY(GenNtp)
};

// ============================================================
// - storage of name, type, position
// ============================================================
template <UINT32 CAP>
class NtpArray :
public SimpleStackArray<Ntp, CAP>,
public StackArray<Ntp, CAP>,
private GenNtp
{
public:
inline NtpArray() {}

inline UINT32 addNtp(const ElementName& name, INT32 type, UINT32 pos)
{
return this->add(genNtp(name, type, pos));
}

NOCOPY(NtpArray)
};

// ============================================================
// - index of name, type, position by name
// ============================================================
template <UINT32 CAP>
class NtpIndex :
public StackArrayIndex<Ntp, CAP>,
Expand All @@ -50,15 +67,18 @@ class NtpIndex :
StackArrayIndex<Ntp, CAP>(a)
{}

inline INT32 findNtp(const ElementName& name) const
{
return this->findRef(genNtp(name));
}
protected:
inline bool isGreater(const Ntp& a, const Ntp& b) const
{
return Mem::cmp(a.name, b.name) > 0;
}

inline INT32 findNtp(const ElementName& name) const
{
return this->findRef(genNtp(name));
}
NOCOPY(NtpIndex)
NtpIndex();
};

#endif // H_
20 changes: 12 additions & 8 deletions application/components/BAS/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
basic integral types and limits
```

**I_Searchable.h**
**I_Array.h**
```
defintion of interface I_Searchable to apply:
defintion of interface I_Array to apply:
- bubble sort
- b-tree search
- uniqueness check / duplicates count
Expand All @@ -20,7 +20,11 @@ type safe memset & memcpy

**NtpArray.h**
```
Storage of Name Type Position
name, type, position
- storage of name, type, position
- index of name, type, position by name
```

**StackArray.h**
Expand All @@ -31,24 +35,24 @@ StackArrays
- can be filled with objects at runtime
- do not provide any overflow protection
SimpleStackArray
StackArray
keeps objects in the same order as they were added.
StackArray
SortableStackArray
- can be sorted
- can search for elements
Derived classes have to provide
the isGreater method for objects of their type
See interface I_Searchable
See interface I_Array
class CRef
enables to store references as objects
StackArrayIndex
provides search for unsorted SimpleStackArray.
provides search for unsorted StackArray.
Derived classes have to provide
the isGreater method for objects of their type
See interface I_Searchable
See interface I_Array
```

**coding.h**
Expand Down
Loading

0 comments on commit c67997b

Please sign in to comment.