Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
all: update d2ds book and dslings
Browse files Browse the repository at this point in the history
0. update dirs and dslings impl
1. book: add cpp basic
2. dslings: template and range-base for

Signed-off-by: SPeak <[email protected]>
  • Loading branch information
Sunrisepeak committed Apr 3, 2024
1 parent a403790 commit 9d95095
Show file tree
Hide file tree
Showing 26 changed files with 691 additions and 44 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ Book: https://sunrisepeak.github.io/d2ds
// - 通过所有编译器检测 和 断言
//

#include <tests/common.hpp>
#include "common/common.hpp"

#include <exercises/dslings.hpp>
#include "exercises/dslings.hpp"

int main() {

Expand Down
26 changes: 22 additions & 4 deletions tests/common.hpp → common/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,34 @@
#define __COMMON_HPP__D2DS

#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <thread>

#include <dstruct.hpp>
#define HONLY_LOGGER_TAG "D2DS"
#include "common/honly_logger.hpp"
#include "common/dslings_config.hpp"


#define d2ds_assert(expr) \
if (!(expr)) { \
HONLY_LOGW("❌ | %s", #expr); \
} else { \
HONLY_LOGI("✅ | %s", #expr); \
}

#define d2ds_assert_eq(a, b) \
if (a != b) \
std::cerr << #a << " == " << #b << " (" << a << " == " << b << ")" << std::endl; \
assert((a) == (b))
if (a != b) {\
HONLY_LOGW("❌ | %s == %s (%s == %s)", \
#a, #b, std::to_string(a).c_str(), std::to_string(b).c_str()); \
} else {\
HONLY_LOGI("✅ | %s == %s (%s == %s)", \
#a, #b, std::to_string(a).c_str(), std::to_string(b).c_str()); \
}

#define D2DS_WAIT HONLY_LOGW("Delete the D2DS_WAIT to continue...");


namespace d2ds {

Expand Down
16 changes: 16 additions & 0 deletions common/dslings_config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef __DSLINGS_CONFIG_HPP__D2DS
#define __DSLINGS_CONFIG_HPP__D2DS

/*
// checker config
#define DSLINGS_0_CHECKER CHCKER_ENABLE
#define DSLINGS_1_CHECKER CHCKER_ENABLE
#define DSLINGS_2_CHECKER CHCKER_ENABLE
#define TEMPLATE_0_CHECKER CHCKER_ENABLE
#define TEMPLATE_1_CHECKER CHCKER_ENABLE
#define TEMPLATE_2_CHECKER CHCKER_ENABLE
#define CHCKER_ENABLE
#define CHCKER_PASS return 0;
*/

#endif
17 changes: 17 additions & 0 deletions common/honly_logger.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef __LOGGER_HPP__HONLY
#define __LOGGER_HPP__HONLY

#include <cstdio>

#ifndef HONLY_LOGGER_TAG
#define HONLY_LOGGER_TAG "HONLY"
#endif

#define LOG_ENABLE true
#define _HONLY_LOG(fd, ...) if (LOG_ENABLE) fprintf (fd, __VA_ARGS__); fprintf (fd, "\033[0m\n")
#define HONLY_LOGI(...) fprintf (stdout, "\033[32m[%s LOGI]: \t%s: %s:%d - ", HONLY_LOGGER_TAG, __func__, __FILE__, __LINE__); _HONLY_LOG(stdout, __VA_ARGS__)
#define HONLY_LOGD(...) fprintf (stdout, "\033[37m[%s LOGD]: \t%s: %s:%d - ", HONLY_LOGGER_TAG, __func__, __FILE__, __LINE__); _HONLY_LOG(stdout, __VA_ARGS__)
#define HONLY_LOGW(...) fprintf (stdout, "\033[33m[%s LOGW]: \t%s: %s:%d - ", HONLY_LOGGER_TAG, __func__, __FILE__, __LINE__); _HONLY_LOG(stdout, __VA_ARGS__)
#define HONLY_LOGE(...) fprintf (stderr, "\033[31m[%s LOGE]: \t%s: %s:%d - ", HONLY_LOGGER_TAG, __func__, __FILE__, __LINE__); _HONLY_LOG(stderr, __VA_ARGS__)

#endif
12 changes: 8 additions & 4 deletions exercises/array/Array.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#ifndef __ARRAY_HPP__D2DS
#define __ARRAY_HPP__D2DS

//#include <DStruct/dstruct.hpp>

namespace d2ds {

//using dstruct::Array;

}
// show your code

template <typename T, unsigned int N>
class Array {


};

}
#endif
3 changes: 0 additions & 3 deletions exercises/dslings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace d2ds {



/*
class MaxValue {
public:
MaxValue(int val) {
Expand All @@ -29,8 +28,6 @@ class MaxValue {
int __mMaxVal;
};

*/

}

#endif
43 changes: 43 additions & 0 deletions exercises/other/cpp-base/RangeFor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef __RANGE_BASE_FOR_HPP__D2DS
#define __RANGE_BASE_FOR_HPP__D2DS

#include <common/common.hpp>

namespace d2ds {
// show your code

class py_range {
public:
py_range(int start, int end) : py_range(start, 1, end) { }

py_range(int start, int step, int end) {

__mLen = (end - start) / step;

d2ds_assert(start < end);
d2ds_assert(step > 0);
d2ds_assert(__mLen <= 100);

for (int i = 0; i < __mLen; i++) {
__mArr[i] = start;
start = start + step;
}
}

public:
const int * begin() const {
return __mArr;
}

const int * end() const {
return __mArr + __mLen;
}

private:
int __mLen;
int __mArr[100];
};

}

#endif
9 changes: 9 additions & 0 deletions exercises/other/cpp-base/Template.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef __TEMPLATE_HPP__D2DS
#define __TEMPLATE_HPP__D2DS

namespace d2ds {
// show your code

}

#endif
8 changes: 4 additions & 4 deletions src/Instroduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

#### 代码示例
```cpp
#include <tests/common.hpp>
#include <exercises/dslings.hpp>
#include "common/common.hpp"
#include "exercises/dslings.hpp"

int main() {

Expand Down Expand Up @@ -226,9 +226,9 @@ Book: https://sunrisepeak.github.io/d2ds
// - 通过所有编译器检测 和 断言
//
#include <tests/common.hpp>
#include "common/common.hpp"
#include <exercises/dslings.hpp>
#include "exercises/dslings.hpp"
int main() {
Expand Down
23 changes: 14 additions & 9 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@
# 阅读准备
- [导读](./Instroduction.md)

# 线性数据结构
# 常用数据结构
- [数组]()
- [Array数组]()
- [Vector动态数组]()

- [链表]()
- [静态单链表]()
- [静态双链表]()
- [嵌入式单链表]()
- [单链表]()
- [嵌入式双链表]()
- [双链表]()
- [静态链表]()

- []()
- [最值栈]()
- [单调栈]()
- [栈适配器]()

- [队列]()
- [队列适配器]()
- [双端队列]()
- [循环队列]()

# 非线性数据结构

Expand All @@ -29,9 +31,12 @@

- []()


# 相关主题
- [数据结构基本概念](./chapter_0.md)
- [C++基础]()
- [数据结构基本概念](other/0_ds_base.md)
- [C++基础](other/1_cpp_base.md)
- [范型编程](other/1_cpp_base.template.md)
- [范围for循环语法糖](other/2_cpp_base.rangefor.md)
- [内存管理]()
- [迭代器设计模式]()
- [设计模式]()
- [迭代器设计模式]()
- [适配器设计模式]()
File renamed without changes.
2 changes: 2 additions & 0 deletions src/other/1_cpp_base.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# C++ 基础

Loading

0 comments on commit 9d95095

Please sign in to comment.