Skip to content

Commit 086c183

Browse files
authored
Merge pull request #7 from Alokzh/fix-core-implementation
Improve Stack Implementation by making it Array based & adding missing methods with proper Tests
2 parents 25847da + 79d33e5 commit 086c183

File tree

10 files changed

+505
-296
lines changed

10 files changed

+505
-296
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-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/currentStablePharo.yml

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

.github/workflows/matrix.yml

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

README.md

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
11
# Containers-Stack
2-
A dead stupid stack implementation, but one fully working with super cool coverage:)
3-
4-
5-
![https://github.com/pharo-containers/Containers-Stack/actions](https://github.com/pharo-containers/Containers-Stack/workflows/Matrix/badge.svg)
6-
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://img.shields.io/badge/license-MIT-blue.svg)
7-
[![Coverage Status](https://coveralls.io/repos/github/pharo-containers/Containers-Stack/badge.svg?branch=master)](https://coveralls.io/github/pharo-containers/Containers-Stack?branch=master)
8-
## Example
9-
10-
```
11-
| aStack |
12-
aStack := CTStack new.
13-
aStack push: 'a'.
14-
aStack size >>> 1.
15-
aStack push: 'b'.
16-
aStack size >>> 2.
17-
aStack top >>> 'b'.
18-
aStack size >>> 2.
19-
aStack pop >>> 'b'.
20-
aStack size >>> 1.
21-
aStack pop >>> 'a'.
22-
aStack size >>> 0.
23-
```
2+
A High-performance, Array based Stack implementation providing efficient LIFO (Last In, First Out) operations with fixed capacity and proper bounds checking.
3+
4+
![Pharo Version](https://img.shields.io/badge/Pharo-10+-blue)
5+
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
6+
7+
## What is a Stack?
8+
9+
A Stack is a linear data structure that follows the LIFO (Last In, First Out) principle. Elements are added and removed from the same end, called the "top" of the stack. Think of it like a stack of plates - you can only add or remove plates from the top.
10+
11+
### Key Benefits
12+
- **O(1) Performance**: Constant time push, pop, and top operations
13+
- **Fixed Memory Usage**: Array-based implementation with bounded capacity
14+
- **Memory Safe**: Automatic cleanup prevents memory leaks
15+
- **Simple API**: Clean, intuitive interface following standard conventions
16+
- **Robust Error Handling**: Proper stack overflow and underflow protection
2417

2518
## Loading
2619
The following script installs Containers-Stack in Pharo.
2720

2821
```smalltalk
2922
Metacello new
3023
baseline: 'ContainersStack';
31-
repository: 'github://pharo-containers/Containers-Stack:v1.0/src';
24+
repository: 'github://pharo-containers/Containers-Stack/src';
3225
load.
3326
```
3427

@@ -39,5 +32,33 @@ Add the following code to your Metacello baseline or configuration
3932
```smalltalk
4033
spec
4134
baseline: 'ContainersStack'
42-
with: [ spec repository: 'github://pharo-containers/Containers-Stack:v1.0/src' ].
35+
with: [ spec repository: 'github://pharo-containers/Containers-Stack/src' ].
36+
```
37+
38+
## Quick Start
39+
40+
```smalltalk
41+
"Create a stack with capacity of 5"
42+
stack := CTStack new: 5.
43+
44+
"Push elements"
45+
stack push: 'first'.
46+
stack push: 'second'.
47+
stack push: 'third'.
48+
49+
"Check top element without removing"
50+
stack top. "Returns 'third'"
51+
stack size. "Returns 3"
52+
53+
"Pop elements (LIFO order)"
54+
stack pop. "Returns 'third'"
55+
stack pop. "Returns 'second'"
56+
stack pop. "Returns 'first'"
57+
58+
"Stack is now empty"
59+
stack isEmpty. "Returns true"
4360
```
61+
62+
## Contributing
63+
64+
This is part of the Pharo Containers project. Feel free to contribute by implementing additional methods, improving tests, or enhancing documentation.

src/BaselineOfContainersStack/BaselineOfContainersStack.class.st

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
Class {
2-
#name : #BaselineOfContainersStack,
3-
#superclass : #BaselineOf,
4-
#category : #BaselineOfContainersStack
2+
#name : 'BaselineOfContainersStack',
3+
#superclass : 'BaselineOf',
4+
#category : 'BaselineOfContainersStack',
5+
#package : 'BaselineOfContainersStack'
56
}
67

7-
{ #category : #baseline }
8+
{ #category : 'baselines' }
89
BaselineOfContainersStack >> baseline: spec [
910
<baseline>
1011

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Package { #name : #BaselineOfContainersStack }
1+
Package { #name : 'BaselineOfContainersStack' }

0 commit comments

Comments
 (0)