DataRow 索引器的时间复杂度是多少?
在 DataRow 实例中按名称访问列的时间复杂度是多少?
object Foo(DataRow row, string columnName)
{
// What is the time complexity of the below line O(1) / O(n) / ?
return row[columnName];
}
What is the time complexity of accessing a column by its name in an instance of DataRow?
object Foo(DataRow row, string columnName)
{
// What is the time complexity of the below line O(1) / O(n) / ?
return row[columnName];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我查看了 Reflector 并可以确认相关代码的时间复杂度为O(1)。实际数据使用按记录号索引的普通旧数组存储在 DataColumn 实例中...每列一个数组。 DataColumn 通过 Hashtable 从名称中获取,记录号直接从 DataRow 实例中获取。所以你有一个哈希表查找和一个数组查找,两者的复杂度都是 O(1)。
I took a peek with Reflector and can confirm that the code in question has a time complexity of O(1). The actual data is stored in DataColumn instances using a plain old array indexed by record number...one array per column. The DataColumn is obtained from the name via a Hashtable and the record number is obtained directly from the DataRow instance. So you have a hash table lookup and an array lookup both of which are O(1).