游戏开发论坛

 找回密码
 立即注册
搜索
查看: 4233|回复: 8

关于STL的map效率问题

[复制链接]

11

主题

53

帖子

55

积分

注册会员

Rank: 2

积分
55
发表于 2009-11-3 10:59:00 | 显示全部楼层 |阅读模式
一个map<string,Element*>  tepMap;
tepMap["name"]访问速度快和我们自己遍历map哪个快?map自身会调用查找方法呢?

11

主题

650

帖子

651

积分

高级会员

Rank: 4

积分
651
发表于 2009-11-3 11:04:00 | 显示全部楼层

Re:关于STL的map效率问题

find成员函数最快。。。effective stl好像写了
但好像find 和operator []实现是一样的

119

主题

1367

帖子

1393

积分

金牌会员

Rank: 6Rank: 6

积分
1393
发表于 2009-11-3 12:44:00 | 显示全部楼层

Re:关于STL的map效率问题

不论什么容器,特别是有序集合,查找某元素不是迫不得已,不要用遍历

3

主题

17

帖子

17

积分

新手上路

Rank: 1

积分
17
发表于 2009-11-4 13:13:00 | 显示全部楼层

Re: 关于STL的map效率问题

  • Linux ebook free download
  • Hardening Linux ebook free download
  • Linux Cookbook ebook free download
  • Linux on the Mainframe ebook free download
  • Linux Unwired  ebook free download
  • Linux: Phrasebook  ebook free download
  • Inside Linux ebook free download
  • Practical Linux ebook free download
  • Suse Linux ebook free download
  • Fedora Linux ebook free download
  • Linux Clustering: Building and Maintaining Linux Clusters ebook free download
  • Linux Kernel in a Nutshell ebook free download
  • Linux Server Hacks ebook free download
  • Linux Power Tools ebook free download
  • Understanding the Linux Kernel ebook free download
  • Linux Security Cookbook ebook free download
  • Advanced Linux Networking ebook free download
  • Advanced Linux Programming ebook free download
  • User Mode Linux ebook free download
  • Linux For Programmers And Users ebook free download
  • Linux Enterprise Cluster ebook free download
  • Professional Linux Programming ebook free download
  • Managing RAID on Linux ebook free download
  • Linux System Programming ebook free download
  • Linux System Administration ebook free download
  • Integrating Linux and Windows ebook free download
  • Troubleshooting Linux Firewalls ebook free download
  • Linux Network Servers ebook free download
  • Linux Programming Bible ebook free download
  • Java Programming on Linux ebook free download
  • Linux Programming Unleashed ebook free download
  • Linux Socket Programming ebook free download
  • Moving from Windows to Linux ebook free download
  • Linux Desktop Hacks ebook free download
  • Hardening Linux (2005) ebook free download
  • Linux+ Certification Bible ebook free download
  • Hacker Linux Uncovered ebook free download
  • Linux Troubleshooting Bible ebook free download
  • Linux Desktop Garage ebook free download
  • 23

    主题

    515

    帖子

    552

    积分

    高级会员

    Rank: 4

    积分
    552
    发表于 2009-11-4 21:26:00 | 显示全部楼层

    Re:关于STL的map效率问题

    当然是find快了,那是二分查找,复杂度为:log2N
    自己遍历复杂度为N


    3

    主题

    101

    帖子

    101

    积分

    注册会员

    Rank: 2

    积分
    101
    发表于 2009-11-6 10:55:00 | 显示全部楼层

    Re:关于STL的map效率问题

    如果已经排序了,2分要快,但是,如果没有排序.........

    3

    主题

    17

    帖子

    17

    积分

    新手上路

    Rank: 1

    积分
    17
    发表于 2009-11-6 13:02:00 | 显示全部楼层

    Re: 关于STL的map效率问题

    3

    主题

    112

    帖子

    112

    积分

    注册会员

    Rank: 2

    积分
    112
    发表于 2009-11-6 13:03:00 | 显示全部楼层

    Re:关于STL的map效率问题

    建议把string的hash作为map的键.

    23

    主题

    515

    帖子

    552

    积分

    高级会员

    Rank: 4

    积分
    552
    发表于 2009-11-6 21:50:00 | 显示全部楼层

    Re: Re:关于STL的map效率问题

    luoqi: Re:关于STL的map效率问题

    如果已经排序了,2分要快,但是,如果没有排序.........


    老大!map 在插入的时候就已经排序了。
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

    GMT+8, 2025-6-18 04:42

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表