summaryrefslogtreecommitdiff
path: root/ecs/src/archetype.rs
blob: a33de66ba064b37e39b58aa5de7081a9737e8766 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use std::hash::{DefaultHasher, Hash, Hasher};

use crate::component::Id as ComponentId;

/// Archetype ID.
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct Id
{
    hash: u64,
}

impl Id
{
    /// Returns the ID of a archetype with the given components.
    pub fn new(component_ids: impl IntoIterator<Item = ComponentId>) -> Self
    {
        let mut hasher = DefaultHasher::new();

        for component_id in component_ids {
            component_id.hash(&mut hasher);
        }

        let hash = hasher.finish();

        Self { hash }
    }
}