File tree Expand file tree Collapse file tree 2 files changed +8
-10
lines changed Expand file tree Collapse file tree 2 files changed +8
-10
lines changed Original file line number Diff line number Diff line change @@ -124,11 +124,10 @@ public T this[int index]
124
124
125
125
_collection [ index ] = value ;
126
126
127
- if ( _heapComparer . Compare ( _collection [ index ] , _collection [ 0 ] ) >= 0 ) // greater than or equal to max
128
- {
129
- _collection . Swap ( 0 , index ) ;
130
- _buildMaxHeap ( ) ;
131
- }
127
+ if ( index != 0 && _heapComparer . Compare ( _collection [ index ] , _collection [ ( index - 1 ) / 2 ] ) > 0 ) // greater than or equal to max
128
+ _siftUp ( index ) ;
129
+ else
130
+ _maxHeapify ( index , _collection . Count - 1 ) ;
132
131
}
133
132
}
134
133
Original file line number Diff line number Diff line change @@ -129,11 +129,10 @@ public T this[int index]
129
129
130
130
_collection [ index ] = value ;
131
131
132
- if ( _heapComparer . Compare ( _collection [ index ] , _collection [ 0 ] ) <= 0 ) // less than or equal to min
133
- {
134
- _collection . Swap ( 0 , index ) ;
135
- _buildMinHeap ( ) ;
136
- }
132
+ if ( index != 0 && _heapComparer . Compare ( _collection [ index ] , _collection [ ( index - 1 ) / 2 ] ) < 0 ) // less than or equal to min
133
+ _siftUp ( index ) ;
134
+ else
135
+ _minHeapify ( index , _collection . Count - 1 ) ;
137
136
}
138
137
}
139
138
You can’t perform that action at this time.
0 commit comments