Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by gosub · May 14, 2011 at 06:35 AM · javascriptdictionarytextassethashtable

Optimising dictionary load (in Javascript)

I have a TextAsset, dictionary, which is a file containing a word per line, representing a scrabble-style word set. Currently I am iterating over it, like so:

var words = dictionary.text.Split("\n"[0]);
validWords = new Hashtable();
for (word in words) {
    validWords[word] = true;
}

But the file is around 3MB and therefore takes several minutes to load. Ideally I would like to be able to store the dictionary contents in a lightweight binary format that could be loaded "in place". Is this possible at all?

Does anyone have any other suggestions?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Meltdown · May 14, 2011 at 11:51 AM

I'm not sure if this will be relevant to your project but have you tried splitting the word file into a seperate file for each letter of the alphabet. i.e A.txt, B.txt etc.

Then if you are randomly getting a word, first pick a random letter from the alphabet. Then open that specific word file.

Alternatively if that doesn't work for you, have you looked into using a database engine of some sort?

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image gosub · May 14, 2011 at 03:22 PM 0
Share

That's an interesting idea, to sort of pre-hash the hash, but I'd really like to have the whole thing cached in memory at startup time, so that I can quickly query it during gameplay.

avatar image lbalasubbaiahapps · Jan 19, 2012 at 04:36 AM 0
Share

hi @gosub, i am also trying to implement dictionary.did you get solution from dictionary? if You know please share your idea.

avatar image lbalasubbaiahapps · Jan 20, 2012 at 10:07 AM 0
Share

i find the solution.i am happy now.

avatar image
0

Answer by Eric5h5 · May 14, 2011 at 02:01 PM

Just to focus on one aspect, using Dictionary would be rather faster (and more typesafe) than Hashtable:

var words = dictionary.text.Split("\n"[0]);
validWords = new Dictionary.<String, boolean>();
for (word in words) {
    validWords[word] = true;
}
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image gosub · May 14, 2011 at 03:23 PM 0
Share

I neglected to mention that I am coding in Javascript and afaik there is no support for the Dictionary type in JS.

avatar image Eric5h5 · May 14, 2011 at 03:39 PM 0
Share

@gosub: I know you're using JS; it was clear from the code you posted. I wouldn't have written my answer if there wasn't support for Dictionary in JS. (Assu$$anonymous$$g you're using at least Unity 3.0.) Use "import System.Collections.Generic" when using generics (List, Dictionary, etc.).

avatar image gosub · May 14, 2011 at 06:46 PM 0
Share

Thanks for the clarification @Eric5h5. I'm new to unity and don't know .NET or C# at all, so there are a lot of unknown unknowns for me atm. Please forgive my ignorance.

avatar image Eric5h5 · May 14, 2011 at 06:57 PM 0
Share

@gosub: see the docs here: http://msdn.microsoft.com/en-us/library/ms229335(v=VS.90).aspx None of the $$anonymous$$icrosoft.* stuff would apply, of course, as well as some things like System.Drawing and System.Web, but most of the more generic stuff works, like text, regular expressions, I/O, xml, etc.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Best Way to Represent an Inventory? 0 Answers

Is there an unsorted hashtable-like container? 2 Answers

Var names in Unity javascript 2 Answers

Hashtables and implicit downcasting of Object to int 0 Answers

TextAsset inside the Array - UnityScript/JavaScript 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges