+void CollReplaceExpand (Collection* C, void* Item, unsigned Index)
+/* If Index is a valid index for the collection, replace the item at this
+ * position by the one passed. If the collection is too small, expand it,
+ * filling unused pointers with NULL, then add the new item at the given
+ * position.
+ */
+{
+ if (Index < C->Count) {
+ /* Collection is already large enough */
+ C->Items[Index] = Item;
+ } else {
+ /* Must expand the collection */
+ unsigned Size = C->Size;
+ if (Size == 0) {
+ Size = 4;
+ }
+ while (Index >= Size) {
+ Size *= 2;
+ }
+ CollGrow (C, Size);
+
+ /* Fill up unused slots with NULL */
+ while (C->Count < Index) {
+ C->Items[C->Count++] = 0;
+ }
+
+ /* Fill in the item */
+ C->Items[C->Count++] = Item;
+ }
+}
+
+
+