public override void Merge(DocValuesFieldUpdates other)
        {
            BinaryDocValuesFieldUpdates otherUpdates = (BinaryDocValuesFieldUpdates)other;
            int newSize = Size + otherUpdates.Size;

            if (newSize > int.MaxValue)
            {
                throw new InvalidOperationException("cannot support more than Integer.MAX_VALUE doc/value entries; size=" + Size + " other.size=" + otherUpdates.Size);
            }
            Docs          = Docs.Grow(newSize);
            Offsets       = Offsets.Grow(newSize);
            Lengths       = Lengths.Grow(newSize);
            DocsWithField = FixedBitSet.EnsureCapacity(DocsWithField, (int)Docs.Size());
            for (int i = 0; i < otherUpdates.Size; i++)
            {
                int doc = (int)otherUpdates.Docs.Get(i);
                if (otherUpdates.DocsWithField.Get(i))
                {
                    DocsWithField.Set(Size);
                }
                Docs.Set(Size, doc);
                Offsets.Set(Size, Values.Length + otherUpdates.Offsets.Get(i)); // correct relative offset
                Lengths.Set(Size, otherUpdates.Lengths.Get(i));
                ++Size;
            }
            Values.Append(otherUpdates.Values);
        }
        public override void Add(int doc, object value)
        {
            // TODO: if the Sorter interface changes to take long indexes, we can remove that limitation
            if (Size == int.MaxValue)
            {
                throw new InvalidOperationException("cannot support more than Integer.MAX_VALUE doc/value entries");
            }

            BytesRef val = (BytesRef)value;

            if (val == null)
            {
                val = BinaryDocValuesUpdate.MISSING;
            }

            // grow the structures to have room for more elements
            if (Docs.Size() == Size)
            {
                Docs          = Docs.Grow(Size + 1);
                Offsets       = Offsets.Grow(Size + 1);
                Lengths       = Lengths.Grow(Size + 1);
                DocsWithField = FixedBitSet.EnsureCapacity(DocsWithField, (int)Docs.Size());
            }

            if (val != BinaryDocValuesUpdate.MISSING)
            {
                // only mark the document as having a value in that field if the value wasn't set to null (MISSING)
                DocsWithField.Set(Size);
            }

            Docs.Set(Size, doc);
            Offsets.Set(Size, Values.Length);
            Lengths.Set(Size, val.Length);
            Values.Append(val);
            ++Size;
        }