MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / utstring_find

Function utstring_find

libCacheSim/dataStructure/ut/utstring.h:318–360  ·  view source on GitHub ↗

Search data from left to right. ( One time search mode. ) */

Source from the content-addressed store, hash-verified

316
317/* Search data from left to right. ( One time search mode. ) */
318UTSTRING_UNUSED static long utstring_find(
319 UT_string *s,
320 long P_StartPosition, /* Start from 0. -1 means last position. */
321 const char *P_Needle,
322 size_t P_NeedleLen)
323{
324 long V_StartPosition;
325 long V_HaystackLen;
326 long *V_KMP_Table;
327 long V_FindPosition = -1;
328
329 if (P_StartPosition < 0)
330 {
331 V_StartPosition = s->i + P_StartPosition;
332 }
333 else
334 {
335 V_StartPosition = P_StartPosition;
336 }
337 V_HaystackLen = s->i - V_StartPosition;
338 if ( (V_HaystackLen >= (long) P_NeedleLen) && (P_NeedleLen > 0) )
339 {
340 V_KMP_Table = (long *)malloc(sizeof(long) * (P_NeedleLen + 1));
341 if (V_KMP_Table != NULL)
342 {
343 _utstring_BuildTable(P_Needle, P_NeedleLen, V_KMP_Table);
344
345 V_FindPosition = _utstring_find(s->d + V_StartPosition,
346 V_HaystackLen,
347 P_Needle,
348 P_NeedleLen,
349 V_KMP_Table);
350 if (V_FindPosition >= 0)
351 {
352 V_FindPosition += V_StartPosition;
353 }
354
355 free(V_KMP_Table);
356 }
357 }
358
359 return V_FindPosition;
360}
361
362
363/* Search data from right to left. ( One time search mode. ) */

Callers

nothing calls this directly

Calls 2

_utstring_BuildTableFunction · 0.85
_utstring_findFunction · 0.85

Tested by

no test coverage detected