$TYPECHECK ON
TYPE QHash EXTENDS QOBJECT
keys AS QSTRINGLIST
values AS QSTRINGLIST
pointer AS INTEGER
SUB SET (k AS STRING, v AS STRING)
WITH QHash
DIM l AS INTEGER
l=.keys.indexof(k)
IF l>0 THEN
.keys.delitems l
.values.delitems l
END IF
.keys.additems k
.values.additems v
END WITH
END SUB
FUNCTION itemcount AS INTEGER
WITH QHash
Result=.keys.itemcount
END WITH
END FUNCTION
FUNCTION GET (k AS STRING) AS STRING
WITH QHash
DIM l AS INTEGER
l=.keys.indexof(k)
IF l>=0 THEN
Result=.values.item(l)
ELSE
Result=""
END IF
END WITH
END FUNCTION
FUNCTION exists (k AS STRING) AS INTEGER
WITH QHash
Result=(.keys.indexof(k)>=0)
END WITH
END FUNCTION
SUB del (k AS STRING)
WITH QHash
DIM l AS INTEGER
l=.keys.indexof(k)
IF l>=0 THEN
.keys.delitems l
.values.delitems l
END IF
END WITH
END SUB
SUB clear
WITH QHash
.keys.clear
.values.clear
END WITH
END SUB
FUNCTION key (i AS INTEGER) AS STRING
WITH QHash
Result=.keys.item(i)
END WITH
END FUNCTION
FUNCTION value (i AS INTEGER) AS STRING
WITH QHash
Result=.values.item(i)
END WITH
END FUNCTION
END TYPE
DIM header AS QHash
header.SET("Host","www.yahoo.com")
header.SET("Date","12:37:44 GMT")
header.SET("X-cache","yes")
DIM i AS INTEGER
FOR i = 0 TO header.itemcount-1
PRINT header.key(i)+"="+header.value(i)
NEXT i
PRINT
PRINT "X-cache="+header.GET("X-cache")
PRINT "delete X-cache..."
header.del "X-cache"
IF header.exists("X-cache") THEN
PRINT header.GET("X-cache")
ELSE
PRINT "X-cache does not exist"
END IF
PRINT "Clean the whole hash"
header.clear
PRINT "Host="+header.GET("Host")
|