- Joined
- Apr 30, 2011
- Messages
- 359
JASS:
//========================================================================================
//
// Integer Indexer
// -*- overcold_ice -*-
//
// -[*] Requirements:
// - JNGP
// - latest version of JassHelper
//
// -[*] Optional Requirements:
// - /*New*/ Table [url]http://www.hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/[/url]
//
// For your almost unlimitted integer-indexing needs
// Supports large and small indexing.
//
// -[*] API:
//
// function GetIntLId takes integer i returns integer
// function GetIntByLId takes integer i returns integer
//
// function GetIntSId takes integer i returns integer
// function GetIntBySId takes integer i returns integer
//
//========================================================================================
library IntegerIndexer requires optional /*New*/Table
//====================================================================================
// G L O B A L S
//====================================================================================
//===---
// Large Index Globals
//===---
globals
private key id
private key int
private integer c
endglobals
static if LIBRARY_Table then
private module TableInit
private static method onInit takes nothing returns nothing
set .t = TableArray [2]
endmethod
endmodule
endif
private struct T
static if LIBRARY_Table then
static TableArray t
implement TableInit
else
static hashtable t
endif
endstruct
//===---
// Small Index Globals
//===---
globals
private integer array value
private integer array index
private integer count = 0
endglobals
//====================================================================================
// A P I
//====================================================================================
//===---
// Large Index API
//===---
function GetIntLId takes integer i returns integer
static if LIBRARY_Table then
if T.t [id].has(i) then
return T.t [id] [i]
else
set T.t [id] [i] = c
set T.t [int] [c] = i
endif
else
if HaveSavedInteger(T.t, id, i) then
return LoadInteger(T.t, id, i)
else
call SaveInteger(T.t, id, i, c)
call SaveInteger(T.t, int, c, i)
endif
endif
set c = c + 1
return c - 1
endfunction
function GetIntByLId takes integer i returns integer
static if LIBRARY_Table then
return T.t [int] [i]
else
return LoadInteger(T.t, int, i)
endif
endfunction
//===---
// Small Index API
//===---
function GetIntSId takes integer i returns integer
if index [i] != 0 then
return index [i]
else
set count = count + 1
set index [i] = count
set value [count] = i
endif
return count
endfunction
function GetIntBySId takes integer i returns integer
return value [i]
endfunction
endlibrary
Last edited: