Home / Function/ binaryInsert() — astro Function Reference

binaryInsert() — astro Function Reference

Architecture documentation for the binaryInsert() function in host-route.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  9ba1afb7_c929_0c88_8171_5062da01bcc4["binaryInsert()"]
  ad6a2143_4751_effa_9c1f_a5f673b5dd66["host-route.ts"]
  9ba1afb7_c929_0c88_8171_5062da01bcc4 -->|defined in| ad6a2143_4751_effa_9c1f_a5f673b5dd66
  b1f43f3f_9019_e0e4_9d66_75b560d13654["add()"]
  b1f43f3f_9019_e0e4_9d66_75b560d13654 -->|calls| 9ba1afb7_c929_0c88_8171_5062da01bcc4
  style 9ba1afb7_c929_0c88_8171_5062da01bcc4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/underscore-redirects/src/host-route.ts lines 53–76

function binaryInsert<T>(sorted: T[], item: T, comparator: (a: T, b: T) => boolean) {
	if (sorted.length === 0) {
		sorted.push(item);
		return 0;
	}
	let low = 0,
		high = sorted.length - 1,
		mid = 0;
	while (low <= high) {
		mid = low + ((high - low) >> 1);
		if (comparator(sorted[mid], item)) {
			low = mid + 1;
		} else {
			high = mid - 1;
		}
	}

	if (comparator(sorted[mid], item)) {
		mid++;
	}

	sorted.splice(mid, 0, item);
	return mid;
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does binaryInsert() do?
binaryInsert() is a function in the astro codebase, defined in packages/underscore-redirects/src/host-route.ts.
Where is binaryInsert() defined?
binaryInsert() is defined in packages/underscore-redirects/src/host-route.ts at line 53.
What calls binaryInsert()?
binaryInsert() is called by 1 function(s): add.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free