# abs_zombieDataFrame **Repository Path**: SongpingWang/abs_zombie_data_frame ## Basic Information - **Project Name**: abs_zombieDataFrame - **Description**: zombieDataFrame的进一步抽象并完善代码 - **Primary Language**: C++ - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-11-27 - **Last Updated**: 2025-07-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # NDFrame轻量级数据处理库 [【新文档】](./doc_static/ZDataFrame.md) #### 介绍 - **ZDataFrame 固定字段的数据处理库** #### ZDataFrame ZDataFrame固定字段为:`idx` | `x0` | `y0` | `x1` | `y1` | `width` | `height` | `text` | `text_sep` 提供了一些方法用于处理数据 1. 使用结构体数组封装数据结构 2. 字符串字段使用了预分配字符串空间 3. 命名空间RE中函数是针对字符串进行正则提取 实现这个库的意图: >实现一个类似python的pandas库,但是个人能力有限,还有就是我这边处理的数据也只需要这些字段了。使用固定字段,结构体简单,库的灵活性虽然降低,但是有更高的性能,更低的内存占用。 #### 测试代码与输出 ##### 测试ZDataFrame库 1. 函数方法字段类型说明: - 字段:`x0,y0,x1,y1,width.height`都为int类型 - 字段:`text, text_sep`都为std::string/std::wstring类型 - 字段: `field` 为Field枚举类型:为:`IDX,X0,Y0,X1,Y1,Width,Height,Text,Text_sep` 2. 库的函数或者方法介绍 - 专注于坐标与字符串的混合关系筛选 - 函数名形如`DF_xxx()`,也就是DF开头的函数都返回副本DataFrame(执行了深复制) - 函数名形如`DV_xxx()`,也就是DV开头的函数都返回DataFrame的视图DataView(无复制),DataView仅仅保留DataFrame连续片段的首地址与尾地址。 - 函数名形如`loc_xxx()`的筛选函数用于对包含生命周期进行筛选(也即是DataFrame原始数据,或者DF_xxx()函数返回的数据)。函数的返回值为DataFrame中的部分符合筛选条件的地址(指针)不进行**深复制**。 - 函数名形如`loc2_xxx()`的筛选函数用于对`loc_xxx()`函数的返回值进行再次筛选(再次筛选符合条件数据的指针)。 3. 数据结构属性介绍 | 函数名 | 功能 | 说明 | | :----------------------------------------------------------- | :----------------------------------------------------------- | :----------------------------------------------------------- | | `df.clone()` | `df`的备份 | 深复制 | | `df.size()` | `df`的行数 | | | `df.empty()` | `df`是否为空 | 行数等于0时为空 | | `df.capacity()` | `df`的容量 | 添加行大于容量时会发生
内存重新分配 | 4. 其它函数介绍: 文档说明:ZDataFrame.md文档为ZDataFrame所有函数的朴素方法,其中包含DF_regex.md,ColView.md,ZDataView.md文档中所有函数的方法。 其中ColView.md中的方法是为了方便链式调用,它获取了ZDataFrame中的列视图, 其中ZDataView.md中的方法是与ZDataFrame大抵相同调用,它获取了ZDataFrame中的连续行视图切片。 - [【ZDataFrame.md】为DataFrame的一系列朴素函数](./doc/ZDataFrame.md) - [【DF_regex】都返回副本DataFrame的一系列函数](./doc/DF_regex.md) - [【ColView.md】仿python使用方法的一系列函数(DataFrame列视图)](./doc/ColView.md) - [【DV_regex.md】为DataFrame切片的一系列函数(DataFrame行视图)](./doc/DV_regex.md) ```cpp // 测试参数化构造函数 ZDataFrame paramFrame({ {0, 10, 120, 370, 460, 50, "Sample Text 1", "Separator 1mmmmm"}, {1, 125, 125, 535, 475, 55, "Sample Text 22222", "Separator 2lll"}, {2, 135, 215, 335, 485, 55, "Sample Text 222", "Separator 2ii"}, {3, 145, 205, 235, 495, 55, "Sample Text 223", "Separator 2oooooooooooooooooo"}, {4, 155, 285, 135, 405, 55, "Sample Text 234", "Separator 2kkkkkkk"}, {5, 165, 275, 351, 425, 55, "Sample Text 2123", "Separator kkkkk2"} }); // 测试复制构造函数 ZDataFrame copyFrame = paramFrame; // 测试移动构造函数 ZDataFrame moveFrame = std::move(paramFrame); // 测试克隆函数 ZDataFrame cloneFrame = moveFrame.clone(); // 测试输出视图(第一行) ZDataView view(cloneFrame); std::cout << "Filtered view: \n"; format_print(view); // 测试新增行 std::cout << "size: " << cloneFrame.size() << ", capacity: " << cloneFrame.capacity() << std::endl; cloneFrame.push_back(NDFrame::DataItem{ 6, 144, 215, 236, 497, 58, "Sample Text 224", "Separator 2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" }); std::cout << "size: " << cloneFrame.size() << ", capacity: " << cloneFrame.capacity() << std::endl; format_print(cloneFrame); // 测试过滤指针 auto pointers = cloneFrame.filter([](const DataItem& item) { return item.x0 > 160 && item.y0 > 270; }); std::cout << "Filtered pointers: \n"; format_print(pointers); return 0; ``` 输出如下: ```shell Filtered view: +=====+=====+=====+=====+=====+========+===============+==================+ | idx | x0 | y0 | x1 | y1 | height | text | text_sep | +=====+=====+=====+=====+=====+========+===============+==================+ | 0 | 10 | 120 | 370 | 460 | 50 | Sample Text 1 | Separator 1mmmmm | +-----+-----+-----+-----+-----+--------+---------------+------------------+ size: 6, capacity: 6 size: 7, capacity: 12 +=====+=====+=====+=====+=====+========+===================+=================================================+ | idx | x0 | y0 | x1 | y1 | height | text | text_sep | +=====+=====+=====+=====+=====+========+===================+=================================================+ | 0 | 10 | 120 | 370 | 460 | 50 | Sample Text 1 | Separator 1mmmmm | | 1 | 125 | 125 | 535 | 475 | 55 | Sample Text 22222 | Separator 2lll | | 2 | 135 | 215 | 335 | 485 | 55 | Sample Text 222 | Separator 2ii | | 3 | 145 | 205 | 235 | 495 | 55 | Sample Text 223 | Separator 2oooooooooooooooo | | 4 | 155 | 285 | 135 | 405 | 55 | Sample Text 234 | Separator 2kkkkkkk | | 5 | 165 | 275 | 351 | 425 | 55 | Sample Text 2123 | Separator kkkkk2 | | 6 | 144 | 215 | 236 | 497 | 58 | Sample Text 224 | Separator 2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | +-----+-----+-----+-----+-----+--------+-------------------+-------------------------------------------------+ Filtered indices: +=====+=====+=====+=====+=====+========+===================+=======================================+ | idx | x0 | y0 | x1 | y1 | height | text | text_sep | +=====+=====+=====+=====+=====+========+===================+=======================================+ | 0 | 10 | 120 | 370 | 460 | 50 | Sample Text 1 | Separator 1mmmmm | | 1 | 125 | 125 | 535 | 475 | 55 | Sample Text 22222 | Separator 2lll | | 2 | 135 | 215 | 335 | 485 | 55 | Sample Text 222 | Separator 2ii | | 3 | 145 | 205 | 235 | 495 | 55 | Sample Text 223 | Separator 2oooooooooooooooooooooooooo | +-----+-----+-----+-----+-----+--------+-------------------+---------------------------------------+ Filtered pointers: +=====+=====+=====+=====+=====+========+==================+==================+ | idx | x0 | y0 | x1 | y1 | height | text | text_sep | +=====+=====+=====+=====+=====+========+==================+==================+ | 5 | 165 | 275 | 351 | 425 | 55 | Sample Text 2123 | Separator kkkkk2 | +-----+-----+-----+-----+-----+--------+------------------+------------------+ ```