Bon... (Un peu plus dans le sujet!) J'ai fait un espèce de tuto sous forme de code. J'espère que ça passe chez tout le monde.
Kcc, n'hésite pas à poser des questions dans le plus correct des repsects pour toi-même! ça ne changera pas la gueule des réponses!
Code : Tout sélectionner
Global BaseW.I
Global BaseH.I
Procedure Base(w, h)
BaseW = w
BaseH = h
EndProcedure
Procedure.I W(N.I, D.I)
Protected Result.I
Result = BaseW * N / D
ProcedureReturn Result
EndProcedure
Procedure.I H(N.I, D.I)
Protected Result.I
Result = BaseH * N / D
ProcedureReturn Result
EndProcedure
Procedure Arrow(X.F, Y.F, DX.F, DY.F)
Line(X, Y, DX, DY)
Line(X + DX - 10, Y - 5, 10, 5, #Black)
Line(X + DX - 10, Y + 5, 10, -5, #Black)
EndProcedure
Procedure SemiBoxU(X, Y, DX, DY)
Box(X, Y + 1, DX, DY, #Black)
Box(X + 1, Y + 1, DX - 2, DY - 2, #White)
EndProcedure
Procedure SemiBoxn(X, Y, DX, DY)
Box(X, Y, DX, DY - 1, #Black)
Box(X + 1, Y + 1, DX - 2, DY - 2, #White)
EndProcedure
Procedure Aff(X, Y, Text.S)
DrawText(X + 16, Y + 10, Text)
EndProcedure
ExamineDesktops()
Dw = DesktopWidth(0)
Dh = DesktopHeight(0)
Dd = DesktopDepth(0)
Base(Dw, Dh)
OpenWindow(0, 0, 0, 0, 0, "I. Extraction d'un numéro d'alvéole à partir du contenu d'une chaîne", $1CF0001)
CreateImage(0, Dw, Dh)
StartDrawing(ImageOutput(0) )
Chaine.S = "Moi, c'est Dudu..."
MD5.S = MD5Fingerprint(@Chaine, Len(Chaine) )
MD524.S = Left(MD5, 6)
Addr.I = Val("$" + MD524)
Box(0, 0, W(1, 1), H(1, 1), #White)
DrawText(W(1, 16), H(1, 16), "1) Exemple de chaîne : " + Chr(34) + Chaine + Chr(34) )
DrawText(W(1, 16), H(2, 16), "2) Empreinte MD5 128 bits de " + Chr(34) + Chaine + Chr(34) )
DrawText(W(1, 16), H(3, 16), "= 0x " + MD5 + " (hexa)")
DrawText(W(1, 16), H(4, 16), "3) Troncature à 24 bits ( ~ 16 millions de possibilités)")
DrawText(W(1, 16), H(5, 16), "= 0x " + MD524 + " (hexa)")
DrawText(W(1, 16), H(6, 16), "4) Conversion Hexadécimal/Décimal")
DrawText(W(1, 16), H(7, 16), "= " + Str(Addr) )
DrawText(W(1, 16), H(8, 16), "Donc " + Chr(34) + Chaine + Chr(34) + " occupera l'alvéole n°" + Str(Addr) )
StopDrawing()
ImageGadget(0, 0, 0, Dw, Dh, ImageID(0) )
Repeat
Evt = WaitWindowEvent()
Until Evt = 16 Or Evt = #PB_Event_Gadget
CloseWindow(0)
OpenWindow(0, 0, 0, 0, 0, "II. Définition d'une alvéole", $1CF0001)
CreateImage(0, Dw, Dh)
StartDrawing(ImageOutput(0) )
Chaine.S = "Moi, c'est Dudu..."
MD5.S = MD5Fingerprint(@Chaine, Len(Chaine) )
MD524.S = Left(MD5, 6)
Addr.I = Val("$" + MD524)
Box(0, 0, W(1, 1), H(1, 1), #White)
DrawText(W(1, 16), H(1, 16), "Une alvéole c'est une cellule mémoire." )
DrawText(W(1, 16), H(2, 16), "Précédemment, on a vu qu'un numéro d'alvéole s'étendait sur 24 bits.")
DrawText(W(1, 16), H(3, 16), "24 bits, c'est environ 16 millions de possibilités (exactement 2 puissance 24 = " + Str(1 << 24) + " possibilités)")
DrawText(W(1, 16), H(4, 16), "Une cellule mémoire doit contenir le minimum élémentaire pour décrire un objet.")
DrawText(W(1, 16), H(5, 16), "Dans notre cas, les objets sont des chaînes donc un pointeur est suffisant.")
DrawText(W(1, 16), H(6, 16), "Un pointeur 32 bits, c'est 4 octets (XP/Linux).")
DrawText(W(1, 16), H(7, 16), "Sous Vista (64 bits), c'est 8 octets.")
DrawText(W(1, 16), H(9, 16), "Résultat, le tableau des alvéoles fera 4 * 16 millions d'octets dans les cas généraux,")
DrawText(W(1, 16), H(10, 16), "et 8 * 16 millions d'octets sous Vista.")
DrawText(W(1, 16), H(12, 16), "XP/Linux : 64Mo d'allocation mémoire")
DrawText(W(1, 16), H(13, 16), "Vista : 128Mo d'allocation mémoire")
StopDrawing()
ImageGadget(0, 0, 0, Dw, Dh, ImageID(0) )
Repeat
Evt = WaitWindowEvent()
Until Evt = 16 Or Evt = #PB_Event_Gadget
CloseWindow(0)
OpenWindow(0, 0, 0, 0, 0, "III. Occupation d'une alvéole", $1CF0001)
CreateImage(0, Dw, Dh)
StartDrawing(ImageOutput(0) )
Chaine.S = "Moi, c'est Dudu..."
MD5.S = MD5Fingerprint(@Chaine, Len(Chaine) )
MD524.S = Left(MD5, 6)
Addr.I = Val("$" + MD524)
Box(0, 0, W(1, 1), H(1, 1), #White)
DrawText(W(1, 16), H(1, 16), "Il y a trois manières d'occuper une alvéole." )
DrawText(W(1, 16), H(3, 16), "1) L'alvéole est vide")
DrawText(W(1, 16), H(4, 16), "Il n'y a pas de chaîne qui corresponde à cette alvéole.")
DrawText(W(1, 16), H(5, 16), "Son contenu est nul ( = 0).")
DrawText(W(1, 16), H(7, 16), "2) L'alvéole contient un pointeur direct.")
DrawText(W(1, 16), H(8, 16), "Une seule chaîne dans la base de donnée correspond à cette alvéole.")
DrawText(W(1, 16), H(9, 16), "L'alvéole contient l'adresse (ou pointeur) vers la chaîne en question.")
DrawText(W(1, 16), H(11, 16), "3) L'alvéole contient un pointeur indirect.")
DrawText(W(1, 16), H(12, 16), "Dans ce cas, plusieurs chaîne correspondent à cette alvéole.")
DrawText(W(1, 16), H(13, 16), "Tout comme le MD5 est une méthode que j'ai choisi, et que mes choix ne sont qu'à")
DrawText(W(1, 16), H(14, 16), "titre d'exemple, dans ce cas où il y a " + Chr(34) + "collision" + Chr(34) + " (plusieurs chaînes pour une seule alvéole) ...")
StopDrawing()
ImageGadget(0, 0, 0, Dw, Dh, ImageID(0) )
Repeat
Evt = WaitWindowEvent()
Until Evt = 16 Or Evt = #PB_Event_Gadget
CloseWindow(0)
OpenWindow(0, 0, 0, 0, 0, "III. Occupation d'une alvéole (suite)", $1CF0001)
CreateImage(0, Dw, Dh)
StartDrawing(ImageOutput(0) )
Chaine.S = "Moi, c'est Dudu..."
MD5.S = MD5Fingerprint(@Chaine, Len(Chaine) )
MD524.S = Left(MD5, 6)
Addr.I = Val("$" + MD524)
Box(0, 0, W(1, 1), H(1, 1), #White)
DrawText(W(1, 16), H(1, 16), "... J'ai choisi de créer une table intermédiaire." )
DrawText(W(1, 16), H(2, 16), "Elle contient :")
DrawText(W(1, 16), H(4, 16), "- une marque d'identification (pour ne pas la confondre avec une chaîne)" )
DrawText(W(1, 16), H(5, 16), "- le nombre de pointeurs de chaînes (minimum = 2)" )
DrawText(W(1, 16), H(6, 16), "- les pointeurs, les uns après les autres." )
StopDrawing()
ImageGadget(0, 0, 0, Dw, Dh, ImageID(0) )
Repeat
Evt = WaitWindowEvent()
Until Evt = 16 Or Evt = #PB_Event_Gadget
CloseWindow(0)
OpenWindow(0, 0, 0, 0, 0, "IV. Schématique", $1CF0001)
CreateImage(0, Dw, Dh)
StartDrawing(ImageOutput(0) )
Chaine.S = "Moi, c'est Dudu..."
MD5.S = MD5Fingerprint(@Chaine, Len(Chaine) )
MD524.S = Left(MD5, 6)
Addr.I = Val("$" + MD524)
Box(0, 0, W(1, 1), H(1, 1), #White)
For Y = 0 To 10
If Y = 0
SemiBoxU(W(1, 8), H(1, 8) + 32 * Y, 96, 32)
Else
If Y = 10
SemiBoxn(W(1, 8), H(1, 8) + 32 * Y, 96, 32)
Else
Box(W(1, 8), H(1, 8) + 32 * Y, 96, 32, #Black)
Box(W(1, 8) + 1, H(1, 8) + 1 + 32 * Y, 94, 30, #White)
EndIf
EndIf
If Y = 1
Aff(W(1, 8), H(1, 8) + 32 * Y, "*ChaineX")
EndIf
If Y = 3
Aff(W(1, 8), H(1, 8) + 32 * Y, "*NodeX")
EndIf
Next Y
Arrow(W(1, 8) + 128, H(1, 8) + 48, 256.0, 0.0)
Aff(W(1, 8) + 128 + 256, H(1, 8) + 32, Chr(34) + "Chaine Dudu" + Chr(34) )
Arrow(W(1, 8) + 128, H(1, 8) + 48 + 64, 64.0, 0.0)
Arrow(W(3, 8) + 128, H(1, 8) + 48 + 64 + 64, 64.0, 0.0)
Aff(W(3, 8) + 128 + 64, H(1, 8) + 48 + 64 + 48, Chr(34) + "Chaine Dédé" + Chr(34) )
Arrow(W(3, 8) + 128, H(1, 8) + 48 + 64 + 96, 64.0, 0.0)
Aff(W(3, 8) + 128 + 64, H(1, 8) + 48 + 64 + 80, Chr(34) + "Chaine Nono" + Chr(34) )
For Y = 0 To 4
If Y = 4
SemiBoxn(W(3, 8), H(1, 8) + 96 + 32 * Y, 96, 32)
Else
Box(W(3, 8), H(1, 8) + 96 + 32 * Y, 96, 32, #Black)
Box(W(3, 8) + 1, H(1, 8) + 97 + 32 * Y, 94, 30, #White)
EndIf
If Y = 0
Aff(W(3, 8), H(1, 8) + 96 + 32 * Y, "Id (*Node)")
EndIf
If Y = 1
Aff(W(3, 8), H(1, 8) + 96 + 32 * Y, "Nb d'adr.")
EndIf
If Y = 2
Aff(W(3, 8), H(1, 8) + 96 + 32 * Y, "*Adr1")
EndIf
If Y = 3
Aff(W(3, 8), H(1, 8) + 96 + 32 * Y, "*Adr2")
EndIf
If Y = 4
Aff(W(3, 8), H(1, 8) + 96 + 32 * Y, "...")
EndIf
Next Y
StopDrawing()
ImageGadget(0, 0, 0, Dw, Dh, ImageID(0) )
Repeat
Evt = WaitWindowEvent()
Until Evt = 16 Or Evt = #PB_Event_Gadget
CloseWindow(0)
End