https://github.com/tobychui/smartsort
A smart sorting algorithm for Go to sort filename containing digits that is not zero padded
https://github.com/tobychui/smartsort
Last synced: 2 months ago
JSON representation
A smart sorting algorithm for Go to sort filename containing digits that is not zero padded
- Host: GitHub
- URL: https://github.com/tobychui/smartsort
- Owner: tobychui
- License: mit
- Created: 2022-01-31T13:03:29.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-01-31T14:52:59.000Z (over 4 years ago)
- Last Synced: 2025-12-26T16:44:32.818Z (6 months ago)
- Language: Go
- Size: 2.93 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# smartsort
A smart sorting algorithm for Go to sort filename containing digits that is not zero padded
## Usage
```
import "github.com/tobychui/smartsort/sorter"
sortedSlice := sorter.SortString(stringSlice)
```
## Examples
```
original := []string{"a1c.o", "A1c.o", "a2016c.o", "a10c.o", "a2c.o", "A2c.o", "a11c.o"}
fmt.Println("Before: ", original)
results := sorter.SortString(original)
fmt.Println("After: ", results)
```
#### Outputs
```
Before: [a1c.o A1c.o a2016c.o a10c.o a2c.o A2c.o a11c.o]
After: [A1c.o A2c.o a1c.o a2c.o a10c.o a11c.o a2016c.o]
```
### Notes
This is a space-time tradeoff version (this use more memory) of the algorithm used by natsort. Take a look at natsort if you have many CPU resources but no memory: https://github.com/facette/natsort