linked list problem

Just starting out? Need help? Post your questions and find answers here.
#NULL
Addict
Addict
Posts: 1497
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

linked list problem

Post by #NULL »

Code: Select all

  ;in procedure, using global list

  If Not CountList(sgxLayeredView()) ; < empty lists do not pass
    ProcedureReturn
  EndIf
  ;Debug CountList(sgxLayeredView()) ; here i get values from 8 to 9
  FirstElement(sgxLayeredView())     ; < here the list ist not empty and should point to the first element
  Debug sgxLayeredView()             ; <<< here i get "[ERROR] The linked list doesn't have a current element" !
could someone give me a hint for an explanation?
#NULL
Addict
Addict
Posts: 1497
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Post by #NULL »

or even simpler:

Code: Select all

  Debug CountList(sgxLayeredView())       ; output: 9
  Debug FirstElement(sgxLayeredView())    ; output: 0
  Debug sgxLayeredView()                  ; ERROR
can this be my fault?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

That is strange.

Try a ForEach.. iteration to check that you can retrieve all the elements.

Can you perhaps post a little more code; showing the creation and the populating of the linked list?
I may look like a mule, but I'm not a complete ass.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Isn't it possible to have a linked list for which no element is currently selected?

cheers
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

If there are procedures involved is it possible that you are using a linked list outside of scope?

That is, for example, checking (countlist) outside of a procedure then doing the firstelement (which returns 0 so is saying no elements exist) inside a procedure?

If so, make it global newlist ..

If not ... mystery (until you show fuller code)
Dare2 cut down to size
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Isn't it possible to have a linked list for which no element is currently selected?
Indeed !

Code: Select all

NewList MyList()
AddElement(MyList())
MyList() = 1
AddElement(MyList())
MyList() = 2
;
; Linked List without current element
;
ResetList(MyList())
Debug CountList(MyList())
Debug MyList() ; ===========> no current element
But in his code, he uses FirstElement(), wich fails.
#NULL wrote:

Code: Select all

Debug FirstElement(sgxLayeredView())    ; output: 0
FirstElement(linkedlist()) : if the first item exists, this function will return a value which is not equal to zero. If the first element does not exist then it will return a value of zero.
#NULL wrote:

Code: Select all

Debug CountList(sgxLayeredView())       ; output: 9
If it were a scope problem, CountList(sgxLayeredView()) would fail I guess.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

He's also using a global linked list anyhow. No it doesn't seem to be a scope issue or one related to there not being a current element because of the use of FirstElement(). This is either a bug or there is something else going on here, some misuse of linked lists perhaps! :)
I may look like a mule, but I'm not a complete ass.
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

srod wrote:He's also using a global linked list anyhow.
You're right. I didn't notice that initial comment.
Dare2 cut down to size
ROUMANET
User
User
Posts: 12
Joined: Thu Aug 26, 2004 9:18 pm
Location: Isere (France)

Post by ROUMANET »

Hi there !

is this "bug" still there since PB 4.10 is officialy available ?
I have an application that's impacted and I need (at least) a workaround !!!

My code was working on PB 4.02... :cry:

Thanks :wink:
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

You'll need to show us some code.
I may look like a mule, but I'm not a complete ass.
ROUMANET
User
User
Posts: 12
Joined: Thu Aug 26, 2004 9:18 pm
Location: Isere (France)

Post by ROUMANET »

Sorry if the code is long but maybe I missed something that create the bug...

The problem occurs in GrapheStats() at the following line :
Entite()\Cumul = Entite()\Cumul + valeur

Thanks for your help :)
Comments are in French, you could guess my country :wink: sorry...

Code: Select all

