コード例 #1
0
ファイル: SAu.c プロジェクト: ccontavalli/full-text-index
int locate(void *index, uchar *pattern, ulong length, ulong **occ, ulong *numocc){
  TSA_Un *_index=(TSA_Un *) index;
  ulong L=0;
  ulong R=_index->n;
  ulong i=(L+R)/2;
  ulong Lraja=0;
  ulong Rraja=0;
  ulong matches=0;
  /* Search for the left boundary */
  if (ComparePos(_index,GetPos(_index, 0),pattern,length) <= 0)
     Lraja=0;
  else {
     while (L<R-1) {
        if (ComparePos(_index,GetPos(_index,i),pattern,length) <= 0)
           R = i;
        else
           L = i;
        i = (R+L)/2;
     }
     Lraja=R;
  }
  /* Search for the right boundary */
  L=0;
  R=_index->n;
  i=(L+R)/2;
  if (ComparePos(_index,GetPos(_index,0),pattern,length) <= 0)
     Rraja=0;
  else {
     while (L < R-1) {
        if (ComparePos(_index,GetPos(_index,i),pattern,length) >= 0)
           L = i;
        else
           R = i;
        i = (R+L)/2;
     }
     Rraja=L;
  }
  matches = Rraja-Lraja+1;
  if (matches >0) {
     ulong locate=0;
     (*occ) = (ulong *) malloc(matches*sizeof(ulong)); 
     if (!(*occ)) return 1;
     for (; Lraja<=Rraja; Lraja++) {
        (*occ)[locate]=GetPos(_index,Lraja);
        locate++;
     }
  } else
     *occ = NULL;
  (*numocc)=matches;
  return 0;
}
コード例 #2
0
ファイル: SAu.c プロジェクト: peper/pizza
/*////////////////////
//Querying the Index//
////////////////////*/
int count(void *index, uchar *pattern, ulong length, ulong *numocc){
  TSA_Un *_index=(TSA_Un *) index;
  ulong L=0;
  ulong R=_index->n;
  ulong i=(L+R)/2;
  ulong Lraja=0;
  ulong Rraja=0;
  /* Search for the left boundary */
  if (ComparePos(_index,GetPos(_index,0),pattern,length) <= 0)
     Lraja=0;
  else {
     while (L<R-1) {
        if (ComparePos(_index,GetPos(_index,i),pattern,length) <= 0)
           R = i;
        else
           L = i;
        i = (R+L)/2;
     }
     Lraja=R;
  }
  /* Search for the right boundary */

  L=0;
  R=_index->n;
  i=(L+R)/2;
  /*if (ComparePos(_index,GetPos(_index,0),pattern,length) <= 0)
     Rraja=0;
  else {*/
     while (L < R-1) {
        if (ComparePos(_index,GetPos(_index,i),pattern,length) >= 0)
           L = i;
        else
           R = i;
        i = (R+L)/2;
     }
     Rraja=L;
  /*}*/
#if 0
  printf("\n");
  printf("Count: %lu de %lu hasta %lu\n",Rraja-Lraja+1, Lraja, Rraja);fflush(stdout);
#endif
  (*numocc)=Rraja-Lraja+1;
  return 0;
}
コード例 #3
0
ファイル: SAu.c プロジェクト: ccontavalli/full-text-index
/*////////////////////
//Querying the Index//
////////////////////*/
int count(void *index, uchar *pattern, ulong length, ulong *numocc){
  TSA_Un *_index=(TSA_Un *) index;
  ulong L=0;
  ulong R=_index->n;
  ulong i=(L+R)/2;
  ulong Lraja=0;
  ulong Rraja=0;
  /* Search for the left boundary */
  if (ComparePos(_index,GetPos(_index,0),pattern,length) <= 0)
     Lraja=0;
  else {
     while (L<R-1) {
        if (ComparePos(_index,GetPos(_index,i),pattern,length) <= 0)
           R = i;
        else
           L = i;
        i = (R+L)/2;
     }
     Lraja=R;
  }
  /* Search for the right boundary */

  L=0;
  R=_index->n;
  i=(L+R)/2;
  if (ComparePos(_index,GetPos(_index,0),pattern,length) <= 0)
     Rraja=0;
  else {
     while (L < R-1) {
        if (ComparePos(_index,GetPos(_index,i),pattern,length) >= 0)
           L = i;
        else
           R = i;
        i = (R+L)/2;
     }
     Rraja=L;
  }
  (*numocc)=Rraja-Lraja+1;
  return 0;
}
コード例 #4
0
ファイル: SrchDlg.c プロジェクト: mike2718/WinVi
BOOL SearchAgain(WORD Flags)
	/*Flags: 1=Reverse (search in opposite direction)
	 *		 2=pop up dialog if not searched before
	 */
{	BOOL  Return;
	ULONG OldLength;

	HideEditCaret();
	if (Flags & 2 && !MatchValid) {
		SearchDialog();
		return (TRUE);
	}
	OldLength = SelectCount;
	if (OldLength) {
		InvalidateArea(&SelectStart, SelectCount, 1);
		SelectCount = 0;
		UpdateWindow(hwndMain);
	}
	SelectStart = CurrPos;
	Return = SearchAndStatus(&SelectStart, (WORD)((Flags & 1) | 2));
	if (Return) {
		if ((OldLength==0 && Mode!=InsertMode) ||
				ComparePos(&SelectStart, &CurrPos) == 0) {
			if (CountBytes(&EndMatch) - CountBytes(&StartPos) == OldLength) {
				SelectStart = CurrPos;
				Return = SearchAndStatus(&SelectStart, (WORD)(Flags & 1));
			}
		}
		if (Return) {
			NewPosition(&SelectStart);
			UpdateWindow(hwndMain);
			SelectStart   = StartPos;
			SelectBytePos = CountBytes(&StartPos);
			SelectCount   = CountBytes(&EndMatch) - SelectBytePos;
			InvalidateArea(&SelectStart, SelectCount, 0);
			UpdateWindow(hwndMain);
		}
	}
	CheckClipboard();
	ShowEditCaret();
	GetXPos(&CurrCol);
	return (Return);
}
コード例 #5
0
ファイル: SAu.c プロジェクト: peper/pizza
int locate(void *index, uchar *pattern, ulong length, ulong **occ, ulong *numocc){
  TSA_Un *_index=(TSA_Un *) index;
  ulong L=0;
  ulong R=_index->n;
  ulong i=(L+R)/2;
  ulong Lraja=0;
  ulong Rraja=0;
  ulong matches=0;
  /*pattern[0]=9;
  pattern[1]=9;
  pattern[2]=9;
  pattern[3]=32;
  pattern[4]=32;

  printf("aqui parte\n");
  for (i=23119; i < 23119+10; i++)
    printf("%d ", _index->text[i]);
  printf("\naqui termina\n");
  printf("aqui parte\n");
  for (i=488; i < 488+10; i++)
    printf("%d ", _index->text[i]);
  printf("\naqui termina\n");
*/
  /* Search for the left boundary */
  if (ComparePos(_index,GetPos(_index, 0),pattern,length) <= 0)
     Lraja=0;
  else {
     while (L<R-1) {
        if (ComparePos(_index,GetPos(_index,i),pattern,length) <= 0)
           R = i;
        else
           L = i;
        i = (R+L)/2;
     }
     Lraja=R;
  }
  /* Search for the right boundary */
  L=0;
  R=_index->n;
  i=(L+R)/2;
  /*/if (ComparePos(_index,GetPos(_index,0),pattern,length) <= 0)
  //   Rraja=0;
  //else {*/
     while (L < R-1) {
        if (ComparePos(_index,GetPos(_index,i),pattern,length) >= 0)
           L = i;
        else
           R = i;
        i = (R+L)/2;
     }
     Rraja=L;
  /*}*/
  matches = Rraja-Lraja+1;
  if (matches >0) {
     ulong locate=0;
     (*occ) = (ulong *) malloc(matches*sizeof(ulong)); 
     if (!(*occ)) return 1;
     for (; Lraja<=Rraja; Lraja++) {
        (*occ)[locate]=GetPos(_index,Lraja);
        locate++;
     }
  } else
     *occ = NULL;
  (*numocc)=matches;
  return 0;
}
コード例 #6
0
ファイル: Clipbrd.c プロジェクト: mike2718/WinVi
BOOL ClipboardCopy(void)
{	HGLOBAL	  hMem;
	char huge *pMem;
	LONG	  lSize;
	BOOL	  WideCharConvert = FALSE;
	UINT	  Codepage = 0;

	/*prepare resources...*/
	if (!SelectCount) {
		Error(209);
		return (FALSE);
	}
	if (!OpenClipboard(hwndMain)) {
		ErrorBox(MB_ICONEXCLAMATION, 302);
		return (FALSE);
	}
	lSize = SelectCount + sizeof(BinaryPart);
	if (!(GetVersion() & 0x80000000U))
		if (UtfEncoding || CharSet == CS_OEM || AnsiCodePage != CP_ACP) {
			/*copy as wide chars...*/
			Codepage = CharSet == CS_OEM ? OemCodePage : AnsiCodePage;
			if (UtfEncoding != 16)
				lSize <<= 1;
			WideCharConvert = TRUE;
		}
	hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, lSize);
	if (!hMem) {
		CloseClipboard();
		ErrorBox(MB_ICONEXCLAMATION, 304);
		return (FALSE);
	}
	pMem = GlobalLock(hMem);
	if (pMem == NULL) {
		CloseClipboard();
		GlobalFree(hMem);
		ErrorBox(MB_ICONEXCLAMATION, 305);
		return (FALSE);
	}

	/*copy into memory...*/
	{	POSITION Pos;
		ULONG    Bytes = SelectCount;
		UINT     i;
		BOOL	 NullbyteFound = FALSE;

		Pos = SelectStart;
		if (UtfEncoding && WideCharConvert) {
			POSITION EndPos = Pos;
			WCHAR	 *pw = (WCHAR *)pMem;

			Advance(&EndPos, Bytes);
			//if (CountBytes(&Pos) != 0 || (i = CharAndAdvance(&Pos)) == C_BOM)
			i = CharAndAdvance(&Pos);
			for (;;) {
				if (ComparePos(&Pos, &EndPos) > 0)
					break;
				if (i == C_EOF) break;
				if (i == C_CRLF) {
					if ((char *)pw + 6 > pMem + lSize)
						break;
					*pw++ = '\r';
					i = '\n';
				}
				if ((char *)pw + 4 > pMem + lSize)
					break;
				*pw++ = i;
				i = CharAndAdvance(&Pos);
			}
			*pw = '\0';
		} else while (Bytes) {
			LPSTR p, pNull;

			CharAt(&Pos);	/*normalize position and enforce page load*/
			i = Pos.p->Fill - Pos.i;
			if (i > Bytes) i = (UINT)Bytes;
			p = Pos.p->PageBuf + Pos.i;
			if (!NullbyteFound && (pNull = _fmemchr(p, '\0', i)) != NULL) {
				if (ErrorBox(MB_ICONINFORMATION|MB_OKCANCEL, 328) == IDCANCEL) {
					CloseClipboard();
					GlobalUnlock(hMem);
					GlobalFree(hMem);
					return (FALSE);
				}
				NullbyteFound = TRUE;
				i = pNull - p + 1;
				if (CharSet == CS_EBCDIC) EbcdicConvert(pMem, p, i);
				else if (WideCharConvert) {
					MultiByteToWideChar(Codepage, 0, p, i, (WCHAR*)pMem, i);
					pMem += i;
				} else hmemcpy(pMem, p, i);
				pMem  += i;
				Bytes -= --i;
				Pos.i += i;
				i = wsprintf(BinaryPart, BinaryFormat, Bytes);
				if (WideCharConvert) {
					MultiByteToWideChar(Codepage, 0, BinaryPart, i,
													 (WCHAR*)pMem, i);
					pMem += i;
				} else hmemcpy(pMem, BinaryPart, i);
				pMem += i;
				continue;
			}
			if (CharSet == CS_EBCDIC)
				EbcdicConvert(pMem, Pos.p->PageBuf + Pos.i, i);
			else if (WideCharConvert) {
				MultiByteToWideChar(Codepage, 0, Pos.p->PageBuf + Pos.i, i,
												 (WCHAR*)pMem, i);
				if (CharSet == CS_OEM) {
					extern WCHAR const MapLowOemToUtf16[33];
					PWSTR			   pw = (WCHAR*)pMem;
					INT				   j;

					for (j=i; j>0; --j) {
						if (*pw < ' ') {
							switch (*pw) {
							case '\0':
							case '\t':
							case '\n':
							case '\r':	break;
							default:	*pw = MapLowOemToUtf16[*pw];
							}
						}
						++pw;
					}
				}
				pMem += i;
			} else hmemcpy(pMem, Pos.p->PageBuf + Pos.i, i);
			pMem  += i;
			Bytes -= i;
			Pos.i += i;
		}
	}

	/*unlock...*/
	GlobalUnlock(hMem);

	/*clear previous clipboard contents...*/
	if (!EmptyClipboard()) {
		CloseClipboard();
		GlobalFree(hMem);
		ErrorBox(MB_ICONEXCLAMATION, 303);
		return (FALSE);
	}

	/*finally, publish...*/
	SetClipboardData(WideCharConvert ? CF_UNICODETEXT
									 : CharSet == CS_OEM ? CF_OEMTEXT
														 : CF_TEXT, hMem);
	CloseClipboard();
	CheckClipboard();
	return (TRUE);
}
コード例 #7
0
ファイル: SA_BPE.cpp プロジェクト: pombredanne/pizza-1
int locate(void *index, uchar *pattern, ulong length, ulong **occ, ulong *numocc) {
    //locate_extract3(index);
    //exit(0);
    TSA_Un *_index=(TSA_Un *) index;
    *occ=NULL;
    ulong LL,RR, matches;
    /* Search for the left boundary */
    ulong L=0;
    ulong R=_index->ns;            // over the sample positions
    ulong i=(L+R)/2;
    ulong Lraja=0;
    ulong DER=_index->ns;
    int aux;
    if (ComparePos(_index,GetPos(_index,0),pattern,length) <= 0)
        Lraja=0;
    else {
        while (L<R-1) {
            aux=ComparePos(_index,GetPos(_index,i),pattern,length);
            if (aux > 0)
                L = i;
            else if (aux < 0) {
                DER = R = i;
            } else
                R = i;
            i = (R+L)/2;
        }
        Lraja=R;
    }
    while ((Lraja != 0) && (_index->pos[Lraja-1]==_index->pos[Lraja]))
        Lraja--;

    /* Search for the right boundary */

    if (Lraja == 0) L=0;
    else L=Lraja-1;
    R=DER;//_index->ns;
    i=(L+R)/2;
    ulong Rraja=0;
    if (ComparePos(_index,GetPos(_index,0),pattern,length) <= 0)
        Rraja=0;
    else {
        while (L < R-1) {
            if (ComparePos(_index,GetPos(_index,i),pattern,length) >= 0)
                L = i;
            else
                R = i;
            i = (R+L)/2;
        }
        Rraja=L;
    }

    while ((Rraja != _index->ns-1) && (_index->pos[Rraja+1]==_index->pos[Rraja]))
        Rraja++;

    /* Cross case */
    ulong *SA;
    ulong largo,RR_N;
    if ((Rraja-Lraja+1)==0) {
        if (Lraja == _index->ns-1) {
            LL = _index->n-1;
            RR_N=_index->n-1;
        }
        else {
            LL=_index->bpe->BR->prev(Lraja*_index->samplerate);
            RR_N=_index->bpe->BR->prev((Rraja+1)*_index->samplerate);
        }
        RR=_index->bpe->BR->prev(Rraja*_index->samplerate);

        SA=_index->bpe->dispair2(RR,RR_N-RR);



        assert(RR_N-RR==SA[0]);
        largo=SA[0];
        SA[1]=_index->pos[Rraja];
        SA[largo+1]=_index->pos[Rraja+1];
        for (i=largo; i >=2; i--)
            SA[i]=SA[i+1]-SA[i]+_index->n;
        /* Search for the left boundary */
        if (Lraja == 0) LL=0;
        else {
            L=1;
            DER=R=largo+2;                 // over the sample positions
            i=(L+R)/2;
            Lraja=1;

            while (L<R-1) {
                aux = ComparePos(_index,SA[i],pattern,length);
                if (aux > 0)
                    L = i;
                else if (aux < 0) {
                    DER = R = i;
                } else
                    R = i;
                i = (R+L)/2;
            }
            Lraja=R;
            LL=LL-largo+Lraja-1;
        }
        /* Search for the right boundary */
        if (Rraja == _index->ns-1) RR=_index->n-1;
        else {
            if (Lraja == 1) L=1;
            else L=Lraja-1;
            //L=1;
            R=DER;//_index->ns;

            //L=0;
            //R=largo+2;
            i=(L+R)/2;
            Rraja=1;
            while (L < R-1) {
                if (ComparePos(_index,SA[i],pattern,length) >= 0)
                    L = i;
                else
                    R = i;
                i = (R+L)/2;
            }
            Rraja=L;
            RR=RR+Rraja-1;
        }
        //printf("\n");
        //printf("Count: %lu de %lu hasta %lu\n",RR-LL+1, LL, RR);fflush(stdout);
        //if (LL==102369)
        //printf("caso1\n");

        (*numocc)=RR-LL+1;
        matches = RR-LL+1;
        if (matches >0) {
            ulong locate=0;
            (*occ) = (ulong *) malloc(matches*sizeof(ulong));
            if (!(*occ)) return 1;
            for (; Lraja<=Rraja; Lraja++) {
                (*occ)[locate]=SA[Lraja];
                locate++;
            }
        } else
            *occ = NULL;
        free(SA);
        return 0;
    }

    /* Normal case */

    ulong *SA1=NULL, *SA2=NULL,L1,R1,LL_P, largol=0;
    /* Search for the left boundary */
    if (Lraja == 0) {
        LL=0;
        L1=0;
    }
    else if (Lraja == _index->ns-1) {
        LL=_index->n-1;
        L1=Lraja;
    }
    else {
        LL=_index->bpe->BR->prev(Lraja*_index->samplerate);
        LL_P=_index->bpe->BR->prev((Lraja-1)*_index->samplerate);
        L1=Lraja;

        SA1=_index->bpe->dispair2(LL_P,LL-LL_P);
        largol=SA1[0];
        SA1[1]=_index->pos[Lraja-1];
        SA1[largol+1]=_index->pos[Lraja];
        for (i=largol; i >=2; i--)
            SA1[i]=SA1[i+1]-SA1[i]+_index->n;
        L=1;
        R=largol+2;                   // over the sample positions
        i=(L+R)/2;
        Lraja=1;
        while (L<R-1) {
            if (ComparePos(_index,SA1[i],pattern,length) <= 0)
                R = i;
            else
                L = i;
            i = (R+L)/2;
        }
        Lraja=R;
        LL=LL-largol+Lraja-1;
    }
    if (Rraja == _index->ns-1) {
        RR=_index->n-1;
        R1=Rraja;
        Rraja=0;
    }
    else {

        if (Rraja+1 == _index->ns-1) RR_N=_index->n-1;
        else RR_N=_index->bpe->BR->prev((Rraja+1)*_index->samplerate);

        RR=_index->bpe->BR->prev(Rraja*_index->samplerate);

        SA2=_index->bpe->dispair2(RR,RR_N-RR);

        R1=Rraja;
        largo=SA2[0];
        SA2[1]=_index->pos[Rraja];
        SA2[largo+1]=_index->pos[Rraja+1];
        for (i=largo; i >=2; i--)
            SA2[i]=SA2[i+1]-SA2[i]+_index->n;

        L=1;
        R=largo+2;
        i=(L+R)/2;
        Rraja=1;
        while (L < R-1) {
            if (ComparePos(_index,SA2[i],pattern,length) >= 0)
                L = i;
            else
                R = i;
            i = (R+L)/2;
        }
        Rraja=L;
        RR=RR+Rraja-1;
    }
    //printf("\n");
    //printf("Count: %lu de %lu hasta %lu\n",RR-LL+1, LL, RR);fflush(stdout);
    (*numocc)=RR-LL+1;
    matches = RR-LL+1;
    (*occ) = (ulong *) malloc(matches*sizeof(ulong));
    if (!(*occ)) return 1;

    if ((SA1 == NULL) && (SA2 == NULL)) {
        (*occ)[0]=_index->pos[_index->ns-1];
        return 0;
    }

    ulong locate=0;
    if (SA1 != NULL)
        for (; Lraja<=largol; Lraja++) {
            (*occ)[locate]=SA1[Lraja];
            locate++;
        }
    locate=matches-1;
    for (; 0 < Rraja; Rraja--) {
        (*occ)[locate]=SA2[Rraja];
        locate--;
    }


    if (SA1 !=NULL) free(SA1);
    if (SA2 !=NULL) free(SA2);
    if ((_index->pos[R1]-_index->pos[L1]) == 0) return 0;

    SA=_index->bpe->dispair2(_index->bpe->BR->prev(L1*_index->samplerate),_index->bpe->BR->prev(R1*_index->samplerate)-_index->bpe->BR->prev(L1*_index->samplerate));
    //SA=_index->bpe->dispair(L1*_index->samplerate+1,_index->samplerate*(R1-L1)-1);
    largo=SA[0];
    SA[0]=_index->pos[L1];
    SA[largo+1]=_index->pos[R1];
    for (i=largo; i >=1; i--) {
        (*occ)[locate]=(*occ)[locate+1]-SA[i]+_index->n;
        locate--;
    }

    free(SA);
    return 0;
}
コード例 #8
0
ファイル: SA_BPE.cpp プロジェクト: pombredanne/pizza-1
/*////////////////////
//Querying the Index//
////////////////////*/
int count(void *index, uchar *pattern, ulong length, ulong *numocc) {
    TSA_Un *_index=(TSA_Un *) index;
    ulong LL,RR;
    /* Search for the left boundary */
    ulong L=0;
    ulong R=_index->ns;            // over the sample positions
    ulong i=(L+R)/2;
    ulong Lraja=0;
    ulong DER=_index->ns;
    int aux;
    if (ComparePos(_index,GetPos(_index,0),pattern,length) <= 0)
        Lraja=0;
    else {
        while (L<R-1) {
            aux=ComparePos(_index,GetPos(_index,i),pattern,length);
            if (aux > 0)
                L = i;
            else if (aux < 0) {
                DER = R = i;
            } else
                R = i;
            i = (R+L)/2;
        }
        Lraja=R;
    }
    while ((Lraja != 0) && (_index->pos[Lraja-1]==_index->pos[Lraja]))
        Lraja--;

    /* Search for the right boundary */

    if (Lraja == 0) L=0;
    else L=Lraja-1;
    R=DER;//_index->ns;
    i=(L+R)/2;
    ulong Rraja=0;
    if (ComparePos(_index,GetPos(_index,0),pattern,length) <= 0)
        Rraja=0;
    else {
        while (L < R-1) {
            if (ComparePos(_index,GetPos(_index,i),pattern,length) >= 0)
                L = i;
            else
                R = i;
            i = (R+L)/2;
        }
        Rraja=L;
    }

    while ((Rraja != _index->ns-1) && (_index->pos[Rraja+1]==_index->pos[Rraja]))
        Rraja++;

    /* Cross case */
    ulong *SA;
    ulong largo,RR_N;
    if ((Rraja-Lraja+1)==0) {
        if (Lraja == _index->ns-1) {
            LL = _index->n-1;
            RR_N=_index->n-1;
        }
        else {
            LL=_index->bpe->BR->prev(Lraja*_index->samplerate);
            RR_N=_index->bpe->BR->prev((Rraja+1)*_index->samplerate);
        }
        RR=_index->bpe->BR->prev(Rraja*_index->samplerate);

        SA=_index->bpe->dispair2(RR,RR_N-RR);
        //ulong *SA2 =_index->bpe->dispair2(RR,RR_N-RR);
        //for (i=0;i<=SA2[0];i++)
        //assert(SA[i]==SA2[i]);
        assert(RR_N-RR==SA[0]);
        largo=SA[0];
        SA[1]=_index->pos[Rraja];
        SA[largo+1]=_index->pos[Rraja+1];
        for (i=largo; i >=2; i--)
            SA[i]=SA[i+1]-SA[i]+_index->n;
        /* Search for the left boundary */
        if (Lraja == 0) LL=0;
        else {
            L=1;
            DER=R=largo+2;                 // over the sample positions
            i=(L+R)/2;
            Lraja=1;

            while (L<R-1) {
                aux = ComparePos(_index,SA[i],pattern,length);
                if (aux > 0)
                    L = i;
                else if (aux < 0) {
                    DER = R = i;
                } else
                    R = i;
                i = (R+L)/2;
            }
            Lraja=R;
            LL=LL-largo+Lraja-1;
        }
        /* Search for the right boundary */
        if (Rraja == _index->ns-1) RR=_index->n-1;
        else {

            if (Lraja == 1) L=1;
            else L=Lraja-1;

            //L=1;
            R=DER;//largo+2;
            i=(L+R)/2;
            Rraja=1;
            while (L < R-1) {
                if (ComparePos(_index,SA[i],pattern,length) >= 0)
                    L = i;
                else
                    R = i;
                i = (R+L)/2;
            }
            Rraja=L;
            RR=RR+Rraja-1;
        }
        //printf("\n");
        //printf("Count: %lu de %lu hasta %lu\n",RR-LL+1, LL, RR);fflush(stdout);
        //if (LL==4864)
        //printf("caso1\n");

        (*numocc)=RR-LL+1;
        free(SA);
        return 0;
    }
    /* Normal case */
    ulong LL_P;
    /* Search for the left boundary */
    if (Lraja == 0) LL=0;
    else if (Lraja == _index->ns-1) LL=_index->n-1;
    else {
        LL=_index->bpe->BR->prev(Lraja*_index->samplerate);
        LL_P=_index->bpe->BR->prev((Lraja-1)*_index->samplerate);


        //LL=Lraja*_index->samplerate;
        //SA=_index->bpe->dispair((Lraja-1)*_index->samplerate+1,_index->samplerate-1);
        SA=_index->bpe->dispair2(LL_P,LL-LL_P);
        assert(LL-LL_P==SA[0]);
        largo=SA[0];
        SA[1]=_index->pos[Lraja-1];
        SA[largo+1]=_index->pos[Lraja];
        for (i=largo; i >=2; i--)
            SA[i]=SA[i+1]-SA[i]+_index->n;
        L=1;
        R=largo+2;                   // over the sample positions
        i=(L+R)/2;
        Lraja=1;
        while (L<R-1) {
            if (ComparePos(_index,SA[i],pattern,length) <= 0)
                R = i;
            else
                L = i;
            i = (R+L)/2;
        }
        Lraja=R;
        LL=LL-largo+Lraja-1;
        free(SA);
    }
    if (Rraja == _index->ns-1) RR=_index->n-1;
    else {

        if (Rraja+1 == _index->ns-1) RR_N=_index->n-1;
        else RR_N=_index->bpe->BR->prev((Rraja+1)*_index->samplerate);

        RR=_index->bpe->BR->prev(Rraja*_index->samplerate);

        SA=_index->bpe->dispair2(RR,RR_N-RR);

        assert(RR_N-RR==SA[0]);


        //RR=Rraja*_index->samplerate;
        //SA=_index->bpe->dispair(RR+1,_index->samplerate-1);
        largo=SA[0];
        SA[1]=_index->pos[Rraja];
        SA[largo+1]=_index->pos[Rraja+1];
        for (i=largo; i >=2; i--)
            SA[i]=SA[i+1]-SA[i]+_index->n;

        L=1;
        R=largo+2;
        i=(L+R)/2;
        Rraja=1;
        while (L < R-1) {
            if (ComparePos(_index,SA[i],pattern,length) >= 0)
                L = i;
            else
                R = i;
            i = (R+L)/2;
        }
        Rraja=L;
        RR=RR+Rraja-1;
        free(SA);
    }
    //printf("\n");
    //printf("Count: %lu de %lu hasta %lu\n",RR-LL+1, LL, RR);fflush(stdout);
    //if (LL==4864)
    //printf("caso2\n");

    (*numocc)=RR-LL+1;
    return 0;
}