@@ -14,9 +14,6 @@ namespace Microsoft.Data.Analysis
14
14
public class DataFrameColumnCollection : Collection < DataFrameColumn >
15
15
{
16
16
private readonly Action ColumnsChanged ;
17
-
18
- private readonly List < string > _columnNames = new List < string > ( ) ;
19
-
20
17
private readonly Dictionary < string , int > _columnNameToIndexDictionary = new Dictionary < string , int > ( StringComparer . Ordinal ) ;
21
18
22
19
internal long RowCount { get ; set ; }
@@ -58,7 +55,6 @@ internal void UpdateColumnNameMetadata(DataFrameColumn column, string newName)
58
55
{
59
56
string currentName = column . Name ;
60
57
int currentIndex = _columnNameToIndexDictionary [ currentName ] ;
61
- _columnNames [ currentIndex ] = newName ;
62
58
_columnNameToIndexDictionary . Remove ( currentName ) ;
63
59
_columnNameToIndexDictionary . Add ( newName , currentIndex ) ;
64
60
ColumnsChanged ? . Invoke ( ) ;
@@ -93,11 +89,10 @@ protected override void InsertItem(int columnIndex, DataFrameColumn column)
93
89
94
90
column . AddOwner ( this ) ;
95
91
96
- _columnNames . Insert ( columnIndex , column . Name ) ;
97
92
_columnNameToIndexDictionary [ column . Name ] = columnIndex ;
98
93
for ( int i = columnIndex + 1 ; i < Count ; i ++ )
99
94
{
100
- _columnNameToIndexDictionary [ _columnNames [ i ] ] ++ ;
95
+ _columnNameToIndexDictionary [ this [ i ] . Name ] ++ ;
101
96
}
102
97
base . InsertItem ( columnIndex , column ) ;
103
98
ColumnsChanged ? . Invoke ( ) ;
@@ -115,9 +110,7 @@ protected override void SetItem(int columnIndex, DataFrameColumn column)
115
110
{
116
111
throw new ArgumentException ( string . Format ( Strings . DuplicateColumnName , column . Name ) , nameof ( column ) ) ;
117
112
}
118
-
119
- _columnNameToIndexDictionary . Remove ( _columnNames [ columnIndex ] ) ;
120
- _columnNames [ columnIndex ] = column . Name ;
113
+ _columnNameToIndexDictionary . Remove ( this [ columnIndex ] . Name ) ;
121
114
_columnNameToIndexDictionary [ column . Name ] = columnIndex ;
122
115
123
116
this [ columnIndex ] . RemoveOwner ( this ) ;
@@ -128,12 +121,11 @@ protected override void SetItem(int columnIndex, DataFrameColumn column)
128
121
129
122
protected override void RemoveItem ( int columnIndex )
130
123
{
131
- _columnNameToIndexDictionary . Remove ( _columnNames [ columnIndex ] ) ;
124
+ _columnNameToIndexDictionary . Remove ( this [ columnIndex ] . Name ) ;
132
125
for ( int i = columnIndex + 1 ; i < Count ; i ++ )
133
126
{
134
- _columnNameToIndexDictionary [ _columnNames [ i ] ] -- ;
127
+ _columnNameToIndexDictionary [ this [ i ] . Name ] -- ;
135
128
}
136
- _columnNames . RemoveAt ( columnIndex ) ;
137
129
138
130
this [ columnIndex ] . RemoveOwner ( this ) ;
139
131
base . RemoveItem ( columnIndex ) ;
@@ -171,7 +163,6 @@ protected override void ClearItems()
171
163
{
172
164
base . ClearItems ( ) ;
173
165
ColumnsChanged ? . Invoke ( ) ;
174
- _columnNames . Clear ( ) ;
175
166
_columnNameToIndexDictionary . Clear ( ) ;
176
167
177
168
//reset RowCount as DataFrame is now empty
0 commit comments