2 added 246 characters in body
source | link

This could be a good strategy for a search algorithm. Supose

Supose you have recursive algorithm whenthat performs very deep searches.

When you found the element that satisfies your search criteria you can just throw an "OnFoundEvent" skipping.

If you found nothing, you can throw an "OnNotFoundEvent".

With this technique you skip all the backtracking mechanism caused by athe return statement. Pseudo

Pseudo code example:

public Object search(Criteria criteria) {
    try {
        performDeepSearch(criteria);
        return null; // should never reach this line
    } catch (OnFoundEvent found) {
        return found.object;
    } catch (OnNotFoundEvent notFound) {
        return null;
    }
}

This could be a good strategy for a search algorithm. Supose you have recursive algorithm when you found the element that satisfies your search criteria you can just throw an "OnFoundEvent" skipping the backtracking caused by a return statement. Pseudo code example:

public Object search(Criteria criteria) {
    try {
        performDeepSearch(criteria);
        return null;
    } catch (OnFoundEvent found) {
        return found.object;
    }
}

This could be a good strategy for a search algorithm.

Supose you have recursive algorithm that performs very deep searches.

When you found the element that satisfies your search criteria you can just throw an "OnFoundEvent".

If you found nothing, you can throw an "OnNotFoundEvent".

With this technique you skip all the backtracking mechanism caused by the return statement.

Pseudo code example:

public Object search(Criteria criteria) {
    try {
        performDeepSearch(criteria);
        return null; // should never reach this line
    } catch (OnFoundEvent found) {
        return found.object;
    } catch (OnNotFoundEvent notFound) {
        return null;
    }
}
1
source | link

This could be a good strategy for a search algorithm. Supose you have recursive algorithm when you found the element that satisfies your search criteria you can just throw an "OnFoundEvent" skipping the backtracking caused by a return statement. Pseudo code example:

public Object search(Criteria criteria) {
    try {
        performDeepSearch(criteria);
        return null;
    } catch (OnFoundEvent found) {
        return found.object;
    }
}