Как использовать stdext:: hash_map?

Реализуйте то, что вам нужно, но это основа.

using UnityEngine;

public class Test : MonoBehaviour
{
    private float distance = 10;
    private float offset = -4;

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Mouse1))
        {
            GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);

            go.transform.position = new Vector3
            {
                x = offset += 1.5f,
                y = 0,
                z = 0
            };
        }

        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            if(Physics.Raycast(ray, out RaycastHit hit, distance))
            {
                Destroy(hit.transform.gameObject);
            }
        }
    }
}
7
задан batty 16 May 2009 в 06:32
поделиться

3 ответа

Это как вы можете это сделать

class MyClass_Hasher {
     const size_t bucket_size = 10; // mean bucket size that the container should try not to exceed
     const size_t min_buckets = (1 << 10); // minimum number of buckets, power of 2, >0
     MyClass_Hasher() {
          // should be default-constructible
     }
     size_t operator()(const MyClass &key) {
             size_t hash_value;
             // do fancy stuff here with hash_value
             // to create the hash value. There's no specific
             // requirement on the value.
             return hash_value;
     }

     bool operator()(const MyClass &left, const MyClass &right) {
            // this should implement a total ordering on MyClass, that is
            // it should return true if "left" precedes "right" in the ordering
     }
 };

Затем вы можете просто использовать

stdext::hash_map my_map<MyClass, MyValue, MyClass_Hasher>
8
ответ дан 7 December 2019 в 03:20
поделиться

Вот пример из MSDN

1
ответ дан 7 December 2019 в 03:20
поделиться

I prefer using a non-member function.

The method expained in the Boost documentation article Extending boost::hash for a custom data type seems to work.

0
ответ дан 7 December 2019 в 03:20
поделиться
Другие вопросы по тегам:

Похожие вопросы: