General Cellular Automata library and simulation in Rust












-1














I have written a library for cellular automata in Rust, along with a (pretty minimal) program that uses it - all the program does is use a trivial cellular automata I made using this library, which really does nothing - it just leaves the state as the initial state. I put quite a few comments - if more are needed (or if you need the code explained - I wasn't very clear lmao), just ask me. To give you a high - level overview of the library structure - "Grid" is the main struct of the whole library, located inside of the cellular_process module. GridDataType contains the actual data - Grid is just a wrapper of griddatatype with a few additional methods. To move from one grid state to another, a transition function is used - really just the "rule" of the cellular automata. The reason why Grid has 2 "copies" of GridDataType is to avoid timing issues - in the first iteration, the data is written to data_a, and data_b is used as a reference (to read the data from - the state of each cell is determined by it's neighbors. The neighbor's values are read from data_b in the first itreation). In the second iteration, data_a and data_b's roles flop, and it goes on. The rest is explained in the code. TEST.CWD is just a "test" file containing the initial state of the program.



My main problems are:




  • Are certain lifetimes that I'm using actually needed (will they automatically be inferred), and am I even USING lifetimes the right way? Right now, whenever the compiler tells me that I need a lifetime, I just put one (quite randomly...)

  • How can I structure the library differently in a better way (merge / separate modules, change struct structure, etc)?

  • How can I make my code more idiomatic?

  • What performance bottlenecks are present, and how do I fix them? This is a more minor concern (actually, basically nil at this point), but still. Especially within the main loop (the compute_internal function and the apply function in cellular_process::Grid).


My code is here:



https://gitlab.com/ndrewxie/cellular_automata



For those of you unfamiliar with cellular automata (or automation):



https://en.wikipedia.org/wiki/Cellular_automaton



Because code review requires that you put at least 3 lines of code (the code is in the git repo), I'll just do this:



this
is
some
stuff
to
fill
the
3
line
minimum









share|improve this question









New contributor




Andrew Xie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • And yes, I did use workspaces. Cellular_lib is in a workspace, and is the library itself.
    – Andrew Xie
    2 hours ago










  • Yeah, "process virtual machine" is an incorrect description of what it is. I'll change the README and the repo description as soon as I can.
    – Andrew Xie
    2 hours ago










  • The link you provide currently requires us to log into GitLab. Also, please include your code in the question itself -- that is the reason why you need to include at least 3 lines of code.
    – esote
    2 hours ago












  • @esote, I'll fix the link, but there are quite a few files, each one being about 50 LOC (short ones), and longer ones having more. There are seriously lots of files, and a lot of them can't be removed, which is why I gave a gitlab link. It would quickly become a mess to read through with so many files. Hopefully the fixed gitlab link would help (I set the visibility to "public", but forgot to save changes the first time.)
    – Andrew Xie
    1 hour ago


















-1














I have written a library for cellular automata in Rust, along with a (pretty minimal) program that uses it - all the program does is use a trivial cellular automata I made using this library, which really does nothing - it just leaves the state as the initial state. I put quite a few comments - if more are needed (or if you need the code explained - I wasn't very clear lmao), just ask me. To give you a high - level overview of the library structure - "Grid" is the main struct of the whole library, located inside of the cellular_process module. GridDataType contains the actual data - Grid is just a wrapper of griddatatype with a few additional methods. To move from one grid state to another, a transition function is used - really just the "rule" of the cellular automata. The reason why Grid has 2 "copies" of GridDataType is to avoid timing issues - in the first iteration, the data is written to data_a, and data_b is used as a reference (to read the data from - the state of each cell is determined by it's neighbors. The neighbor's values are read from data_b in the first itreation). In the second iteration, data_a and data_b's roles flop, and it goes on. The rest is explained in the code. TEST.CWD is just a "test" file containing the initial state of the program.



My main problems are:




  • Are certain lifetimes that I'm using actually needed (will they automatically be inferred), and am I even USING lifetimes the right way? Right now, whenever the compiler tells me that I need a lifetime, I just put one (quite randomly...)

  • How can I structure the library differently in a better way (merge / separate modules, change struct structure, etc)?

  • How can I make my code more idiomatic?

  • What performance bottlenecks are present, and how do I fix them? This is a more minor concern (actually, basically nil at this point), but still. Especially within the main loop (the compute_internal function and the apply function in cellular_process::Grid).


My code is here:



https://gitlab.com/ndrewxie/cellular_automata



For those of you unfamiliar with cellular automata (or automation):



https://en.wikipedia.org/wiki/Cellular_automaton



Because code review requires that you put at least 3 lines of code (the code is in the git repo), I'll just do this:



this
is
some
stuff
to
fill
the
3
line
minimum









share|improve this question









New contributor




Andrew Xie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • And yes, I did use workspaces. Cellular_lib is in a workspace, and is the library itself.
    – Andrew Xie
    2 hours ago










  • Yeah, "process virtual machine" is an incorrect description of what it is. I'll change the README and the repo description as soon as I can.
    – Andrew Xie
    2 hours ago










  • The link you provide currently requires us to log into GitLab. Also, please include your code in the question itself -- that is the reason why you need to include at least 3 lines of code.
    – esote
    2 hours ago












  • @esote, I'll fix the link, but there are quite a few files, each one being about 50 LOC (short ones), and longer ones having more. There are seriously lots of files, and a lot of them can't be removed, which is why I gave a gitlab link. It would quickly become a mess to read through with so many files. Hopefully the fixed gitlab link would help (I set the visibility to "public", but forgot to save changes the first time.)
    – Andrew Xie
    1 hour ago
















-1












-1








-1







I have written a library for cellular automata in Rust, along with a (pretty minimal) program that uses it - all the program does is use a trivial cellular automata I made using this library, which really does nothing - it just leaves the state as the initial state. I put quite a few comments - if more are needed (or if you need the code explained - I wasn't very clear lmao), just ask me. To give you a high - level overview of the library structure - "Grid" is the main struct of the whole library, located inside of the cellular_process module. GridDataType contains the actual data - Grid is just a wrapper of griddatatype with a few additional methods. To move from one grid state to another, a transition function is used - really just the "rule" of the cellular automata. The reason why Grid has 2 "copies" of GridDataType is to avoid timing issues - in the first iteration, the data is written to data_a, and data_b is used as a reference (to read the data from - the state of each cell is determined by it's neighbors. The neighbor's values are read from data_b in the first itreation). In the second iteration, data_a and data_b's roles flop, and it goes on. The rest is explained in the code. TEST.CWD is just a "test" file containing the initial state of the program.



My main problems are:




  • Are certain lifetimes that I'm using actually needed (will they automatically be inferred), and am I even USING lifetimes the right way? Right now, whenever the compiler tells me that I need a lifetime, I just put one (quite randomly...)

  • How can I structure the library differently in a better way (merge / separate modules, change struct structure, etc)?

  • How can I make my code more idiomatic?

  • What performance bottlenecks are present, and how do I fix them? This is a more minor concern (actually, basically nil at this point), but still. Especially within the main loop (the compute_internal function and the apply function in cellular_process::Grid).


My code is here:



https://gitlab.com/ndrewxie/cellular_automata



For those of you unfamiliar with cellular automata (or automation):



https://en.wikipedia.org/wiki/Cellular_automaton



Because code review requires that you put at least 3 lines of code (the code is in the git repo), I'll just do this:



this
is
some
stuff
to
fill
the
3
line
minimum









share|improve this question









New contributor




Andrew Xie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I have written a library for cellular automata in Rust, along with a (pretty minimal) program that uses it - all the program does is use a trivial cellular automata I made using this library, which really does nothing - it just leaves the state as the initial state. I put quite a few comments - if more are needed (or if you need the code explained - I wasn't very clear lmao), just ask me. To give you a high - level overview of the library structure - "Grid" is the main struct of the whole library, located inside of the cellular_process module. GridDataType contains the actual data - Grid is just a wrapper of griddatatype with a few additional methods. To move from one grid state to another, a transition function is used - really just the "rule" of the cellular automata. The reason why Grid has 2 "copies" of GridDataType is to avoid timing issues - in the first iteration, the data is written to data_a, and data_b is used as a reference (to read the data from - the state of each cell is determined by it's neighbors. The neighbor's values are read from data_b in the first itreation). In the second iteration, data_a and data_b's roles flop, and it goes on. The rest is explained in the code. TEST.CWD is just a "test" file containing the initial state of the program.



My main problems are:




  • Are certain lifetimes that I'm using actually needed (will they automatically be inferred), and am I even USING lifetimes the right way? Right now, whenever the compiler tells me that I need a lifetime, I just put one (quite randomly...)

  • How can I structure the library differently in a better way (merge / separate modules, change struct structure, etc)?

  • How can I make my code more idiomatic?

  • What performance bottlenecks are present, and how do I fix them? This is a more minor concern (actually, basically nil at this point), but still. Especially within the main loop (the compute_internal function and the apply function in cellular_process::Grid).


My code is here:



https://gitlab.com/ndrewxie/cellular_automata



For those of you unfamiliar with cellular automata (or automation):



https://en.wikipedia.org/wiki/Cellular_automaton



Because code review requires that you put at least 3 lines of code (the code is in the git repo), I'll just do this:



this
is
some
stuff
to
fill
the
3
line
minimum






rust cellular-automata






share|improve this question









New contributor




Andrew Xie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Andrew Xie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 1 hour ago





















New contributor




Andrew Xie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 hours ago









Andrew Xie

11




11




New contributor




Andrew Xie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Andrew Xie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Andrew Xie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • And yes, I did use workspaces. Cellular_lib is in a workspace, and is the library itself.
    – Andrew Xie
    2 hours ago










  • Yeah, "process virtual machine" is an incorrect description of what it is. I'll change the README and the repo description as soon as I can.
    – Andrew Xie
    2 hours ago










  • The link you provide currently requires us to log into GitLab. Also, please include your code in the question itself -- that is the reason why you need to include at least 3 lines of code.
    – esote
    2 hours ago












  • @esote, I'll fix the link, but there are quite a few files, each one being about 50 LOC (short ones), and longer ones having more. There are seriously lots of files, and a lot of them can't be removed, which is why I gave a gitlab link. It would quickly become a mess to read through with so many files. Hopefully the fixed gitlab link would help (I set the visibility to "public", but forgot to save changes the first time.)
    – Andrew Xie
    1 hour ago




















  • And yes, I did use workspaces. Cellular_lib is in a workspace, and is the library itself.
    – Andrew Xie
    2 hours ago










  • Yeah, "process virtual machine" is an incorrect description of what it is. I'll change the README and the repo description as soon as I can.
    – Andrew Xie
    2 hours ago










  • The link you provide currently requires us to log into GitLab. Also, please include your code in the question itself -- that is the reason why you need to include at least 3 lines of code.
    – esote
    2 hours ago












  • @esote, I'll fix the link, but there are quite a few files, each one being about 50 LOC (short ones), and longer ones having more. There are seriously lots of files, and a lot of them can't be removed, which is why I gave a gitlab link. It would quickly become a mess to read through with so many files. Hopefully the fixed gitlab link would help (I set the visibility to "public", but forgot to save changes the first time.)
    – Andrew Xie
    1 hour ago


















And yes, I did use workspaces. Cellular_lib is in a workspace, and is the library itself.
– Andrew Xie
2 hours ago




And yes, I did use workspaces. Cellular_lib is in a workspace, and is the library itself.
– Andrew Xie
2 hours ago












Yeah, "process virtual machine" is an incorrect description of what it is. I'll change the README and the repo description as soon as I can.
– Andrew Xie
2 hours ago




Yeah, "process virtual machine" is an incorrect description of what it is. I'll change the README and the repo description as soon as I can.
– Andrew Xie
2 hours ago












The link you provide currently requires us to log into GitLab. Also, please include your code in the question itself -- that is the reason why you need to include at least 3 lines of code.
– esote
2 hours ago






The link you provide currently requires us to log into GitLab. Also, please include your code in the question itself -- that is the reason why you need to include at least 3 lines of code.
– esote
2 hours ago














@esote, I'll fix the link, but there are quite a few files, each one being about 50 LOC (short ones), and longer ones having more. There are seriously lots of files, and a lot of them can't be removed, which is why I gave a gitlab link. It would quickly become a mess to read through with so many files. Hopefully the fixed gitlab link would help (I set the visibility to "public", but forgot to save changes the first time.)
– Andrew Xie
1 hour ago






@esote, I'll fix the link, but there are quite a few files, each one being about 50 LOC (short ones), and longer ones having more. There are seriously lots of files, and a lot of them can't be removed, which is why I gave a gitlab link. It would quickly become a mess to read through with so many files. Hopefully the fixed gitlab link would help (I set the visibility to "public", but forgot to save changes the first time.)
– Andrew Xie
1 hour ago

















active

oldest

votes











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");

StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Andrew Xie is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f210621%2fgeneral-cellular-automata-library-and-simulation-in-rust%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes








Andrew Xie is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















Andrew Xie is a new contributor. Be nice, and check out our Code of Conduct.













Andrew Xie is a new contributor. Be nice, and check out our Code of Conduct.












Andrew Xie is a new contributor. Be nice, and check out our Code of Conduct.
















Thanks for contributing an answer to Code Review Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f210621%2fgeneral-cellular-automata-library-and-simulation-in-rust%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Morgemoulin

Scott Moir

Souastre