【发布时间】:2017-01-28 23:55:00
【问题描述】:
据我所知,对于纯函数序列类型,序列的幼稚实现将导致元素访问的 O(n) 时间复杂度和更好的实现(如 Chris Okasaki 所述)享受 O(log n ) 复杂度,对于长度为 n 的序列。
用operator[] 访问boost::hana::tuple 中的任意元素的时间复杂度是多少?如果以上都不是,那它是如何实现的呢?
【问题讨论】:
-
如果文档 boost::hana 在概念上与
std::tuple相似,则为 O(1) -
我不明白为什么它会是 O(1)(在运行时)。
-
运行时间还是编译时间?
-
文档的图表“转换的运行时行为”(boostorg.github.io/hana/index.html#tutorial-performance) 向我建议 O(1),否则
hana::tuple的图表最终会呈指数级偏离,对吗?我们基本上可以在这里与std::array的复杂性进行比较,我认为......假设transform至少需要N 个op[]s(确实如此!)
标签: c++ functional-programming template-meta-programming random-access boost-hana