内存中的多图表示 [英] multimap representation in memory

查看:30
本文介绍了内存中的多图表示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调试我的代码,有一次我有一个多重映射,其中包含成对的 long 和一个 Note 对象 像这样创建:

I'm debugging my code and at one point I have a multimap which contains pairs of a long and a Note object created like this:

void Track::addNote(Note &note) {
    long key = note.measureNumber * 1000000 + note.startTime;
    this->noteList.insert(make_pair(key, note));
}

我想看看这些值是否真的插入到多映射中,所以我放置了一个断点,这就是多映射的样子(在 Xcode 中):

I wanted to look if these values are actually inserted in the multi map so I placed a breakpoint and this is what the multimap looks like (in Xcode):

似乎我可以无限地打开元素(我的实际多图是第一个名为 noteList 的元素)任何想法是否正常以及为什么我无法读取实际对值(长和注释)?

It seems like I can infinitely open the elements (my actual multimap is the first element called noteList) Any ideas if this is normal and why I can't read the actual pair values (the long and the Note)?

推荐答案

libstdc++ 使用通用的红/黑树来实现它的映射和集合.树的节点使用基类_Rb_tree_node_base,它包含指向父/左/右节点相同类型的指针.

libstdc++ implements it's maps and sets using a generic Red/Black tree. The nodes of the tree use a base class _Rb_tree_node_base which contain pointers to the same types for the parent/left/right nodes.

为了访问数据,它对特定于您提供的模板参数的节点类型执行静态转换.除非您可以强制转换,否则您将无法使用 XCode 查看数据.

To access the data, it performs a static cast to the node type that's specific to the template arguments you provided. You won't be able to see the data using XCode unless you can force the cast.

它与链表类似,具有链表节点基.

It does something similar with linked lists, with a linked list node base.

这样做是为了删除模板生成的大量重复代码.而不是有 RbTreeRbTree 等等;libstdc++ 有一组适用于基类的操作,无论映射的底层类型如何,这些操作都是相同的.它仅在需要检查数据时进行转换,并且所有树的实际旋转/重新平衡代码都相同.

It does this to remove the amount of duplicate code that is generated by the template. Rather than have a RbTree<Type1>, RbTree<Type2>, and so on; libstdc++ has a single set of operations that work on the base class, and those operations are the same regardless of the underlying type of the map. It only casts when it needs to examine the data, and the actual rotation/rebalance code is the same for all of the trees.

这篇关于内存中的多图表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