Procedure GrapheStats(fichier$)
	; Cette procedure doit permettre de grapher les statistiques enregistrées par StaLaWa 2
	; 1) on lit l'index du fichier et on place les noms dans une liste chainée (structure NOM, index_ou_colonne, min, max, moy)
	; 2) on compte le nombre de ligne (NumberEchantillon) et on remplit déjà GlobalWAN et GlobalLAN. On créé une image (h x NumberEchantillon)
	; 3) on affiche dans une liste la liste des noms de WAN ou LAN
	; 4) on graphe GlobalLAN et GlobalWAN puis on copie cette image dans un buffer
	; 5) un clic sur le bouton [Graph Selected] entraine la lecture des champs sélectionnés (une couleur/champ pour chaque ligne)
	;
	Structure reference
		Nom.s			; nom du site
		index.l		; son N° de colonne dans le fichier stat (index)
		min.l			; données statistiques précalculées
		max.l
		moy.l
		Cumul.d
		rrel.d		; pourcentage par rapport à sa catégorie (LAN, WAN et CAST)
		rabs.d		; pourcentage par rapport aux cumuls totaux
	EndStructure
	
	
	CumulGWAN.d  = 0
	CumulGLAN.d  = 0
	CumulGCAST.d = 0
	
	NewList Entite.reference()
	
	Taille = 460	; taille du graphique en largeur
	Index = 5			; Les Cast (bradcast + Multicast)
	; 1) Lecture des index :
	If ReadFile(10, fichier$)
		; La lecture fichier peut être longue : affiche une petite fenêtre d'attente
		If OpenWindow(#Window_Wait, 10,10,150,50,"Analysing",#PB_Window_ScreenCentered) And CreateGadgetList(WindowID(#Window_Wait))
			TextGadget(#TxtWait,10,55,100,35,"Analyzing...")
		EndIf 
		
		; Analyse en cours...
		Legend$ = ReadString(10)
		If FindString(Legend$,Chr(9),1)																; on cherche les [tab] comme séparateur
			n = 0
			While StringField(Legend$,n,Chr(9)) > ""
				AddElement(Entite())
				Entite()\nom = StringField(Legend$,n,Chr(9))
				Entite()\Index = n
				Entite()\min = -1
				Entite()\max = 0
				Entite()\moy = 0
				Entite()\Cumul = 0
				Entite()\rrel = 0
				Entite()\rabs = 0
				n + 1
			Wend
		EndIf
		Debug "Nombre d'entité = "+Str(n)
		
		; 2) Remplissage des données : double-boucle
		While Not Eof(10)																; Tant que l'on n'est pas à la fin du fichier
			a$ = ReadString(10)															; on lit une ligne du fichier de stats
			NumberEchantillon = NumberEchantillon + 1				; on en profite pour compter le nombre d'échantillons (pour la moyenne)
			AddElement(LANWAN())														; et on prépare le graphique
			ResetList(Entite())															; on remet le pointeur de la liste chainée au début et		
			For t = 2 To n-1																	; on commence à 2, le premier champ étant la date (la liste commence à 0)
				valeur.l = Val(StringField(a$,t,Chr(9)))
				Select t																			; en fonction de la colonne, on cumule en WAN, en LAN ou en CAST
				Case 2																				; Colonne GlobalWAN
					CumulGWAN + valeur													; opération de cumul (pour moyenne)
					LANWAN()\dWAN = valeur
					If valeur > MaxGWAN
						MaxGWAN = valeur
					EndIf
				Case 3																				; même chose pour la colonne GlobalLAN
					CumulGLAN + valeur
					LANWAN()\dLAN = valeur
					If valeur > MaxGWAN
						MaxGLAN = valeur
					EndIf
				Case Index
					LANWAN()\dNET = valeur
				Case 6
					CumulGCAST + valeur
				EndSelect
				SelectElement(Entite(),t)
				Debug Str(NumberEchantillon) + " = "+ Str(CountList(Entite()))
				Entite()\Cumul = Entite()\Cumul + valeur
				If Valeur > Entite()\max											; Calcul de la valeur max
					Entite()\max = Valeur
				EndIf
				If Valeur < Entite()\Min											; Calcul de la valeur min
					Entite()\min = Valeur
				EndIf
				If Entite()\min = -1													; Cas particulier : la première valeur min
					Entite()\min = Valeur
				EndIf
				If t = 40000
				Debug "40000 -------------------------------"
				EndIf
			Next t
		Wend
		CloseFile(10)
	Else
		MessageRequester("File Reading error","Couldn't read Stats file.")
	EndIf
	; X) Vérification debug
	Debug "Nombre = "+Str(NumberEchantillon)
	Debug "Cumuls : LAN="+Str(CumulGLAN)+"  WAN="+Str(CumulGWAN)+"  CAST="+Str(CumulGCAST)
	Debug "----------------------"
	
	ResetList(Entite())
	t = 0
	ForEach Entite()																				; Prépare la liste à afficher : uniquement les sites actifs !
		If Entite()\Cumul > 0
			; Debug "---------------------------"
			Entite()\Moy = Int(Entite()\Cumul / NumberEchantillon)
			Entite()\rabs = Entite()\Cumul / (CumulGWAN+CumulGLAN+CumulGCAST) * 100
			If t > 2	And t < 7 ; Serveurs LAN
				Entite()\rrel = Int(Entite()\Cumul / CumulGLAN * 10000) / 100
			ElseIf t > 6 Or t = 2	; réseaux WAN
				Entite()\rrel = Int(Entite()\Cumul / CumulGWAN * 10000) / 100
			EndIf
			; chaine$ = Entite()\nom+"   [min:"+Str(Entite()\min)+" / moy:"+Str(Entite()\moy)+" / max:"+Str(Entite()\max)+" ] ==> Cumul = "+Str(Entite()\Cumul)+" bits" 
			; chaine$ + "      soit "+StrD(Entite()\rabs,2)+"% (relatif = "+StrD(Entite()\rrel,2)+"%)"
			; Debug chaine$
		EndIf
		t = t + 1
	Next
	
	; Affichage
	If IsWindow(#Window_Wait)
		CloseWindow(#Window_Wait)
	EndIf
	If OpenWindow(#Windows_Graph, 100, 250, 870, 245, "StaLaWa 2 - Grapher") And CreateGadgetList(WindowID(#Window_0))
		CreateGadgetList(WindowID(#Windows_Graph)) 
	  ListIconGadget(#Liste_Entites,2,10,385,180,"Sites actifs",100,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
	  AddGadgetColumn(#Liste_Entites,1,"% Global",55)
	  AddGadgetColumn(#Liste_Entites,2,"% Relatif",55)
	  AddGadgetColumn(#Liste_Entites,3,"Min",55)
	  AddGadgetColumn(#Liste_Entites,4,"Moy",55)
	  AddGadgetColumn(#Liste_Entites,5,"Max",55)
	  AddGadgetColumn(#Liste_Entites,6,"Cumul",55)
	  AddGadgetColumn(#Liste_Entites,7,"Index",40)
	  SelectElement(Entite(),1)
	  cpt = 0
	  While NextElement(Entite())
	  	; Debug Str(cpt)+"  --->  "+ Entite()\nom
	  	If Entite()\Cumul > 0 
	  		If Val(StrD(Entite()\Cumul)) = Entite()\Cumul				; Evites l'affichage disgracieux x.000000
	  			Cumul$ = Str(Entite()\Cumul)
	  		Else
	  			Cumul$ = StrD(Entite()\Cumul)
	  		EndIf
	  		a$ = Entite()\nom + Chr(10) + StrD(Entite()\Rabs,2) + Chr(10) + StrD(Entite()\Rrel,2) + Chr(10) + Str(Entite()\Min) + Chr(10)
	  		a$ + Str(Entite()\moy) + Chr(10) + Str(Entite()\Max) + Chr(10) + Cumul$ + Chr(10) + Str(Cpt)
	  		AddGadgetItem(#Liste_Entites,-1,a$)
  			SetGadgetItemColor(#Liste_Entites,0,#PB_Gadget_BackColor, RGB(64,127,255),-1)
  			SetGadgetItemColor(#Liste_Entites,1,#PB_Gadget_BackColor, RGB(64,224,240),-1)
  			SetGadgetItemColor(#Liste_Entites,index,#PB_Gadget_BackColor, RGB(224,0,0),-1)  		
	  	EndIf
	  	Cpt + 1
	  Wend
		TextGadget(#StringTOT,3,195,150,15,"Actives WAN Sites : "+Str(CountGadgetItems(#Liste_Entites)-4))
		ButtonGadget(#Button_GraphOne,	2,222,90,15,"Graph It")
		ButtonGadget(#Button_CreateList,100,222,90,15,"Create WAN list")
		ButtonGadget(#Button_CreateStat,198,222,90,15,"Create Excel Stats")
		ButtonGadget(#Button_ExportStat,296,222,90,15,"Copy Report")
		TrackBarGadget(#Zoom, 180,195,200,15,1,50,#PB_TrackBar_Ticks)
		GadgetToolTip(#Zoom,"Zoom : from x1 on left, to x64 on right")
		
		SetGadgetState(#Liste_Entites,3)
		Colonne = Val(GetGadgetItemText(#Liste_Entites,GetGadgetState(#Liste_Entites),7))
		GrapheOne(fichier$,	Colonne,GetGadgetState(#Zoom),1)
	  ; Create a gadget to display our nice image

	EndIf
EndProcedure
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

I assume your problem is the LL doesn't have a current element ?
Maybe

Code: Select all

SelectElement(Entite(),t)
fails ?
Try a ForEach/Loop to select the element.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Roumanet, it would help if we code which we could run! :?
I may look like a mule, but I'm not a complete ass.
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Post by Demivec »

@Roumanet:
you need to include the file to be read, the global declaration of LANWAN() and a call to GrapheStats() to round out the sample code (at least). It can't be tested without these.
Post Reply