Need some help on where to begin

agolangf · · 446 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>So I was given the task of putting about 200k files into a tree of nested folders. Basically there will be a folder with 100 folders in it with each folder also having 100 folders each. So the tree would have a height of about 4. Iv looked at the go documentation for the mkdir and mkdirall functions but I&#39;m still not sure where to go with that. I&#39;m not asking for the code to achieve this, just some guidance on where I should begin or what kind of concepts to research more. </p> <p>Thanks</p> <hr/>**评论:**<br/><br/>kris-nova: <pre><p>What is the end goal here? I don&#39;t understand what we need to do with all these folders. It sounds like we need to create them. If so you could make a recursive tree walker that would create a directory at each node. </p> <p>It would be helpful if we knew the context and any restraints here. Do you need to do this once? Once a second? </p> <p>Do you need to do this based on some sort of naming convention? If so do we know the names and how they fit together?</p></pre>lroe: <pre><p>Well I wasn&#39;t given much, all that I was told was to make the tree of folders then place the files in the folders of the bottom row of nodes. I&#39;ll look into the recursive tree walker, thank you. I just have one question, how would I make each node have 100 children? Do I just have 100 pointers in my tree struct?</p></pre>kris-nova: <pre><p>I prefer to use a tree where each node has a list of children. Some people might argue a tree composed of linked lists might be better, or at least make for a better academic exercise. </p> <p>Here is an example of a tree composed of nodes, each with a list of children, and how to walk through it. <a href="https://play.golang.org/p/r2N1V2FvOZ" rel="nofollow">https://play.golang.org/p/r2N1V2FvOZ</a></p> <p>Also for reference here is the source code to an article I wrote a while back. The article is gone, but I think the source is still valuable. Note in this example the tree is processed concurrently so that might be a little bit more involved then what you are going for. <a href="https://github.com/Nivenly/nivenly.com/blob/master/examples/go/concurrent_digraph_processing.go" rel="nofollow">https://github.com/Nivenly/nivenly.com/blob/master/examples/go/concurrent_digraph_processing.go</a></p> <p>Does this help?</p></pre>lroe: <pre><p>Yeah that helps a lot, thank you very much :)</p></pre>kris-nova: <pre><p>Glad it helped. It was a good exercise, I went ahead and dropped the source code off here in a write up. I know it&#39;s not exactly what you are looking for, but it&#39;s a good tree demo. <a href="https://www.nivenly.com/single-rooted-tree-in-go/" rel="nofollow">https://www.nivenly.com/single-rooted-tree-in-go/</a></p></pre>fhjfgfhfhfhftyjfghft: <pre><p>I&#39;d argue a linked list is a tree, and that linking trees in a certain way(linearly) produces a linked list.</p></pre>kris-nova: <pre><p>I think semantically that&#39;s 100% correct. I just usually think of a linked list as having a &#34;next&#34; instead of a &#34;parent&#34; or &#34;child&#34;. So it&#39;s really just the way I am thinking about it. Also aren&#39;t linked lists typically a single node connecting to another single node? A tree would then be a case where a single node can connect to N other nodes.</p></pre>fhjfgfhfhfhftyjfghft: <pre><p>Trees are complex. Trees in this context would be <a href="https://en.wikipedia.org/wiki/Tree_(data_structure)" rel="nofollow">https://en.wikipedia.org/wiki/Tree_(data_structure)</a>. Linked lists have a degree of one.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

446 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传