How to refer to children in a tree with millions of nodes

后端 未结 1 1976
情书的邮戳
情书的邮戳 2020-12-21 22:26

I\'m attempting to build a tree, where each node can have an unspecified amount of children nodes. The tree is to have over a million nodes in practice.

I\'ve manage

相关标签:
1条回答
  • 2020-12-21 22:43

    How many of your nodes will be "leaf" nodes? Perhaps only create the data structure to store children when you first have a child, otherwise keeping a null reference.

    Unless you need to look up the children as a map, I'd use a List<T> (initialized with an appropriate capacity) instead of a Dictionary<,> for the children. It sounds like you may have more requirements than you've explained though, which makes it hard to say.

    I'm surprised you're failing after only a few thousand nodes though - you should be able to create a pretty large number of objects before having problems.

    I'd also suggest that if you think you'll end up using a lot of memory, make sure you're on a 64-bit machine and make sure your application itself is set to be 64-bit. (That may just be a thin wrapper over a class library, which is fine so long as the class library is set to be 64-bit or AnyCPU.)

    0 讨论(0)
提交回复
热议问题