Skip to content

Commit e1e4aa4

Browse files
authored
Merge pull request #8 from Alokzh/Improve-KeyedTree-Implementation
Improve CTKeyedTree Implementation, Tests, Workflows & Readme
2 parents bf2719d + e69dc3b commit e1e4aa4

File tree

10 files changed

+1066
-363
lines changed

10 files changed

+1066
-363
lines changed

.github/workflows/CI.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: CI
2+
3+
env:
4+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5+
6+
on:
7+
push:
8+
branches: [master]
9+
pull_request:
10+
branches: [master]
11+
workflow_dispatch:
12+
13+
jobs:
14+
build:
15+
strategy:
16+
matrix:
17+
os: [macos-latest, ubuntu-latest, windows-latest]
18+
smalltalk: [Pharo64-14, Pharo64-13, Pharo64-12, Pharo64-11, Pharo64-10]
19+
20+
runs-on: ${{ matrix.os }}
21+
name: ${{ matrix.smalltalk }} on ${{ matrix.os }}
22+
23+
steps:
24+
- uses: actions/checkout@v3
25+
- name: Setup SmalltalkCI
26+
uses: hpi-swa/setup-smalltalkCI@v1
27+
with:
28+
smalltalk-version: ${{ matrix.smalltalk }}
29+
- name: Load and Test
30+
run: smalltalkci -s ${{ matrix.smalltalk }}
31+
shell: bash
32+
timeout-minutes: 15

.github/workflows/matrix.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

.travis.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

README.md

Lines changed: 95 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,110 @@
11
# Containers-KeyedTree
2-
An implementation of KeyedTree
2+
A hierarchical data structure that provides path-based access to nested elements with dictionary-like functionality. Perfect for configuration management, file system structures & hierarchical data organization.
33

