tag:blogger.com,1999:blog-3840687515615686738.post4878226649778808971..comments2022-03-22T07:59:46.099+01:00Comments on Nikoloogle Lindbloogle: Counting Strings and Things in Scala (2.8)Nikolaj Lindberghttp://www.blogger.com/profile/12153448128671603936noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-3840687515615686738.post-48645845142007274562016-11-07T05:41:36.716+01:002016-11-07T05:41:36.716+01:00Very informative article.Thank you author for post...Very informative article.Thank you author for posting this kind of article .<br /><br /><a href="http://www.wikitechy.com/view-article/c-program-to-find-frequency-of-characters-in-a-string-with-example-and-explanation" rel="nofollow"><br />http://www.wikitechy.com/view-article/c-program-to-find-frequency-of-characters-in-a-string-with-example-and-explanation</a><br /><br /><br />Both are really good,<br />Cheers,<br />Venkat<br /><br />Anonymoushttps://www.blogger.com/profile/14254305782663491999noreply@blogger.comtag:blogger.com,1999:blog-3840687515615686738.post-76392250609297633832010-02-03T19:30:11.390+01:002010-02-03T19:30:11.390+01:00Sure. Its worth pointing out that the 2.8 version...Sure. Its worth pointing out that the 2.8 version keeps a large temporary map whereas the foldLeft version is about as fast and compact as you can get (it really doesn't need any temp space if you use the mutable map version).<br /><br />What I'd like to be able to do is the probably more common case of:<br /><br />Given a string that is an entire document, perform the same counting routine. You can just put :<br /><br />myBigString.split(" ").[any one of the processes used to group the list entries]<br /><br />But this means that split has to create the large temp list of words. Is there a one-liner (or two-liner) that would allow you to do the split and the count word-by-word, instead of doing all of the split, followed by all of the counting? That would be the most performant way...<br /><br />- DavidAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-3840687515615686738.post-42416751248523471742010-02-03T08:01:10.830+01:002010-02-03T08:01:10.830+01:00David,
I also tried to put together a non-2.8 fre...David,<br /><br />I also tried to put together a non-2.8 frequency counting one-liner, but I failed miserably... Thanks for your comment.Nikolaj Lindberghttps://www.blogger.com/profile/12153448128671603936noreply@blogger.comtag:blogger.com,1999:blog-3840687515615686738.post-49233522448452093082010-02-03T05:34:49.360+01:002010-02-03T05:34:49.360+01:00I hadn't seen those 2.8 functions. Very neat....I hadn't seen those 2.8 functions. Very neat. I tried it out to see what I could do with foldLeft (which is the first thing that pops into my head when I hear about a counting problem). Here is is, also in one (kinda long) line. Not as short as the 2.8 version...<br /><br />foldLeft(Map[String, Int]())((countmap, word) => countmap + (word -> (countmap.getOrElse(word, 0)+1)))<br /><br />(The mutable map case just means making the first parameter to foldLeft a mutable map and using += instead of +.)<br /><br />- DavidAnonymousnoreply@blogger.com