Skip to content
Skills Library
Programming · Building & coding

pywayne-data-structure

/pywayne-data-structure

Data structure toolkit for logical condition trees, union-find operations, and XML file I/O. Use when working with tree-based data structures, set operations, union-find algorithms, or XML parsing and serialization.

Licence
MIT
Last repository change
23.10.2026

Assessment and security

90/ 100Class: good
Format20 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content30 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 23.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Data structure toolkit for logical condition trees, union-find operations, and XML file I/O. Use when working with tree-based data structures, set operations, union-find algorithms, or XML parsing and serialization.

Original author description

Data structure toolkit for logical condition trees, union-find operations, and XML file I/O. Use when working with tree-based data structures, set operations, union-find algorithms, or XML parsing and serialization.

How it works

  1. Quick Start
  2. ConditionTree - 逻辑条件树
  3. UnionFind - 并查集
  4. XmlIO - XML 读写
  5. 应用场景
Original SKILL.md headings · 158 lines, 305 words
SKILL.md preview
---
name: pywayne-data-structure
description: Data structure toolkit for logical condition trees, union-find operations, and XML file I/O. Use when working with tree-based data structures, set operations, union-find algorithms, or XML parsing and serialization.
---

# Pywayne Data Structure

数据结构工具集,提供逻辑条件树、并查集和 XML 文件读写功能。

## Quick Start

```python
from pywayne.data_structure import ConditionTree, UnionFind, XmlIO

# 逻辑条件树
tree = ConditionTree("root")
tree.append_by_path([{'tag': 'if', 'attrib': {}, 'text': '条件1'}])
tree.append_by_path([{'tag': 'else', 'attrib': {}, 'text': '条件2'}])

# 并查集操作
uf = UnionFind(10)
rep = uf.find(3)  # 返回集合标识
uf.union(1, 2)  # 合并两个集合

# XML 读写
xml_io = XmlIO("config.xml", "output.xml")
tree = xml_io.read()
xml_io.write("root", tree)
```

## ConditionTree - 逻辑条件树

用于存储和管理条件表达式的树形结构。

### 初始化

```python
from pywayne.data_structure import ConditionTree

tree = ConditionTree("root")
```

### 添加节点

通过路径列表添加节点。

```python
# 根节点
tree.append_by_path([{'tag': 'if', 'attrib': {}, 'text': '条件1'}])

# 子节点
path = [{'tag': 'if', 'attrib': {}, 'text': '条件1-1'}]
tree.append_by_path(path)
```

**节点字典格式**:`{'tag': 标签名, 'attrib': 属性字典, 'text': 文本内容}`

### 查找节点

**按标签名查找**:`find(nick_name)` - 查找指定标签名的节点

```python
tree.find("if")  # 返回 if 节点
```

**按路径查找**:`find_by_path(path)` - 沿给定路径查找节点

```python
node = tree.find_by_path(["root", "if", "条件1-1"])
```

### 打印树路径

打印从根到所有叶子的完整路径。

```python
tree.print_path()
```

## UnionFind - 并查集

并查集数据结构,支持按秩合并与路径压缩。

### 初始化

```python
from pywayne.data_structure import UnionFind

uf = UnionFind(10)  # N 个元素
```

### 查找集合标识

```python
rep = uf.find(3)  # 返回元素 3 所在集合的标识(整数)
```

### 合并集合

```python
uf.union(1, 2)  # 合并集合 1 和 2
```

### 检查连接性

```python
uf.connected(1, 2)  # 检查元素 1 和 2 是否在同一集合
```

### 元素计数

```python
count = uf.count()  # 返回集合中元素数量
```

## XmlIO - XML 读写

用于 XML 文件的读取和写入,支持与 ConditionTree 互转。

### 初始化

```python
from pywayne.data_structure import XmlIO

xml_io = XmlIO("input.xml", "output.xml")
```

**参数说明**:

| 参数 | 类型 | 说明 |
|------|------|------|
| `file_read` | str | 待读取的 XML 文件路径 |
| `file_write` | str | 待输出的 XML 文件路径 |

### 读取 XML

```python
tree = xml_io.read()
```

**返回**:解析得到的 `ConditionTree` 对象

### 写入 XML

```python
xml_io.write("root", tree)
```

**参数说明**:

| 参数 | 类型 | 说明 |
|------|------|------|
| `root_name` | str | 根节点名称,将作为 XML 根标签 |

## 应用场景

| 场景 | 使用类 |
|------|------|
| 决策树逻辑 | `ConditionTree` |
| 网络连接管理 | `UnionFind` |
| 配置文件处理 | `XmlIO` |

Versions

The database has no other skills named pywayne-data-structure.

Database snapshot: 13.11.2026 · package version b97bc75ccd92 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100knx-xml-context
    Context loader for KNX XML development. Use when user says "knx context", "load knx", "knx validation", "knx xml rules", or starts working on KNX XML/knxprod files.
  • 95pywayne-cv-tools
    OpenCV YAML file read/write utilities. Use when working with pywayne.cv.tools module to read OpenCV FileStorage YAML files with support for nested structures, numpy arrays, basic types, and lists. Handles cv2.FileNode parsing including Map, Seq, and matrix nodes.
  • 95algorithms-education
    Skills and conventions for an educational algorithms and data structures repository. Use this skill whenever working on algorithm implementations, data structure code, LeetCode-style problems, graph theory, dynamic programming, or any Java-based educational coding project.…
  • 95pywayne-cv-camera-model
    Camera model wrapper for camera_models C++ library via pybind11. Use when working with pywayne.cv.camera_model module to load camera models from YAML configuration files, access camera properties (model type, image size, parameters), perform projection operations…
  • 80role-algorithms:data-structures
    Implements and selects optimal data structures — hash tables (chaining, open addressing, Robin Hood, cuckoo), balanced BSTs (AVL, Red-Black, B-trees), heaps (binary, Fibonacci, pairing), tries, skip lists, segment trees, Fenwick trees, Bloom filters, Count-Min Sketch,…
  • 100graph-algorithms
    Use when working with graph problems including traversal, shortest paths, minimum spanning trees, topological sorting, and connectivity analysis. Covers BFS, DFS, Dijkstra, Bellman-Ford, Floyd-Warshall, Prim, Kruskal, Tarjan, Kosaraju, A*, and Union-Find. Based on Knuth's TAOCP.…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.