本文整理汇总了C++中mozilla::BinarySearch方法的典型用法代码示例。如果您正苦于以下问题:C++ mozilla::BinarySearch方法的具体用法?C++ mozilla::BinarySearch怎么用?C++ mozilla::BinarySearch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mozilla
的用法示例。
在下文中一共展示了mozilla::BinarySearch方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: settle
void
AsmJSFrameIterator::settle(uint8_t *returnAddress)
{
uint32_t target = returnAddress - module_->codeBase();
size_t lowerBound = 0;
size_t upperBound = module_->numCallSites();
size_t match;
if (!BinarySearch(GetCallSite(*module_), lowerBound, upperBound, target, &match)) {
module_ = nullptr;
return;
}
callsite_ = &module_->callSite(match);
if (callsite_->isEntry()) {
module_ = nullptr;
return;
}
sp_ += callsite_->stackDepth();
if (callsite_->isExit())
return settle(ReturnAddressForJitCall(sp_));
JS_ASSERT(callsite_->isNormal());
}
示例2:
const FuncExport&
Metadata::lookupFuncExport(uint32_t funcIndex) const
{
size_t match;
if (!BinarySearch(ProjectFuncIndex(funcExports), 0, funcExports.length(), funcIndex, &match))
MOZ_CRASH("missing function export");
return funcExports[match];
}
示例3: target
const CodeRange*
Code::lookupRange(void* pc) const
{
CodeRange::PC target((uint8_t*)pc - segment_->base());
size_t lowerBound = 0;
size_t upperBound = metadata_->codeRanges.length();
size_t match;
if (!BinarySearch(metadata_->codeRanges, lowerBound, upperBound, target, &match))
return nullptr;
return &metadata_->codeRanges[match];
}
示例4: target
const CodeRange*
Module::lookupCodeRange(void* pc) const
{
CodeRange::PC target((uint8_t*)pc - code());
size_t lowerBound = 0;
size_t upperBound = module_->codeRanges.length();
size_t match;
if (!BinarySearch(module_->codeRanges, lowerBound, upperBound, target, &match))
return nullptr;
return &module_->codeRanges[match];
}
示例5: code
const HeapAccess*
Module::lookupHeapAccess(void* pc) const
{
MOZ_ASSERT(containsFunctionPC(pc));
uint32_t target = ((uint8_t*)pc) - code();
size_t lowerBound = 0;
size_t upperBound = module_->heapAccesses.length();
size_t match;
if (!BinarySearch(HeapAccessOffset(module_->heapAccesses), lowerBound, upperBound, target, &match))
return nullptr;
return &module_->heapAccesses[match];
}
示例6: if
int32_t
gfxMathTable::GetCoverageIndex(const Coverage* aCoverage, uint32_t aGlyph)
{
using mozilla::BinarySearch;
using mozilla::BinarySearchIf;
if (uint16_t(aCoverage->mFormat) == 1) {
// Coverage Format 1: list of individual glyph indices in the glyph set.
const CoverageFormat1* table =
reinterpret_cast<const CoverageFormat1*>(aCoverage);
const uint16_t count = table->mGlyphCount;
const char* start = reinterpret_cast<const char*>(table + 1);
if (ValidStructure(start, count * sizeof(GlyphID))) {
const GlyphID* glyphArray = reinterpret_cast<const GlyphID*>(start);
size_t index;
if (BinarySearch(GlyphArrayWrapper(glyphArray), 0, count, aGlyph, &index)) {
return index;
}
}
} else if (uint16_t(aCoverage->mFormat) == 2) {
// Coverage Format 2: ranges of consecutive indices.
const CoverageFormat2* table =
reinterpret_cast<const CoverageFormat2*>(aCoverage);
const uint16_t count = table->mRangeCount;
const char* start = reinterpret_cast<const char*>(table + 1);
if (ValidStructure(start, count * sizeof(RangeRecord))) {
const RangeRecord* rangeArray = reinterpret_cast<const RangeRecord*>(start);
size_t index;
if (BinarySearchIf(rangeArray, 0, count, RangeRecordComparator(aGlyph),
&index)) {
uint16_t rStart = rangeArray[index].mStart;
uint16_t startCoverageIndex = rangeArray[index].mStartCoverageIndex;
return (startCoverageIndex + aGlyph - rStart);
}
}
}
return -1;
}
示例7: main
int main()
{
size_t m;
Vector<int> v1;
v1.append(2);
v1.append(4);
v1.append(6);
v1.append(8);
MOZ_ASSERT(!BinarySearch(v1, 0, v1.length(), 1, &m) && m == 0);
MOZ_ASSERT( BinarySearch(v1, 0, v1.length(), 2, &m) && m == 0);
MOZ_ASSERT(!BinarySearch(v1, 0, v1.length(), 3, &m) && m == 1);
MOZ_ASSERT( BinarySearch(v1, 0, v1.length(), 4, &m) && m == 1);
MOZ_ASSERT(!BinarySearch(v1, 0, v1.length(), 5, &m) && m == 2);
MOZ_ASSERT( BinarySearch(v1, 0, v1.length(), 6, &m) && m == 2);
MOZ_ASSERT(!BinarySearch(v1, 0, v1.length(), 7, &m) && m == 3);
MOZ_ASSERT( BinarySearch(v1, 0, v1.length(), 8, &m) && m == 3);
MOZ_ASSERT(!BinarySearch(v1, 0, v1.length(), 9, &m) && m == 4);
MOZ_ASSERT(!BinarySearch(v1, 1, 3, 1, &m) && m == 1);
MOZ_ASSERT(!BinarySearch(v1, 1, 3, 2, &m) && m == 1);
MOZ_ASSERT(!BinarySearch(v1, 1, 3, 3, &m) && m == 1);
MOZ_ASSERT( BinarySearch(v1, 1, 3, 4, &m) && m == 1);
MOZ_ASSERT(!BinarySearch(v1, 1, 3, 5, &m) && m == 2);
MOZ_ASSERT( BinarySearch(v1, 1, 3, 6, &m) && m == 2);
MOZ_ASSERT(!BinarySearch(v1, 1, 3, 7, &m) && m == 3);
MOZ_ASSERT(!BinarySearch(v1, 1, 3, 8, &m) && m == 3);
MOZ_ASSERT(!BinarySearch(v1, 1, 3, 9, &m) && m == 3);
MOZ_ASSERT(!BinarySearch(v1, 0, 0, 0, &m) && m == 0);
MOZ_ASSERT(!BinarySearch(v1, 0, 0, 9, &m) && m == 0);
Vector<int> v2;
MOZ_ASSERT(!BinarySearch(v2, 0, 0, 0, &m) && m == 0);
MOZ_ASSERT(!BinarySearch(v2, 0, 0, 9, &m) && m == 0);
Vector<Person> v3;
v3.append(Person(2, 42));
v3.append(Person(4, 13));
v3.append(Person(6, 360));
MOZ_ASSERT(!BinarySearch(GetAge(v3), 0, v3.length(), 1, &m) && m == 0);
MOZ_ASSERT( BinarySearch(GetAge(v3), 0, v3.length(), 2, &m) && m == 0);
MOZ_ASSERT(!BinarySearch(GetAge(v3), 0, v3.length(), 3, &m) && m == 1);
MOZ_ASSERT( BinarySearch(GetAge(v3), 0, v3.length(), 4, &m) && m == 1);
MOZ_ASSERT(!BinarySearch(GetAge(v3), 0, v3.length(), 5, &m) && m == 2);
MOZ_ASSERT( BinarySearch(GetAge(v3), 0, v3.length(), 6, &m) && m == 2);
MOZ_ASSERT(!BinarySearch(GetAge(v3), 0, v3.length(), 7, &m) && m == 3);
}