{
assertion(hasCache(), "addNodeInDocOrder must be done on a mutable sequence!");
int insertIndex = -1;
NodeVector vec = getVector();
// This needs to do a binary search, but a binary search
// is somewhat tough because the sequence test involves
// two nodes.
int size = vec.size(), i;
for (i = size - 1; i >= 0; i--)
{
int child = vec.elementAt(i);
if (child == node)
{
i = -2; // Duplicate, suppress insert
break;
}
DTM dtm = m_dtmMgr.getDTM(node);
if (!dtm.isNodeAfter(node, child))
{
break;
}
}
if (i != -2)
{
insertIndex = i + 1;
vec.insertElementAt(node, insertIndex);
}
// checkDups();
return insertIndex;
} // end addNodeInDocOrder(Vector v, Object obj)