Skip to content

Commit 19d82b9

Browse files
committed
v1.0.0
0 parents  commit 19d82b9

File tree

8 files changed

+938
-0
lines changed

8 files changed

+938
-0
lines changed

Diff for: .gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.vscode/
2+
build/
3+
old/

Diff for: lib/drxType_cpp_v1.0.0.a

13.4 KB
Binary file not shown.

Diff for: lib/drxType_cpp_v1.0.0.dll

120 KB
Binary file not shown.

Diff for: licence.md

+675
Large diffs are not rendered by default.

Diff for: makefile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
include src/cpp/cpp.mk
2+
3+
info:
4+
@echo "-------------------------------------"
5+
@echo "Project Configuration for cpp :"
6+
@echo "-------------------------------------"
7+
@echo "CXX (C++ Compiler) . . . . . . . : $(CXX)"
8+
@echo "CXXFLAGS (C++ Flags) . . . . . . : $(CXXFLAGS)"
9+
@echo "CPP_SRC_FILES (C++ Source Files) : $(SOURCES)"
10+
@echo "PROJECT_NAME . . . . . . . . . . : $(LIB_NAME)"
11+
@echo "-------------------------------------"

Diff for: readme.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
![License](https://img.shields.io/badge/license-GPL3-green)
2+
![License](https://img.shields.io/badge/version-v1.0.0-green)
3+
4+
5+
# DRX types : type implementation for C, C++ and Python dev
6+
Implementation of a lot of type with docstring documentation made has exercice to improve personal dev skill in C and C++.
7+
8+
## Dependencies :
9+
- Need makefile (4.4.x)
10+
- C (Version depend on the list under this)
11+
- C++ (Version depend on the list under this)
12+
13+
## All types implemented
14+
| Type name | for C | for C++ | For python | Folder |
15+
|:-------------------------|:------|:--------|:-----------|:-------------------------:|
16+
| Linked list (single ptr) | X | >v3 | X | [](./src/linked_list/) |
17+
| Dynamic Array | X | >v3 | X | [](./src/dynamic_array/) |
18+
19+
## All type to implement :
20+
Legend:
21+
| Symbol | Meaning |
22+
|:------:|:------------------|
23+
| 🛑 | will node be made |
24+
|| not made |
25+
|| made |
26+
| ✅P | made using Py API* |
27+
| 🔁 | in dev |
28+
29+
> *: Some python implementations is just C++ implementation of Python API, in this case, the symbol : `✅P`
30+
31+
| Type name | in C ? | in C++ ? | in Python ? |
32+
|:---------------------------|:------:|:--------:|:-----------:|
33+
| Linked list (double ptr) ||||
34+
| Linked list (single ptr) | 🔁 |||
35+
| Dynamic Array || 🔁 ||
36+
| Binary tree ||||
37+
| n-branch tree ||||
38+
| graphs ||||
39+
| Vector2/Vector3 | 🔁 | 🔁 | 🔁 |
40+
| Queue FIFO | 🔁 | 🔁 | 🔁 |
41+
| Stack LIFO | 🔁 | 🔁 | 🔁 |
42+
| Deque (double-ended queue) | 🔁 | 🔁 | 🔁 |
43+
44+
## Changelogs
45+
- **v1.0.0**
46+
- Added Linked list in single ptr
47+
48+
## Music
49+
If you want to take a cup of coffee and see/review my code here one of my playlist with :
50+
51+
[![Ma Playlist](https://image-cdn-ak.spotifycdn.com/image/ab67706c0000da8457887b87c49785d8d3fc57b4)](https://open.spotify.com/playlist/2MxUFRUAxXbT7cG0rsOewU)

Diff for: src/cpp/chaine.cpp

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
[FR] Implementation du concept de Liste chaînée en C++ vue en cours
3+
[ANG] Implementation of chain list concept in C++
4+
@licence = GPL-3
5+
@author = Dervaux Esteban
6+
*/
7+
#include <iostream> // For std::cout & std::endl
8+
#include <stdexcept> // For std::runtime_error
9+
#include <string> // For std::string, std::to_string(), std::pop_back()
10+
//#include <cassert> // For check the code with some cases
11+
using std::string; // Shortcut for std::string to string
12+
13+
struct node {
14+
int value;
15+
node* previous;
16+
// Model of a constructor of an struct
17+
node(int val, node* prev) : value(val), previous(prev) {}
18+
};
19+
20+
/* NodeChain is an node manager using none fixed memory bloc */
21+
class NodeChain {
22+
private :
23+
unsigned int size; // Size of the chain
24+
node* sommet; // Pointer to an node at the first place of the chain
25+
public :
26+
/* ----- Main methods ----- */
27+
void pushNode(int value) {
28+
/* Insert new node in memory */
29+
sommet = new node(value, sommet);
30+
std::cout << "Added node with value: " << value << std::endl;
31+
size++;
32+
}
33+
34+
void pullNode(const unsigned int index) {
35+
/* Pull a node from the chain using her index */
36+
if(index >= size) {
37+
throw std::runtime_error("IndexError, index >= size of the Chain, index = "+std::to_string(index)+", index need to be < size");
38+
}
39+
node* pulledNode = getByIndex(index);
40+
if (index == size-1) {
41+
// In cas we pulled the sommet
42+
sommet = sommet->previous; // Now the first element is the next one
43+
} else if (index == 0) {
44+
// In case we pulled the first element at index 0
45+
getByIndex(1)->previous = nullptr;
46+
} else {
47+
// In common case
48+
node* nextNode = getByIndex(index+1);
49+
node* previousNode = getByIndex(index-1);
50+
nextNode->previous = previousNode;
51+
}
52+
delete pulledNode; // Pull out the node from RAM
53+
size--; // Decrement size because we pulled an element
54+
}
55+
56+
node* getByIndex(unsigned int index) {
57+
/* Return an pointer of the node in the node chain at the index index*/
58+
node* actualNode = sommet;
59+
if(index >= size) {
60+
throw std::runtime_error("IndexError, index > size of the Chain, index = "+std::to_string(index));
61+
}
62+
63+
for (size_t i = size-1; i > index; i--) {
64+
// We go back to the previous and set it the actual index time
65+
actualNode = actualNode->previous;
66+
};
67+
return actualNode; // Return result
68+
}
69+
70+
/* ----- Chain representation methods ----- */
71+
string getChainToString() {
72+
/* Return the chain as a string */
73+
string chain = "[";
74+
if (size != 0) {
75+
node* actualNode = sommet;
76+
for (size_t i = size-1; i > 0; i--) {
77+
chain += std::to_string(actualNode->value) + ", ";
78+
actualNode = actualNode->previous;
79+
};
80+
chain.pop_back(), chain.pop_back();
81+
}
82+
return chain+"]"; // Return a chain like "[a, b, c, d]"
83+
}
84+
85+
/* ----- Constructor and destructor ----- */
86+
NodeChain() {
87+
size = 0; // At the construction, the chain is empty
88+
sommet = nullptr;
89+
}
90+
~NodeChain() {
91+
while (sommet != nullptr) {
92+
node* toDelete = sommet;
93+
std::cout << "Delete sommet : " << sommet << std::endl;
94+
sommet = sommet->previous;
95+
delete toDelete;
96+
};
97+
delete sommet; // Enfin tue le sommet
98+
99+
}
100+
};
101+
102+
/* Test function for NodeChain*/
103+
class TestNodeChain {
104+
private:
105+
// Test getChainToString with empty chain
106+
int Test_emptyGetChainToString() {
107+
NodeChain lambdaChain;
108+
string result = lambdaChain.getChainToString();
109+
return (result == "[]") ? 0 : 1;
110+
}
111+
// Test push with some value
112+
int Test_pushNode() {
113+
NodeChain lambdaChain;
114+
lambdaChain.pushNode(10);
115+
lambdaChain.pushNode(0.5);
116+
return (lambdaChain.getChainToString() == "[10, 0.5]") ? 0 : 1;
117+
}
118+
119+
120+
public:
121+
TestNodeChain() {
122+
};
123+
~TestNodeChain(){};
124+
};
125+
126+
127+
int main(int argc, char const *argv[]) {
128+
NodeChain manage;
129+
std::cout << manage.getChainToString() << std::endl;
130+
manage.pushNode(10); // Create new node
131+
manage.pushNode(20); // Create new node
132+
manage.pushNode(30); // Create new node
133+
manage.pushNode(40); // Create new node
134+
std::cout << manage.getChainToString() << std::endl;
135+
manage.pullNode(1); // Deleted second node
136+
std::cout << manage.getChainToString() << std::endl;
137+
// "manage" stop being used so the deconstructor of NodeManager is call
138+
// All node's has been destroyed from the ram
139+
return 0;
140+
}

Diff for: src/cpp/cpp.mk

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Variables générales
2+
CXX = g++
3+
AR = ar
4+
SRC_DIR = src
5+
OBJ_DIR = build
6+
LIB_DIR = lib
7+
INCLUDE_DIR = include
8+
CXXFLAGS = -std=c++17 -O2 -I$(INCLUDE_DIR) -fPIC
9+
LDFLAGS =
10+
SOURCES = $(wildcard $(SRC_DIR)/cpp/*.cpp)
11+
OBJECTS = $(patsubst $(SRC_DIR)/cpp/%.cpp, $(OBJ_DIR)/%.o, $(SOURCES))
12+
13+
LIB_VERSION = v1.0.0
14+
LIB_NAME = drxType_cpp_$(LIB_VERSION)
15+
16+
# Bibliothèque
17+
STATIC_LIB = $(LIB_DIR)/$(LIB_NAME).a
18+
SHARED_LIB = $(LIB_DIR)/$(LIB_NAME).so
19+
20+
# Détection de l'OS
21+
ifeq ($(OS),Windows_NT)
22+
SHARED_LIB = $(LIB_DIR)/$(LIB_NAME).dll
23+
LDFLAGS += -shared
24+
CXXFLAGS += -DWIN32
25+
else
26+
UNAME_S := $(shell uname -s)
27+
ifeq ($(UNAME_S),Darwin)
28+
SHARED_LIB = $(LIB_DIR)/$(LIB_NAME).dylib
29+
LDFLAGS += -dynamiclib
30+
CXXFLAGS += -DMACOS
31+
else
32+
CXXFLAGS += -DLINUX
33+
endif
34+
endif
35+
36+
# Règles par défaut
37+
all: $(STATIC_LIB) $(SHARED_LIB)
38+
39+
# Création de la bibliothèque statique
40+
$(STATIC_LIB): $(OBJECTS)
41+
mkdir -p $(LIB_DIR)
42+
$(AR) rcs $@ $^
43+
44+
# Création de la bibliothèque dynamique
45+
$(SHARED_LIB): $(OBJECTS)
46+
mkdir -p $(LIB_DIR)
47+
$(CXX) $(LDFLAGS) -o $@ $^
48+
49+
# Compilation des fichiers objets
50+
$(OBJ_DIR)/%.o: $(SRC_DIR)/cpp/%.cpp
51+
mkdir -p $(OBJ_DIR)
52+
$(CXX) $(CXXFLAGS) -c $< -o $@
53+
54+
# Nettoyage
55+
clean:
56+
rm -rf $(OBJ_DIR) $(LIB_DIR)
57+
58+
.PHONY: all clean

0 commit comments

Comments
 (0)