SortM - Roblox Sorting Module

SortM is a open-sourced module for sorting arrays (tables) in ROBLOX.

Hello, I am Oliver (or undiscvrd). I am a scripter here on ROBLOX, and while working on a script I found myself creating a extremely slow sorting algorithm. So, I decided to quickly make this module for easy sorting of tables/arrays.

I’ve only implemented 5 sorting algorithms, but I am open to adding more just request in the replies.

How to use the module?

To use the module you just simply import it using require require(Path.To.SortM) then access the Sort function.

local SortM = require(game:GetService("ReplicatedStorage").SortM)
local Array = {5,4,3,2,1}
local newArray = SortM.Sort(Array, "QuickSort")

print(tostring(newArray))

What sorting algorithms are there?

  • Quick Sort (QuickSort)
  • Insertion Sort (InsertionSort)
  • Selection Sort (SelectionSort)
  • Bubble Sort (BubbleSort)
  • Merge Sort (mergeSort)

What functions are included?

  • SortM.VerifyArray
  • SortM.Sort
  • SortM.AlgorithmList (Dictionary[Name:Function])

Github
Download

Hopefully it works well for yall, you like it. If you want to request something, or have an issue just send a reply down below. Also if I forgot to include something, feel free to tell me and I’ll include it.

Yours Truly,
undiscvrd

1 Like

I would like to inform you that table.sort exists for this very purpose.

1 Like

im so done :sob: welp, its there if anyone wants it.

I don’t know what sorting algorithm table.sort uses, but different algorithms can probably be of some use to some developers. That would probably be in some situations where you are dealing with gigantic tables and want something that is performant I guess

This is a nice way to improve coding skills but practically… lolmansReturn says it. table.sort() exists, its quite performant and overall quite beginner friendly

2 Likes

There is the comp function which does the job (unless i’m mistaken)

this code snippet is for you

local ello = workspace:GetChildren()

table.sort(ello, function(alpha, beta)
	return alpha < beta
end)

I have yet to see a Roblox sorting algorithm that’s faster than the native table.sort().

2 Likes

I am aware of that functionality, what I meant was using a sorting function that works differently for more performance

Radix sort would be my guess, I thought table.sort() used a “linear sorting algorithm”, but I cannot find that information on the docs (where I thought I saw it)

table.sort exists…

local t = workspace:GetChildren()

table.sort(t, function(a, b)
    return #a.Name > #b.Name
end)

print(t)

image

still, I think some people might prefer to use your module over table.sort because of its algorithms and how easy to use it is

2 Likes