4-
[![Build Status](https://travis-ci.com/Ducasse/Containers-KeyedTree.svg?branch=master)](https://travis-ci.com/Ducasse/Containers-KeyedTree)
5-
[![Coverage Status](https://coveralls.io/repos/github//Ducasse/Containers-KeyedTree/badge.svg?branch=master)](https://coveralls.io/github//Ducasse/Containers-KeyedTree?branch=master)
6-
[![License](https://img.shields.io/badge/license-MIT-blue.svg)]()
7-
[![Pharo version](https://img.shields.io/badge/Pharo-7.0-%23aac9ff.svg)](https://pharo.org/download)
8-
[![Pharo version](https://img.shields.io/badge/Pharo-8.0-%23aac9ff.svg)](https://pharo.org/download)
9-
<!-- [![Build status](https://ci.appveyor.com/api/projects/status/1wdnjvmlxfbml8qo?svg=true)](https://ci.appveyor.com/project/olekscode/dataframe) -->
4+
![Pharo Version](https://img.shields.io/badge/Pharo-10+-blue)
5+
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
106

7+
## What is a KeyedTree?
8+
A KeyedTree is a specialized dictionary that allows nested structures where values can be accessed through path-based keys. Each node can contain both direct values and subtrees, enabling hierarchical data organization similar to file systems or nested configurations.
119

10+
## Loading
11+
The following script installs Containers-KeyedTree in Pharo.
1212

13-
## Example
14-
To have an overview of the features this datastructure provide, have a look at the following code snippet (extracted from a unit test):
13+
```smalltalk
14+
Metacello new
15+
baseline: 'ContainersKeyedTree';
16+
repository: 'github://pharo-containers/Containers-KeyedTree/src';
17+
load.
18+
```
1519

16-
```st
17-
firstLevelOneSubTree := CTKeyedTree new.
18-
firstLevelOneSubTree
19-
at: #two put: 'One-Two';
20-
at: #three put: 'One-Three'.
21-
22-
tree := CTKeyedTree new.
23-
tree
24-
at: 1 put: firstLevelOneSubTree;
25-
at: 2 put: 'Two'.
26-
27-
self assert: (tree atPath: #(1)) equals: firstLevelOneSubTree.
28-
self assert: (tree atPath: #(1 two)) equals: 'One-Two'.
29-
self assert: (tree atPath: #(1 three)) equals: 'One-Three'.
30-
self assert: (tree atPath: #(2)) equals: 'Two'.
31-
self should: [ tree atPath: #(2 4) ] raise: self defaultTestError.
32-
self should: [ tree atPath: #(1 two three) ] raise: self defaultTestError.
33-
self should: [ tree atPath: #(3) ] raise: self defaultTestError
20+
## If you want to depend on it
21+
Add the following code to your Metacello baseline or configuration:
22+
23+
```smalltalk
24+
spec
25+
baseline: 'ContainersKeyedTree'
26+
with: [ spec repository: 'github://pharo-containers/Containers-KeyedTree/src' ].
3427
```
3528

36-
## Loading
29+
## Why use Containers-KeyedTree?
3730

38-
The following script installs Containers-Stack in Pharo.
31+
KeyedTrees solve the problem of **organizing hierarchical data with efficient path-based access**. Perfect for configuration files, menu systems, and any data that naturally forms a tree structure.
3932

40-
```st
41-
Metacello new
42-
baseline: 'ContainersKeyedTree';
43-
repository: 'github://pharo-containers/Containers-KeyedTree:v1.0/src';
44-
load.
45-
```
33+
### Key Benefits
34+
- **Hierarchical Organization**: Natural tree structure for nested data
35+
- **Path-based Access**: Access deep elements with simple path arrays
36+
- **Flexible Values**: Store any object type at any level
37+
- **Merge Capability**: Combine trees intelligently
38+
- **Dictionary Compatibility**: Inherits from Dictionary for familiar API
39+
40+
## Basic Usage
41+
42+
```smalltalk
43+
"Create a hierarchical structure"
44+
tree := CTKeyedTree new.
4645
47-
## If you want to depend on it
46+
"Add simple values"
47+
tree at: #name put: 'MyApp'.
48+
tree at: #version put: '1.0.0'.
4849
49-
Add the following code to your Metacello baseline or configuration
50+
"Create nested structures"
51+
config := CTKeyedTree new.
52+
config at: #host put: 'localhost'.
53+
config at: #port put: 8080.
54+
tree at: #server put: config.
5055
56+
"Access with paths"
57+
tree atPath: #(server host). "=> 'localhost'"
58+
tree atPath: #(server port). "=> 8080"
59+
tree atPath: #(version). "=> '1.0.0'"
5160
```
52-
spec
53-
baseline: 'ContainersKeyedTree'
54-
with: [ spec repository: 'github://pharo-containers/Containers-KeyedTree:v1.0/src' ]
61+
62+
## Real-World Use Cases
63+
64+
```smalltalk
65+
"Build a hierarchical menu structure for GUI Applications"
66+
mainMenu := CTKeyedTree new.
67+
68+
"File menu"
69+
fileMenu := CTKeyedTree new
70+
at: #new put: 'Create New Document';
71+
at: #open put: 'Open Document';
72+
at: #recent put: (CTKeyedTree new
73+
at: #doc1 put: '/path/to/recent1.txt';
74+
at: #doc2 put: '/path/to/recent2.txt';
75+
yourself);
76+
at: #save put: 'Save Document';
77+
at: #exit put: 'Exit Application';
78+
yourself.
79+
80+
"Edit menu"
81+
editMenu := CTKeyedTree new
82+
at: #undo put: 'Undo Last Action';
83+
at: #redo put: 'Redo Last Action';
84+
at: #copy put: 'Copy Selection';
85+
at: #paste put: 'Paste Content';
86+
yourself.
87+
88+
"Tools menu with nested submenus"
89+
toolsMenu := CTKeyedTree new
90+
at: #preferences put: (CTKeyedTree new
91+
at: #general put: 'General Settings';
92+
at: #appearance put: 'Theme & UI';
93+
at: #shortcuts put: 'Keyboard Shortcuts';
94+
yourself);
95+
at: #plugins put: 'Manage Plugins';
96+
yourself.
97+
98+
mainMenu
99+
at: #file put: fileMenu;
100+
at: #edit put: editMenu;
101+
at: #tools put: toolsMenu.
102+
103+
"Access menu items by path"
104+
newAction := mainMenu atPath: #(file new). "=> 'Create New Document'"
105+
recentDoc := mainMenu atPath: #(file recent doc1). "=> '/path/to/recent1.txt'"
106+
themeSettings := mainMenu atPath: #(tools preferences appearance). "=> 'Theme & UI'"
55107
```
108+
109+
## Contributing
110+
This is part of the Pharo Containers project. Feel free to contribute by implementing additional methods, improving tests, or enhancing documentation.
Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
Class {
2-
#name : #BaselineOfContainersKeyedTree,
3-
#superclass : #BaselineOf,
4-
#category : #BaselineOfContainersKeyedTree
2+
#name : 'BaselineOfContainersKeyedTree',
3+
#superclass : 'BaselineOf',
4+
#category : 'BaselineOfContainersKeyedTree',
5+
#package : 'BaselineOfContainersKeyedTree'
56
}
67

7-
{ #category : #baselines }
8+
{ #category : 'baselines' }
89
BaselineOfContainersKeyedTree >> baseline: spec [
10+
911
<baseline>
10-
spec for: #pharo do: [
11-
spec package: 'Containers-KeyedTree'.
12-
spec package: 'Containers-KeyedTree-Tests' with: [ spec requires: #('Containers-KeyedTree') ]
13-
]
14-
]
12+
spec for: #common do: [
13+
spec package: 'Containers-KeyedTree'.
14+
spec
15+
package: 'Containers-KeyedTree-Tests'
16+
with: [ spec requires: #( 'Containers-KeyedTree' ) ] ]
17+
]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Package { #name : #BaselineOfContainersKeyedTree }
1+
Package { #name : 'BaselineOfContainersKeyedTree' }

0 commit comments

Comments
 (0)