Jump to content
Sign in to follow this  
marko001

Relationships between strings

Recommended Posts

marko001

Hi all,

just a tricky request:

which are the relationships between strings?

I mean, when it can happen then

$vValue < $avArray[$iMid]
 
given, for example,
 
$value = <z:row c0='Sims2000' Platform='DS'
$avArray[$iMid] = <z:row c0='AlphaZero' Platform='Wii' Price='12.99'/>

?

This is simpy part of _arraybinarysearch() and I can't understand when a given string is lower or higher than another one

_arraybinarysearch() uses a binary method to search trough array and given the result ($vValue < $avArray[$iMid]) it gives a +/- 1 to $mid and cycle again

My tries always return the relationship with "<" but I can't understand which logic is used to set a value lower or higher than another one..

M.

Share this post


Link to post
Share on other sites
czardas

I'm going to hazard a guess, since the code you posted doesn't use _ArrayBinarySearch. Binary representations of strings are numerical. Perhaps that's the answer?

Edited by czardas

Share this post


Link to post
Share on other sites
BrewManNH

I'm going to hazard a guess, since the code you posted doesn't use _ArrayBinarySearch. Binary representations of strings are numerical. Perhaps that's the answer?

The Binary part of it's name isn't because it uses binary comparisons,it's because the type of search it does is called that. It takes your search pattern, and looks at the halfway point in the array for it, if it's higher it jumps 50% higher into the array to see if it's there, if it's lower it searches 50% lower in the array. By dividing the remaining portion of the array by 50% every iteration it finds the string faster than searching the whole string one item at a time. This is why the array has to be sorted for it to work correctly, because otherwise you will either not find the pattern or it will take a very long time.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
czardas

BrewManNH

Thanks for the explanation. I never used _ArrayBinarySearch, but the name is clearly misleading. Coming from a different background I am often bemused by programming terms: Had the function been called _ArrayDeadReckoningSearch it would have made perfect sense to me. As it stands, it just seems to be a misnomer. Perhaps I've been out of school too long. :graduated:

Edited by czardas

Share this post


Link to post
Share on other sites
BrewManNH

I didn't understand what it meant when I first ran across it myself, the name didn't go with what it did in my mind until I looked it up. I think that this article might explain it a bit better. It's a little confusing but you get the highlights of how it's supposed to work and why it's named what it is. Other than the fact that it needs a sorted array to work correctly, and the current version of it only works on 1D arrays, I'm surprised it isn't used more for large array searching.

BTW, I have created a 2D version of it that searches a sub-item ("column") of the 2D array, the _Array.au3 link in my signature links to a modified Array.au3 file that includes several modified 2D capable array functions.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
czardas

Thanks I'll take a look. Actually Dead Reckoning is not the term I'm looking for although its similar. The term I am looking for is what drafsten have always done with a compass Well anyway, its always good to learn new stuff. ;)

I get the binary part now, although :graduated:

Edited by czardas

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • nooneclose
      By nooneclose
      I need help turning this string "20180913221626" into a formatted time string.
      I need to go from this: 20180913221626
      to this: 09/13/2018 10:16 PM
      I do not always know what the date will be so I can not just use a variable I need to actually convert/format. 
      I did see an older post in the forms that was basically the same question only the other guy did not post the working code and I can not figure out how to use _AD_GetObjectProperties properly to get what I want. 
      As always any help would be appreciated. 
      Here is the code I use to find the date, but it always gives me the unformatted version. 
      ;retrieve the items object $oItem = $oOutlook.Session.GetItemFromID($aItems[1][0], Default) $oItem.GetInspector $eSentOn = $oItem.SentOn ; When was the email sent? MsgBox("", "Sent On of the email", $eSentOn) ;******************************************************************************* ; Formats the date and time from the email ;******************************************************************************* ;Local $fDatenTime = _DateTimeFormat($eSentOn, 1) ;MsgBox("", "Formatted email time", $fDatenTime) $aProperties = _AD_GetObjectProperties($eSentOn) _ArrayDisplay($aProperties, "Did the conversion work?")  
    • nooneclose
      By nooneclose
      My program has to first search for names in Column D that do not match up with column C. I got that search to work using arrays. It was slow and I could not figure out how to delete them so I just manually put coded the names that do not belong. I found their cell location but I do not know how to store that location and delete it.
      This is what I have so far.
      Local $NameToDelete1[6]  = _Excel_RangeFind($OpenWorkbook, "Smith, Bill") _ArrayDisplay($NameToDelete1, "Excel UDF: _Excel_RangeFind Example 1", "", 0, "|", "Sheet|Name|Cell|Value|Formula|Comment") _Excel_RangeDelete($OpenWorkbook.ActiveSheet, $NameToDelete1[2], $xlShiftUp)  
      Please help, I wanted to have this program done yesterday but I did not see this problem until yesterday. 
    • Miliardsto
      By Miliardsto
      I got that func
      Func makeHelpImgGUI($title,$width,$height,$img) $img = GUICtrlCreatePic("",20,40,$width,$height) _ResourceSetImageToCtrl($img, "HERE") EndFunc and I call this func like that
      makeHelpImgGUI("Image",1190, 800,$SETTINGS_JPG)  
      so what is the problem in the parameter where is - "HERE" I need value of img but passed as string
      so $img = $SETTINGS_JPG and how make it "SETTINGS_JPG"
       
      I tried something like that but not work
      Func makeHelpImgGUI($title,$width,$height,$img) $name_str = String($img) $name_str = StringTrimLeft ($name_str, 1 ) $img = GUICtrlCreatePic("",20,40,$width,$height) _ResourceSetImageToCtrl($img, $name_str) EndFunc  
    • liagason
      By liagason
      Hello everyone,
      How can I display in ascending  sequence some numbers stored in a string variable?
      $str = "18,03,48,23" MsgBox(0,"test",$str) I would like it to display "03,18,23,48"
    • Rskm
      By Rskm
      Hi, I have the following line in a text file 'input.txt'. I know the line number - say '6'. I wish to replace the text 'WWW' in the below line with a random number (I can generate that with random()).
      WERIS  WWWJP   3.83  8.330  1.000                1097.RAXX 
      The WWW is a 3 digit integer (could be any number between 0 to 999), I can use stringtrimleft and get the numerical value of WWW in this file
      so, basically, I know the string to replace (ie; WWW stored in a variable), I know the line number to work on and the file location/name and the replacement variable (through random()). My requirement is to fill that 3 spaces with my random number (which Is a integer between 1 and 999)
      please put ur suggestions
       
×