Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Google deepmind Mujoco Engine Name

From Leeroopedia
Revision as of 12:45, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Google_deepmind_Mujoco_Engine_Name.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Physics Simulation, Name Resolution
Last Updated 2026-02-15 04:00 GMT

Overview

Implements name-to-id and id-to-name lookup functions for all named MuJoCo model objects, using hash-based name resolution.

Description

This file provides the name resolution system for MuJoCo models, allowing bidirectional mapping between human-readable string names and integer IDs for all object types (bodies, joints, geoms, sites, cameras, lights, tendons, actuators, sensors, flexes, meshes, skins, materials, textures, pairs, excludes, equalities, numerics, texts, tuples, keys, plugins). The internal _getnumadr function uses a switch statement with explicit fallthrough to compute hash map addresses for each object type, traversing the type hierarchy to find the correct offset into the names map. mj_name2id performs hash-based lookup using the djb2 hash function (mj_hashString) with linear probing for collision resolution. mj_id2name performs direct array-based reverse lookup. The hash map uses a load factor of 0.5 (controlled by mjLOAD_MULTIPLE).

Usage

Called by user code and internal engine functions whenever an object needs to be referenced by name (e.g., mj_name2id(m, mjOBJ_BODY, "torso")) or when an object's name needs to be displayed (e.g., for visualization labels).

Code Reference

Source Location

Key Functions

// Internal: get number of objects and name address array for a given type
static int _getnumadr(const mjModel* m, mjtObj type, int** padr, int* mapadr);

// Hash function (djb2 variant)
uint64_t mj_hashString(const char* s, uint64_t n);

// Name-to-ID lookup (returns -1 if not found)
int mj_name2id(const mjModel* m, int type, const char* name);

// ID-to-name lookup (returns NULL if not found)
const char* mj_id2name(const mjModel* m, int type, int id);

Import

#include "engine/engine_name.h"

I/O Contract

Inputs

Name Type Required Description
m const mjModel* Yes Model containing name arrays and hash maps
type int (mjtObj) Yes Object type enum (mjOBJ_BODY, mjOBJ_JOINT, etc.)
name const char* Yes (for name2id) String name to look up
id int Yes (for id2name) Integer ID to look up

Outputs

Name Type Description
return value (mj_name2id) int Object ID, or -1 if name not found
return value (mj_id2name) const char* Object name string, or NULL if ID invalid or unnamed
return value (mj_hashString) uint64_t Hash value modulo table size

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment