This repository has been archived by the owner on Sep 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
book: update vector chapter dslings: 1.update vector's exercise code - split big task to small task 2.add D2DS_WAIT for every exercise-code 3.optimize: add compile bypass mechanism by target file's mtime Signed-off-by: SPeak <[email protected]>
- Loading branch information
1 parent
6f7a26e
commit 9dcf4da
Showing
27 changed files
with
445 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,5 +16,8 @@ | |
int main() { | ||
d2ds::Array<int, 5> intArr; | ||
d2ds::Array<double, 10> doubleArr; | ||
|
||
D2DS_WAIT | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,8 @@ | |
|
||
int main() { | ||
d2ds::Array<int, 5> intArr { 5, 4, 3, 2 /*, 1*/ }; | ||
|
||
D2DS_WAIT | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,5 +24,7 @@ int main() { | |
intArr[4] = intArr[0]; | ||
d2ds_assert_eq(intArr[0], intArr[4]); | ||
|
||
D2DS_WAIT | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,5 +22,7 @@ int main() { | |
|
||
d2ds_assert_eq(4, intArr.back()); | ||
|
||
D2DS_WAIT | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,5 +24,7 @@ int main() { | |
val++; | ||
} | ||
|
||
D2DS_WAIT | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,5 +21,7 @@ int main() { | |
|
||
d2ds_assert_eq(mVal.get(), 2); | ||
|
||
D2DS_WAIT | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,5 +27,7 @@ int main() { | |
mVal.set(100); | ||
d2ds_assert_eq(mVal.get(), 100); | ||
|
||
D2DS_WAIT | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,8 @@ | |
int main() { | ||
d2ds::PyRange(0, 10); | ||
d2ds::PyRange(0, 5, 200); | ||
|
||
D2DS_WAIT | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,5 +21,7 @@ int main() { | |
auto begin = range.begin(); | ||
auto end = range.end(); | ||
|
||
D2DS_WAIT | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,5 +27,7 @@ int main() { | |
++begin; | ||
d2ds_assert_eq(*begin, 1); | ||
|
||
D2DS_WAIT | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,10 @@ | |
|
||
|
||
int main() { | ||
|
||
d2ds::Box<int> intBox; | ||
d2ds::Box<dstruct::String> stringBox; | ||
|
||
D2DS_WAIT | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// vector.0.cpp - readonly | ||
// | ||
// 描述: | ||
// 定义Vector | ||
// | ||
// 目标/要求: | ||
// - 实现类模板和数据初成员定义 | ||
// - 在exercises/array/Vector.hpp中完成你的代码设计 | ||
// - 通过编译器检测 | ||
// | ||
|
||
#include "common/common.hpp" | ||
|
||
#include <exercises/array/Vector.hpp> | ||
|
||
struct DataMember { | ||
int size; | ||
void *ptr; | ||
}; | ||
|
||
int main() { | ||
|
||
d2ds::Vector<int> intVec; | ||
d2ds_assert(sizeof(intVec) >= sizeof(DataMember)); | ||
|
||
D2DS_WAIT | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// vector.1.cpp - readonly | ||
// | ||
// 描述: | ||
// Vector自定义分配器支持 | ||
// | ||
// struct AllocatorInterface { | ||
// static void * allocate(int bytes); | ||
// static void deallocate(void *addr, int bytes); | ||
// }; | ||
// | ||
// 目标/要求: | ||
// - 开发者能使用默认分配器, 也可以通过模板的第二个参数配置自定义的分配器 | ||
// - 在exercises/array/Vector.hpp中完成你的代码设计 | ||
// - 通过编译器检测 | ||
// | ||
|
||
#include "common/common.hpp" | ||
|
||
#include <exercises/array/Vector.hpp> | ||
|
||
struct StackMemAllocator { | ||
|
||
static void * allocate(int bytes) { | ||
HONLY_LOGI("StackMemAllocator: try to allocate %d bytes", bytes); | ||
mTop = mTop - bytes; | ||
assert(mTop >= mMemory); | ||
return mTop; | ||
} | ||
|
||
static void deallocate(void *addr, int bytes) { | ||
HONLY_LOGI("StackMemAllocator: free addr %p, bytes %d", addr, bytes); | ||
// nothing | ||
} | ||
|
||
static void config_and_init(char *memory, int size) { | ||
mMemory = memory; | ||
mTop = memory + size; | ||
} | ||
|
||
static char *mTop; | ||
static char *mMemory; | ||
}; | ||
|
||
char * StackMemAllocator::mTop = nullptr; | ||
char * StackMemAllocator::mMemory = nullptr; | ||
|
||
int main() { | ||
|
||
char stackMemory[1024]; | ||
StackMemAllocator::config_and_init(stackMemory, 1024); | ||
|
||
{ | ||
int *intPtr = (int *) StackMemAllocator::allocate(sizeof(4)); | ||
*intPtr = 1010; | ||
std::cout << intPtr << ": " << *intPtr << std::endl; | ||
StackMemAllocator::deallocate(intPtr, sizeof(intPtr)); | ||
} | ||
|
||
d2ds::Vector<int, d2ds::DefaultAllocator> intVec; | ||
d2ds::Vector<char, StackMemAllocator> charVecByStack; | ||
d2ds::Vector<double> doubleVec; | ||
|
||
D2DS_WAIT | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// vector.1.cpp - readonly | ||
// | ||
// 描述: | ||
// 显示定义数据结构Vector的bigfive - 析构 | ||
// | ||
// 目标/要求: | ||
// - 实现Vector的析构函数 | ||
// - 在exercises/array/Vector.hpp中完成你的代码设计 | ||
// - 通过编译器检测 | ||
// | ||
|
||
#include "common/common.hpp" | ||
|
||
#include <exercises/array/Vector.hpp> | ||
|
||
using d2ds::BigFiveTest; | ||
|
||
int main() { | ||
|
||
d2ds::DefaultAllocator::debug() = true; | ||
|
||
{ | ||
d2ds::Vector<BigFiveTest::Obj> objArr(1); | ||
} | ||
|
||
d2ds_assert(BigFiveTest::destructor()); | ||
d2ds_assert_eq(1,d2ds::DefaultAllocator::deallocate_counter()); | ||
|
||
D2DS_WAIT | ||
|
||
return 0; | ||
} |
Oops, something went wrong.