mirror of
https://github.com/facebook/sapling.git
synced 2024-10-12 09:48:05 +03:00
c12e300bb8
Summary: Move top-level Python packages `mercurial`, `hgext` and `hgdemandimport` to a new top-level package `edenscm`. This allows the Python packages provided by the upstream Mercurial to be installed side-by-side. To maintain compatibility, `edenscm/` gets added to `sys.path` in `mercurial/__init__.py`. Reviewed By: phillco, ikostia Differential Revision: D13853115 fbshipit-source-id: b296b0673dc54c61ef6a591ebc687057ff53b22e
47 lines
924 B
C
47 lines
924 B
C
// Copyright 2016-present Facebook. All Rights Reserved.
|
|
//
|
|
// bsearch.c: binary search implementation with context-aware callback.
|
|
//
|
|
// no-check-code
|
|
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
|
|
#include "bsearch.h"
|
|
|
|
size_t bsearch_between(
|
|
const void* needle,
|
|
const void* base,
|
|
const size_t nel,
|
|
const size_t width,
|
|
int (*compare)(
|
|
const void* needle,
|
|
const void* fromarray,
|
|
const void* context),
|
|
const void* context) {
|
|
ptrdiff_t start = 0;
|
|
ptrdiff_t end = nel;
|
|
|
|
while (start < end) {
|
|
ptrdiff_t midpoint = start + ((end - start) / 2);
|
|
|
|
if (midpoint == nel) {
|
|
return nel;
|
|
}
|
|
|
|
const void* ptr = (const void*)((char*)base + (midpoint * width));
|
|
|
|
int cmp = compare(needle, ptr, context);
|
|
|
|
if (cmp == 0) {
|
|
return midpoint;
|
|
} else if (cmp < 0) {
|
|
end = midpoint;
|
|
} else {
|
|
start = midpoint + 1;
|
|
}
|
|
}
|
|
|
|
return start;
|
|
}
|