Home / Function/ getWeightedIndices() — drizzle-orm Function Reference

getWeightedIndices() — drizzle-orm Function Reference

Architecture documentation for the getWeightedIndices() function in utils.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  b944ea69_4ea2_ead0_df3f_03885521d095["getWeightedIndices()"]
  3590021a_2509_fc1e_c0e6_fb6ddfe693d4["utils.ts"]
  b944ea69_4ea2_ead0_df3f_03885521d095 -->|defined in| 3590021a_2509_fc1e_c0e6_fb6ddfe693d4
  e7bb7ead_27db_e586_431c_367e654ae94a["init()"]
  e7bb7ead_27db_e586_431c_367e654ae94a -->|calls| b944ea69_4ea2_ead0_df3f_03885521d095
  81c8cbf9_2fb1_f2b8_0172_4f36943e36bf["init()"]
  81c8cbf9_2fb1_f2b8_0172_4f36943e36bf -->|calls| b944ea69_4ea2_ead0_df3f_03885521d095
  04fe66ef_8078_c10b_d9d6_844a98dd34fb["init()"]
  04fe66ef_8078_c10b_d9d6_844a98dd34fb -->|calls| b944ea69_4ea2_ead0_df3f_03885521d095
  3c526ff2_7a2f_e494_ab9a_539d2fa06371["sumArray()"]
  b944ea69_4ea2_ead0_df3f_03885521d095 -->|calls| 3c526ff2_7a2f_e494_ab9a_539d2fa06371
  style b944ea69_4ea2_ead0_df3f_03885521d095 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-seed/src/services/utils.ts lines 27–43

export const getWeightedIndices = (weights: number[], accuracy = 100) => {
	const weightsSum = sumArray(weights);
	if (weightsSum !== 1) {
		throw new Error(
			`The weights for the Weighted Random feature must add up to exactly 1. Please review your weights to ensure they total 1 before proceeding`,
		);
	}

	// const accuracy = 100;
	const weightedIndices: number[] = [];
	for (const [index, weight] of weights.entries()) {
		const ticketsNumb = Math.floor(weight * accuracy);
		weightedIndices.push(...Array.from<number>({ length: ticketsNumb }).fill(index));
	}

	return weightedIndices;
};

Domain

Subdomains

Calls

Called By

Frequently Asked Questions

What does getWeightedIndices() do?
getWeightedIndices() is a function in the drizzle-orm codebase, defined in drizzle-seed/src/services/utils.ts.
Where is getWeightedIndices() defined?
getWeightedIndices() is defined in drizzle-seed/src/services/utils.ts at line 27.
What does getWeightedIndices() call?
getWeightedIndices() calls 1 function(s): sumArray.
What calls getWeightedIndices()?
getWeightedIndices() is called by 3 function(s): init, init, init.

Analyze Your Own Codebase

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

Try Supermodel Free