The Trunk: Collections-eem.760.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

The Trunk: Collections-eem.760.mcz

commits-2
Eliot Miranda uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-eem.760.mcz

==================== Summary ====================

Name: Collections-eem.760
Author: eem
Time: 12 July 2017, 5:29:57.850345 pm
UUID: 622a9db4-e0d8-4c28-886a-d9b71a8fac49
Ancestors: Collections-pre.759

Make Interval>>, answer another Interval if possible, so that (1 to: 2), (3 to: 4) answers (1 to: 4) not #(1 2 3 4).

Correct a misapprension in String>>hash.

Use the preferred var:type: and nuke an unused declaration in some translated primitives.

=============== Diff against Collections-pre.759 ===============

Item was changed:
  ----- Method: ByteString class>>indexOfAscii:inString:startingAt: (in category 'primitives') -----
  indexOfAscii: anInteger inString: aString startingAt: start
 
  | stringSize |
  <primitive: 'primitiveIndexOfAsciiInString' module: 'MiscPrimitivePlugin'>
+ <var: #aString type: #'unsigned char *'>
- <var: #aCharacter declareC: 'int anInteger'>
- <var: #aString declareC: 'unsigned char *aString'>
 
  stringSize := aString size.
  start to: stringSize do: [:pos |
  (aString basicAt: pos) = anInteger ifTrue: [^ pos]].
 
+ ^ 0!
- ^ 0
- !

Item was changed:
  ----- Method: ByteString>>findSubstring:in:startingAt:matchTable: (in category 'comparing') -----
  findSubstring: key in: body startingAt: start matchTable: matchTable
  "Answer the index in the string body at which the substring key first occurs, at or beyond start.  The match is determined using matchTable, which can be used to effect, eg, case-insensitive matches.  If no match is found, zero will be returned.
 
  The algorithm below is not optimum -- it is intended to be translated to C which will go so fast that it wont matter."
  | index |
  <primitive: 'primitiveFindSubstring' module: 'MiscPrimitivePlugin'>
+ <var: #key type: #'unsigned char *'>
+ <var: #body type: #'unsigned char *'>
+ <var: #matchTable type: #'unsigned char *'>
- <var: #key declareC: 'unsigned char *key'>
- <var: #body declareC: 'unsigned char *body'>
- <var: #matchTable declareC: 'unsigned char *matchTable'>
 
  key size = 0 ifTrue: [^ 0].
  (start max: 1) to: body size - key size + 1 do:
  [:startIndex |
  index := 1.
+ [(matchTable at: (body basicAt: startIndex+index-1) + 1)
+ = (matchTable at: (key basicAt: index) + 1)]
+ whileTrue:
- [(matchTable at: (body basicAt: startIndex+index-1) + 1)
- = (matchTable at: (key basicAt: index) + 1)]
- whileTrue:
  [index = key size ifTrue: [^ startIndex].
  index := index+1]].
  ^ 0
  "
  ' ' findSubstring: 'abc' in: 'abcdefabcd' startingAt: 1 matchTable: CaseSensitiveOrder 1
  ' ' findSubstring: 'abc' in: 'abcdefabcd' startingAt: 2 matchTable: CaseSensitiveOrder 7
  ' ' findSubstring: 'abc' in: 'abcdefabcd' startingAt: 8 matchTable: CaseSensitiveOrder 0
  ' ' findSubstring: 'abc' in: 'abcdefABcd' startingAt: 2 matchTable: CaseSensitiveOrder 0
  ' ' findSubstring: 'abc' in: 'abcdefABcd' startingAt: 2 matchTable: CaseInsensitiveOrder 7
  "!

Item was added:
+ ----- Method: Interval>>, (in category 'adding') -----
+ , otherCollection
+ "Override to answer an Interval if otherCollection is an adjacent and congruent interval."
+ ^(otherCollection isInterval
+  and: [otherCollection increment = step
+  and: [otherCollection first = (self last + step)]])
+ ifTrue: [self class from: start to: otherCollection last by: step]
+ ifFalse: [super, otherCollection]!

Item was changed:
  ----- Method: String>>hash (in category 'comparing') -----
  hash
  "#hash is implemented, because #= is implemented"
  "ar 4/10/2005: I had to change this to use ByteString hash as initial
  hash in order to avoid having to rehash everything and yet compute
  the same hash for ByteString and WideString.
  md 16/10/2006: use identityHash as initialHash, as behavior hash will
+ use String hash (name) to have a better hash soon.
+ eem 4/17/2017 it's not possible to use String hash (name) for the
+ initial hash because that would be recursive."
+ ^self class stringHash: self initialHash: ByteString identityHash!
-     use String hash (name) to have a better hash soon"
- ^ self class stringHash: self initialHash: ByteString identityHash!


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: The Trunk: Collections-eem.760.mcz

Chris Muller-3
Hmmm...

Yeeeeah buddy, I think I like this... I'm seeing nothing but
positives.  It's more beautifully abstract and efficient to stay with
Intervals if you can, and one can opt-out by sending #asArray, if
necessary, but probably won't be.

You may be interested in my "IntervalCollection" class, which keeps
efficient track of a collection of intervals.  As intervals are added
that intersect or are within the #proximityThreshold of existing
intervals, the existing interval is enlarged to include for the new
interval.

To see:

