private InsertDentry ( int lastpos, int value, int &curpos ) : int | ||
lastpos | int | |
value | int | |
curpos | int | |
Результат | int |
private int InsertDentry(int lastpos, int value, ref int curpos)
{
int tmpdepos;
int curdepos;
int sufpos;
int hsize;
int hpos;
if (lastpos != DM_DENTRY_FIRST)
{
sufpos = dentry[lastpos].suffix_pos;
}
else
{
sufpos = entrance;
}
if (sufpos == DM_SUFENTRY_NULL)
{
if (seinfo.Count > sebufsize)
{
if (ResizeInfo() < 0)
{
return -1;
}
}
dentry[lastpos].suffix_pos = seinfo.Count;
sufentry s = InitSufentry(1, lastpos);
seinfo.Add(s);
sufpos = dentry[lastpos].suffix_pos;
}
hsize = seinfo[sufpos].hashsize;
hpos = value % hsize;
tmpdepos = seinfo[sufpos].hashList[hpos];
if ((tmpdepos != DM_DENTRY_NULL) && (dentry[tmpdepos].value == value))
{
curpos = tmpdepos;
return 0;
}
else
{
dm_entry_t det = new dm_entry_t();
det.value = value;
det.lemma_pos = DM_LEMMA_NULL;
det.suffix_pos = DM_SUFENTRY_NULL;
curdepos = dentry.Count;
dentry.Add(det);
if (tmpdepos == DM_DENTRY_NULL)
{
seinfo[sufpos].hashList[hpos] = curdepos;
curpos = curdepos;
return 1;
}
else
{
int newhash;
for (newhash = hsize + 1; ; newhash++)
{
int conflict = 0;
if (seinfo.Count > sebufsize)
{
if (ResizeInfo() < 0)
{
return -1;
}
}
if (lastpos != DM_DENTRY_FIRST)
{
sufpos = dentry[lastpos].suffix_pos;
}
else
{
sufpos = entrance;
}
sufentry s = InitSufentry(newhash, lastpos);
for (int i = 0; i < hsize; i++)
{
int others;
others = seinfo[sufpos].hashList[i];
if (others != DM_DENTRY_NULL)
{
int tmphpos;
tmphpos = dentry[others].value % newhash;
if (s.hashList[tmphpos] == DM_DENTRY_NULL)
{
s.hashList[tmphpos] = others;
}
else
{
conflict = 1;
break;
}
}
}
if (conflict == 0)
{
int tmphpos;
tmphpos = dentry[curdepos].value % newhash;
if (s.hashList[tmphpos] == DM_DENTRY_NULL)
{
s.hashList[tmphpos] = curdepos;
}
else
{
conflict = 1;
}
}
if (conflict == 0)
{
if (lastpos != DM_DENTRY_FIRST)
{
dentry[lastpos].suffix_pos = seinfo.Count;
}
else
{
entrance = seinfo.Count;
}
seinfo.Add(s);
curpos = curdepos;
return 1;
}
}
}
}
}