@@ -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 ; }
@@ -46,7 +43,6 @@ public void SetColumnName(DataFrameColumn column, string newName)
46
43
string currentName = column . Name ;
47
44
int currentIndex = _columnNameToIndexDictionary [ currentName ] ;
48
45
column . SetName ( newName ) ;
49
- _columnNames [ currentIndex ] = newName ;
50
46
_columnNameToIndexDictionary . Remove ( currentName ) ;
51
47
_columnNameToIndexDictionary . Add ( newName , currentIndex ) ;
52
48
ColumnsChanged ? . Invoke ( ) ;
@@ -77,11 +73,10 @@ protected override void InsertItem(int columnIndex, DataFrameColumn column)
77
73
throw new ArgumentException ( string . Format ( Strings . DuplicateColumnName , column . Name ) , nameof ( column ) ) ;
78
74
}
79
75
RowCount = column . Length ;
80
- _columnNames . Insert ( columnIndex , column . Name ) ;
81
76
_columnNameToIndexDictionary [ column . Name ] = columnIndex ;
82
77
for ( int i = columnIndex + 1 ; i < Count ; i ++ )
83
78
{
84
- _columnNameToIndexDictionary [ _columnNames [ i ] ] ++ ;
79
+ _columnNameToIndexDictionary [ this [ i ] . Name ] ++ ;
85
80
}
86
81
base . InsertItem ( columnIndex , column ) ;
87
82
ColumnsChanged ? . Invoke ( ) ;
@@ -99,21 +94,19 @@ protected override void SetItem(int columnIndex, DataFrameColumn column)
99
94
{
100
95
throw new ArgumentException ( string . Format ( Strings . DuplicateColumnName , column . Name ) , nameof ( column ) ) ;
101
96
}
102
- _columnNameToIndexDictionary . Remove ( _columnNames [ columnIndex ] ) ;
103
- _columnNames [ columnIndex ] = column . Name ;
97
+ _columnNameToIndexDictionary . Remove ( this [ columnIndex ] . Name ) ;
104
98
_columnNameToIndexDictionary [ column . Name ] = columnIndex ;
105
99
base . SetItem ( columnIndex , column ) ;
106
100
ColumnsChanged ? . Invoke ( ) ;
107
101
}
108
102
109
103
protected override void RemoveItem ( int columnIndex )
110
104
{
111
- _columnNameToIndexDictionary . Remove ( _columnNames [ columnIndex ] ) ;
105
+ _columnNameToIndexDictionary . Remove ( this [ columnIndex ] . Name ) ;
112
106
for ( int i = columnIndex + 1 ; i < Count ; i ++ )
113
107
{
114
- _columnNameToIndexDictionary [ _columnNames [ i ] ] -- ;
108
+ _columnNameToIndexDictionary [ this [ i ] . Name ] -- ;
115
109
}
116
- _columnNames . RemoveAt ( columnIndex ) ;
117
110
base . RemoveItem ( columnIndex ) ;
118
111
ColumnsChanged ? . Invoke ( ) ;
119
112
}
@@ -144,7 +137,6 @@ protected override void ClearItems()
144
137
{
145
138
base . ClearItems ( ) ;
146
139
ColumnsChanged ? . Invoke ( ) ;
147
- _columnNames . Clear ( ) ;
148
140
_columnNameToIndexDictionary . Clear ( ) ;
149
141
}
150
142
0 commit comments