|
![](/i/fill.gif) |
Warp wrote:
> Orchid XP v8 <voi### [at] dev null> wrote:
>> Oh, er... can you have a vector of vectors? Or would it have to be a
>> vector of vector pointers?
>
> It's perfectly possible.
OK. I just wasn't sure if it's permissible for the element type to be of
variable size, that's all.
> When you start having nested data containers, it may be useful to abstract
> a bit.
Agreed.
> Of course there's no limit on how many containers you can nest.
> Managing all this in your head might become a bit complicated, though. :)
Hence the abstraction. ;-)
Presumably I'm going to do something like define a struct that holds all
the data I need about each symbol (what the symbol is, its probability,
its current codeword, etc), and then define a typedef for a vector of
symbol info structs. Then it'll be quite clear that vector<tree> is a
vector of Huffman trees.
> For example, if you want a vector of huffman trees, it would be a bad
> idea to try to manage them directly. Instead, it's a much better idea to
> abstract the whole huffman tree concept, and then use that as the element
> of the outermost vector. In other words, something like:
>
> class HuffmanTree
> {
> public:
> // A nice and easy-to-use interface here
>
> private:
> typedef std::vector<int> IntCont;
> std::vector<IntCont> theTree; // Or whatever
>
> // Other possible private members
> };
>
> Now you can do this:
>
> std::vector<HuffmanTree> trees; // A vector of huffman trees
>
> So here you have three levels of nesting of vectors, but they are so
> well abstracted that it's easily manageable. In the outermost layer you
> only see the HuffmanTree class and its simple public interface.
...or I could do that, yes. That would provide an obvious place to put
the "tree merge" functionallity, as well as symbol lookup, etc.
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
![](/i/fill.gif) |