• UniqueKeys
    5 replies, posted
Anybody have any ideas on how to generate a UniqueKey ( an Integer ) that can support up to 100,000 unique entries? I'm kinda stumped on this one, I've investigated using Time as a key gen, but multiple entries can be created at once, thus it is not unique.
Can you tell why you need that? There might be alternatives.
I have a large list of Entities, and I need to be able to access them in a table quickly, if I have a unique ID i can do that quickly. However I need to be able to add and remove them efficiently, because the props will be added and removed, and If i have to loop through a table 100,000 ( This obviously is worse case scenario ) every time I add and remove a prop its gonna be a bad time.
Entity:EntIndex()? Entity:GetCreationID()?
[QUOTE=Noobulater;41174949]I have a large list of Entities, and I need to be able to access them in a table quickly, if I have a unique ID i can do that quickly. However I need to be able to add and remove them efficiently, because the props will be added and removed, and If i have to loop through a table 100,000 ( This obviously is worse case scenario ) every time I add and remove a prop its gonna be a bad time.[/QUOTE] You could use the entity as a key and the unique ID as the value.
[QUOTE=Chessnut;41177215]You could use the entity as a key and the unique ID as the value.[/QUOTE] Actually, any value would do. [lua] -- Creates an empty table Entities = {} -- Adds an entity to the table Entities[ent] = true -- Removes an entity from the table Entities[ent] = nil -- Check if the table contains a given entity if Entities[ent] then print("ok") end -- Loop through all entities in the table for ent, _ in pairs(Entities) do print(ent) end [/lua]
Sorry, you need to Log In to post a reply to this thread.