开发者

What is the time complexity of DataRow indexer?

开发者 https://www.devze.com 2022-12-10 00:33 出处:网络
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 accessing a column by its name in an instance of DataRow?


object Foo(DataRow row, string columnName)
{
    // What is the time complexity of 开发者_JAVA百科the below line O(1) / O(n) / ?
    return row[columnName];
}


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消