{"id":"yumacide/array3d","name":"array3d","scope":"yumacide","platform":"roblox","description":"A flat 3D array implementation","version":"1.0.1","latest":"1.0.1","versions":["1.0.1"],"license":"MIT","licenseRating":"safe","licenseCaveats":["License identified from the packaged LICENSE file; the manifest declared none."],"licenseVerified":true,"dependencies":{},"integrity":"bce1e49717e9af563f84575c91e75a6e99aadd1f6f25ad9cc22f1ffade458327","likes":0,"downloads":0,"install":"forest install yumacide/array3d","url":"https://forest.dev/p/roblox/yumacide/array3d","files":"https://api.forest.dev/ai/package/roblox/yumacide/array3d/files","readme":"# Array3D\r\n\r\nA flat 3D array implementation\r\n\r\n## Usage\r\n\r\n```lua\r\nlocal Array3D = require(path.to.Array3D)\r\n\r\nlocal grid = Array3D.new(10, 10, 10, \"Hello, world!\") -- Create a 10x10x10 3D array and fill it\r\nprint(grid:Get(1, 2, 3)) -- Hello, world!\r\ngrid:Set(4, 5, 6, \"Goodbye, world.\")\r\n```\r\n\r\n## Performance\r\n\r\n#### Iterating through a 50x50x50 array and incrementing every value by 1 (native mode):\r\n\r\n-   Flat array: 0.3248ms (3079/s)\r\n-   Nested array: 2.0054ms (499/s)\r\n\r\nThis is an 84% difference in speed!\r\n\r\nThe `Get` and `Set` methods are marginally slower than `array[x][y][z]` in a nested array, but this is due to the overhead of calling the method, checking if the index is in bounds, and indexing the object's `XMax` and `YMax` properties.\r\n\r\nThis library is basically 5 lines of math and some sugar, so you can implement `Array3D:To1D(x, y, z)` as a local function with no checks instead:\r\n\r\n```lua\r\nlocal function to1D(x: number, y: number, z: number, xMax: number, yMax: number)\r\n    return ((z - 1) * xMax * yMax) + ((y - 1) * xMax) + x\r\nend\r\n\r\nprint(flatArray[to1D(1, 2, 3, 10, 10)])\r\n```\r\n\r\nAnd it becomes 20% faster than indexing a nested array! This is trivial, however, and the main benefit of using a flat array is being able to iterate through it faster.\r\n","readmeTruncated":false}