• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Offset in list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Offset in list


  • Subject: Re: Offset in list
  • From: kai <email@hidden>
  • Date: Tue, 15 Feb 2005 05:54:18 +0000


On Mon, 14 Feb 2005 09:14:13 -0500, Paul Skinner <email@hidden> wrote:


Thanks for condensing that Kai!

My pleasure, Paul.

I saw the trees, but the forest eluded me.

Ah yes - I know that feeling only too well myself. I find that a chain-saw can sometimes be quite helpful in such situations... ;-)


As for avoiding TIDs collisions, how about this? Do you see any method
to do this that doesn't duplicate data and without using 'contains'? On
large data sets both of these are limiting factors.

on itemIndices(i, l)
	set d to text item delimiters
	set AppleScript's text item delimiters to ""
	set listAsText to l as text
	repeat with c from 0 to 255
		set s to ASCII character c
		set text item delimiters to s
		if (length of text items of listAsText) is 1 then exit repeat
	end repeat
	set text item delimiters to s & s
	set l to s & l & s
	set text item delimiters to s & i & s
	set l to l's text items
	set text item delimiters to s
	set c to 0
	set i to {}
	set o to (count l) - 1
	repeat with n from 1 to o
		set c to (count l's item n's text items) div 2 + 1 + c
		set i's end to c
	end repeat
	set text item delimiters to d
	{occurrences:o, indices:i}
end itemIndices

Interesting. Seems like a pretty sensible approach to me. I tried a variation that considers a few additional issues, namely:


1) Using TIDs based on an extending string sequence, rather than simply different characters. The odds against a particular run of characters appearing in the search text are obviously going to be much higher than for any individual character. Of course, given this approach, there's nothing really wrong with repeating the odd character - although I haven't followed that particular route.

2) Randomising the string sequence, to reduce further the chance of a particular run appearing in the search text.

3) In spite of the above, retaining some front-loading of low-numbered ascii characters. So the TID string actually starts with a random sequence of ascii characters 1-8. These may be generally less likely to appear in search text than those from, say, conventionally typed text.

4) Using pre-evaluated characters, rather than converting ascii numbers at run time (which can slow things down a bit). I've included a randomisation/conversion routine (executed at compile time), which may also help to get around some of the problems caused by copying and pasting certain characters - not to mention transmitting them via email. For greater brevity, the resulting string could just be inserted into a script instead.

Anyway, just a few stray thoughts, FWIW. Hope there's something for you to play with here:

--------------------

script getRandomText
	on rnd(l)
		set r to {}
		set a to 1 - (l's item 1)
		repeat count l times
			set i to (some item of l's integers)
			set r's end to ASCII character (i - 1)
			set l's item (i + a) to ""
		end repeat
		r
	end rnd
	set l to {}
	repeat with n from 1 to 256
		set l's end to n
	end repeat
	set text item delimiters to {""}
	rnd(l's items 1 thru 9) & rnd(l's items 10 thru 256) as string
end script

property rTxt : run getRandomText (* or just insert the resulting string from 'getRandomText' *)

on itemIndices(i, l)
	set d to text item delimiters
	set text item delimiters to {""}
	set t to l as string
	repeat with n from 1 to 256
		set text item delimiters to rTxt's text 1 thru n
		if (count t's text items) is 1 then exit repeat
	end repeat
	set s to text item delimiters
	set text item delimiters to s & s
	set l to s & l & s
	set text item delimiters to s & i & s
	set l to l's text items
	set text item delimiters to s
	set c to 0
	set i to {}
	set o to (count l) - 1
	repeat with n from 1 to o
		set c to (count l's item n's text items) div 2 + 1 + c
		set i's end to c
	end repeat
	set text item delimiters to d
	{occurrences:o, indices:i}
end itemIndices

itemIndices("A", "AAabcdefghABCDEFabcABCaAA"'s items)
--> {occurrences:6, indices:{1, 2, 11, 20, 24, 25}}

--------------------

---
kai

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: Setting icon (Applescript-users Digest, Vol 2, Issue 108)
  • Next by Date: Re: Setting icon
  • Previous by thread: Re: Offset in list
  • Next by thread: Quoting
  • Index(es):
    • Date
    • Thread