# letscode **Repository Path**: ailbd/letscode ## Basic Information - **Project Name**: letscode - **Description**: letscode是一个用于练习算法编程的管理应用,它将算法程序以插件的形式进行管理,并动态的加载json文件中为算法定义的数据,方便进行数据输入和数据持久化。 - **Primary Language**: Unknown - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 1 - **Created**: 2021-09-28 - **Last Updated**: 2023-02-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: LeetCode, gn, shell, Framework, GDB ## README # Letscode ## Description letscode is a management application for practicing algorithmic programming. It manages algorithmic programs as plugins and dynamically loads data defined for the algorithm in json files to facilitate data entry and data persistence. ## Copyright ``` Copyright (c) 2023 Jianjun Yue and letscode contributors. ``` ## Hierarchy ``` . ├── build # build scripts │   ├── scripts │   └── toolchains ├── core # letscode core logic │   ├── dataloader # data loader │   │   ├── cjson # cjson used to parse configs │   │   ├── data # defind data files │   │   └── include │   ├── include │   └── manager # solution manager │   └── include ├── docs # docs │   └── resource │   └── pics ├── leetcode # types of algorithm solutions │   ├── array │   ├── dynamic_program │   ├── find_and_union │   ├── greedy │   ├── hash │   ├── include │   ├── recursive │   ├── search │   ├── slip_window │   ├── sort │   ├── stack │   ├── standby │   ├── string │   └── tree ├── securec # securec │   ├── include │   └── src ├── tests # test │   ├── gtest # test suits for unittest │   │   ├── include │   │   └── testsuits │   ├── standby # standalone tests, third party │   └── ytest └── utils # common utils ├── include └── src ``` ## Architecture ![architecture](./docs/resource/pics/letscode_arch.png) ## Environment Set Up * Prerequesite 1. [gn][gn official page] 2. [ninja][ninja official page] 3. [cmake][cmake official page] 4. gtest * gn GN is a meta-build system that generates build files for Ninja. You can get binary at [here][gn download url] for unix like system. Substitude following _"$YOUR_GN_DIR"_ with the directory in where your's gn sets. ``` vim ~/.bashrc export PATH=$YOUR_GN_DIR:$PATH ``` * ninja We use gn to parse BUILD.gn and generate ninja files. ninja will inteprete ninja scripts to compile source code. You can [download the Ninja binary][ninja download url]. ``` vim ~/.bashrc export PATH=$YOUR_NINJA_DIR:$PATH ``` * cmake(optional) Cross-platform family of tools designed to build, test and package software. We use cmake hereby to compile googletests. Following [download page][cmake download page] to get latest version. ``` tar -xzf cmake-xx.xx.x-linux-x86_64.tar.gz vim ~/.bashrc export PATH=$YOUR_CMAKE_DIR:$PATH ``` * gtest(optional) Worldkonwn googletest. you can access toturials and get more infomation at [official page][gtest official page]. Source code download page is [here][gtest source code]. Compile googletest: ``` cd googletest mkdir build cmake .. # if you want install gtest to non standard system directories ccmake . # configure install prefix make; make install ``` Following message will be helpful for you while you not install gtest into _/usr/local_ or _/usr/lib_. > setting C_INCLUDE_PATH (for C header files) or CPLUS_INCLUDE_PATH (for C++ header files) to add search path. > CPATH will set the path for both C and C++ (and any other language). [more relative info](https://web.archive.org/web/20090129230009if_/http://www.network-theory.co.uk/docs/gccintro/gccintro_23.html) about searching path; ## Compile Solutions Use build.sh to compile solutions. Normally, you just need type: ``` ./build.sh -g out ## build letscode and solutons ./build.sh -T leetcode:leetcode ## build specified target ./build.sh -g out -p enable_asan="true" ## build letscode with asan ./build.sh -g out -p use_plugin="false" ## build solutions as standalone executable ./build.sh -g out -p testing="true" ## build all targets with testsuits ``` scripts will start build all targets or certain targets specified by "-T". ## Compile Unit Testsuits(To be complete) Solutions can be easily tested with google test framework. ``` ./build.sh -g out -p only_test="true" ## build only tests ./build.sh -T tests/gtests:test -p testing="true" ``` ## Add solutions All solutions should be placed under //leetcode, whatever subdir. Conventionally, A solution has only one source file which name will be used as target name when compiling. Standalone solution must have a main entry. But, fixd formated main function must be implement If you want to use the script solution_adp.sh to automate the plug-in adaptation for your Solution, you must implement a fixed form of the main function. And a newline should be followed by your main function body. ``` int main(int argc, char const *argv[]) { } // newline is needed ``` Modulized solution (plugin) have common predefined hook functions must be implemented. At least this two below should be done. And you should use macro HAS_FEATURE_SLUMGR to compile your solution conditionally. ``` # ifdef HAS_FEATURE_SLUMGR void *solution_init(void *pdata) { } #else // HAS_FEATURE_SLUMGR void *solution_deinit(void *pdata) { } #endif // HAS_FEATURE_SLUMGR ``` Now, lets compile your solution. It's pretty simple to add script to compile your solution if you want to used it as a plugin of letscode. just add a line like below into //leetcode/solutions.gni. ``` ["solution-name", "file-type"], ``` if your solution name is unique among solutions under leetcode, you can just set file-type to null. Then, script locate_src.sh will automatically find it out and make it compiled. Currently, solution-name should be unique within solutions.gni, otherwise, compile error will be occur. ## Dataloader Dataloader is a module in Letscode that provides Solutions with the ability to fetch data from json. To make it easier to read data into C++ string and vector containers, you can use the following function macros for data loading for more efficiency. | MACRO | PARAMETERS | DESCRIPTION | |----|------|-----| |LOADDATA_DUB(pdata, data)|sluargs_t *pdata, double data|Load double data| |LOADDATA_DUB(pdata, data)|sluargs_t *pdata, int data|Load int data| |LOADDATA_STR(pdata, str)|sluargs_t *pdata, string str|Load string data| |LOADDATA_STR_ARR(pdata, vect)|sluargs_t *pdata, vector vect|Load string array| |LOADDATA_DUB_ARR(pdata, vect)|sluargs_t *pdata, vector vect|Load double array| |LOADDATA_INT_ARR(pdata, vect)|sluargs_t *pdata, vector vect|Load int array| |LOADDATA_DUB_2D_ARR(pdata, vvect)|sluargs_t *pdata, vector> vvect|Load a two-dimensional array of type double| |LOADDATA_DUB_2D_ARR(pdata, vvect)|sluargs_t *pdata, vector> vvect|Load a two-dimensional array of type int| |OBJLOADDATA_PRELOAD(pdata)|sluargs_t *pdata|Preload for object data| |OBJLOADDATA_DUB(key, data)|char * key, double data|Load the double data corresponding to the object key| |OBJLOADDATA_INT(key, data)|char * key, int data|Load the int data corresponding to the object key| |OBJLOADDATA_DUB_ARR(key, vect)|char * key, vector vect|Load the double array corresponding to the object key| |OBJLOADDATA_INT_ARR(key, vect)|char * key, vector vect|Load the int array corresponding to the object key| |OBJLOADDATA_DUB_2D_ARR(key, vvect)|char * key, vector> vvect|Load the double two-dimensional array corresponding to the object key| |OBJLOADDATA_INT_2D_ARR(key, vvect)|char * key, vector> vvect|Load the int two-dimensional array corresponding to the object key| |OBJLOADDATA_STR(key, str)|char * key, string str|Load the string data corresponding to the object key| |OBJLOADDATA_STR_ARR(key, vect)|char * key, vector vect|Load the string array corresponding to the object key| Now, please enjoy it! :) ## Get Involved In Commit or pull request will be welcome, let's code together. [gn official page]:https://gn.googlesource.com/gn/ [gn download url]:https://chrome-infra-packages.appspot.com/dl/gn/gn/linux-amd64/+/latest [ninja official page]:https://ninja-build.org/ [ninja download url]:https://github.com/ninja-build/ninja/releases [cmake official page]:https://cmake.org/ [cmake download page]:https://cmake.org/download/ [gtest official page]:https://google.github.io/googletest/ [gtest source code]:https://github.com/google/googletest [leetcode official page]:https://leetcode-cn.com