"do it"
Installer new merge: #maInstaller.
(Smalltalk classNamed: #MaInstaller) new merge: #base.
(Smalltalk classNamed: #MaIntervalCollection) browse

It's 10 methods in total, but was only ever lightly used.


On Wed, Jul 12, 2017 at 7:30 PM,  <[hidden email]> wrote:

> Eliot Miranda uploaded a new version of Collections to project The Trunk:
> http://source.squeak.org/trunk/Collections-eem.760.mcz
>
> ==================== Summary ====================
>
> Name: Collections-eem.760
> Author: eem
> Time: 12 July 2017, 5:29:57.850345 pm
> UUID: 622a9db4-e0d8-4c28-886a-d9b71a8fac49
> Ancestors: Collections-pre.759
>
> Make Interval>>, answer another Interval if possible, so that (1 to: 2), (3 to: 4) answers (1 to: 4) not #(1 2 3 4).
>
> Correct a misapprension in String>>hash.
>
> Use the preferred var:type: and nuke an unused declaration in some translated primitives.
>
> =============== Diff against Collections-pre.759 ===============
>
> Item was changed:
>   ----- Method: ByteString class>>indexOfAscii:inString:startingAt: (in category 'primitives') -----
>   indexOfAscii: anInteger inString: aString startingAt: start
>
>         | stringSize |
>         <primitive: 'primitiveIndexOfAsciiInString' module: 'MiscPrimitivePlugin'>
> +       <var: #aString type: #'unsigned char *'>
> -       <var: #aCharacter declareC: 'int anInteger'>
> -       <var: #aString declareC: 'unsigned char *aString'>
>
>         stringSize := aString size.
>         start to: stringSize do: [:pos |
>                 (aString basicAt: pos) = anInteger ifTrue: [^ pos]].
>
> +       ^ 0!
> -       ^ 0
> - !
>
> Item was changed:
>   ----- Method: ByteString>>findSubstring:in:startingAt:matchTable: (in category 'comparing') -----
>   findSubstring: key in: body startingAt: start matchTable: matchTable
>         "Answer the index in the string body at which the substring key first occurs, at or beyond start.  The match is determined using matchTable, which can be used to effect, eg, case-insensitive matches.  If no match is found, zero will be returned.
>
>         The algorithm below is not optimum -- it is intended to be translated to C which will go so fast that it wont matter."
>         | index |
>         <primitive: 'primitiveFindSubstring' module: 'MiscPrimitivePlugin'>
> +       <var: #key type: #'unsigned char *'>
> +       <var: #body type: #'unsigned char *'>
> +       <var: #matchTable type: #'unsigned char *'>
> -       <var: #key declareC: 'unsigned char *key'>
> -       <var: #body declareC: 'unsigned char *body'>
> -       <var: #matchTable declareC: 'unsigned char *matchTable'>
>
>         key size = 0 ifTrue: [^ 0].
>         (start max: 1) to: body size - key size + 1 do:
>                 [:startIndex |
>                 index := 1.
> +               [(matchTable at: (body basicAt: startIndex+index-1) + 1)
> +                       = (matchTable at: (key basicAt: index) + 1)]
> +                       whileTrue:
> -                       [(matchTable at: (body basicAt: startIndex+index-1) + 1)
> -                               = (matchTable at: (key basicAt: index) + 1)]
> -                               whileTrue:
>                                 [index = key size ifTrue: [^ startIndex].
>                                 index := index+1]].
>         ^ 0
>   "
>   ' ' findSubstring: 'abc' in: 'abcdefabcd' startingAt: 1 matchTable: CaseSensitiveOrder 1
>   ' ' findSubstring: 'abc' in: 'abcdefabcd' startingAt: 2 matchTable: CaseSensitiveOrder 7
>   ' ' findSubstring: 'abc' in: 'abcdefabcd' startingAt: 8 matchTable: CaseSensitiveOrder 0
>   ' ' findSubstring: 'abc' in: 'abcdefABcd' startingAt: 2 matchTable: CaseSensitiveOrder 0
>   ' ' findSubstring: 'abc' in: 'abcdefABcd' startingAt: 2 matchTable: CaseInsensitiveOrder 7
>   "!
>
> Item was added:
> + ----- Method: Interval>>, (in category 'adding') -----
> + , otherCollection
> +       "Override to answer an Interval if otherCollection is an adjacent and congruent interval."
> +       ^(otherCollection isInterval
> +         and: [otherCollection increment = step
> +         and: [otherCollection first = (self last + step)]])
> +               ifTrue: [self class from: start to: otherCollection last by: step]
> +               ifFalse: [super, otherCollection]!
>
> Item was changed:
>   ----- Method: String>>hash (in category 'comparing') -----
>   hash
>         "#hash is implemented, because #= is implemented"
>         "ar 4/10/2005: I had to change this to use ByteString hash as initial
>         hash in order to avoid having to rehash everything and yet compute
>         the same hash for ByteString and WideString.
>         md 16/10/2006: use identityHash as initialHash, as behavior hash will
> +       use String hash (name) to have a better hash soon.
> +       eem 4/17/2017 it's not possible to use String hash (name) for the
> +       initial hash because that would be recursive."
> +       ^self class stringHash: self initialHash: ByteString identityHash!
> -     use String hash (name) to have a better hash soon"
> -       ^ self class stringHash: self initialHash: ByteString identityHash!
>
>

Loading...