Skip to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[2.3.56] Hash cluster

Featured Replies

OSBot version number:
 
2.3.56 although I doubt this is new.

Description of the bug/error:
 
Hashes for RS2Object (and probably others) are inefficient and cause clusters.

Instructions how to replicate the bug/error:
 * @author 		Bjorn Krols (Botre)
 * @version		0.0
 * @since		March 26, 2015
 */

@ScriptManifest(author = "Botre", info = "TestScript", logo = "", name = "TestScript", version = 0)
public class TestScript extends Script {

	/**
	 * The amount of times getAll() was called.
	 */
	private int calls;
	
	@Override
	public int onLoop() throws InterruptedException {
		// Increment calls.
		calls++;
		// Create list.
		List<RS2Object> list = getObjects().getAll();
		// Store size of list.
		int listSize = list.size();
		// Convert list to Set.
		Set<RS2Object> set = new HashSet<RS2Object>(list);
		// Store size of set.
		int setSize = set.size();	
		// Log data here.
	}

}
[iNFO][bot #1][03/26 09:05:37 PM]: Calls: 1 | List size: 9089 | Set size: 8123 | 
[iNFO][bot #1][03/26 09:05:38 PM]: Calls: 2 | List size: 9089 | Set size: 8123 | 
[iNFO][bot #1][03/26 09:05:39 PM]: Calls: 3 | List size: 9089 | Set size: 8123 | 
[iNFO][bot #1][03/26 09:05:40 PM]: Calls: 4 | List size: 9089 | Set size: 8123 | 
[iNFO][bot #1][03/26 09:05:41 PM]: Calls: 5 | List size: 9089 | Set size: 8123 | 
[iNFO][bot #1][03/26 09:05:42 PM]: Calls: 6 | List size: 9089 | Set size: 8123 | 

Edited by Botre

  • Developer

The hashCode methods of those specific classes are not overridden and therefore not guaranteed to be unique and collisions are very likely using Java's standard hashing techniques. What would you need this for? I'm sure we can implement methods that return a guaranteed unique hash for each java object, just wondering what purpose it would serve. The Wrapper.equals() method does not rely on the hashCode method, but compares the accessor instances of the OSRS client.

 

P.S. I think the word you were looking for was "hash collisions" not "clusters".

  • Author

The hashCode methods of those specific classes are not overridden and therefore not guaranteed to be unique and collisions are very likely using Java's standard hashing techniques. What would you need this for? I'm sure we can implement methods that return a guaranteed unique hash for each java object, just wondering what purpose it would serve. The Wrapper.equals() method does not rely on the hashCode method, but compares the accessor instances of the OSRS client.

 

 

 

To optimize HashMap performance mainly

It's no biggie though and I doubt it affects many scripters :p

 

 P.S. I think the word you were looking for was "hash collisions" not "clusters".

 

No idea how I come up with cluster lel.

  • Developer

Another question, why would you fill a hash map with objects? Especially so many.

 

Regardless of that, providing a collision resistant Object#hashCode() method shouldn't be hard.

  • Author

Another question, why would you fill a hash map with objects? Especially so many.

 

Regardless of that, providing a collision resistant Object#hashCode() method shouldn't be hard.

 

I filled the map just to to compare it with the list / test the hash methods while experimenting.

 

The initial thought was to, rather than testing an objects for say reach-ability ever x milliseconds or seconds, to calculate it once and cache the result.

 

I ended up doing just that, but with the object's position as key rather than the object itself.

Position p = o.getPosition();

if (!validityMap.containsKey(p)) validityMap.put(p,script.getMap().canReach(o));

return validityMap.get(p);

I'm not sure how efficient the Position hash is, but it seems... better tongue.png

 

Anyhow I'm getting of track here tongue.png

Edited by Botre

  • Developer

I filled the map just to to compare it with the list / test the hash methods while experimenting.

 

The initial thought was to, rather than testing an objects for say reach-ability ever x milliseconds or seconds, to calculate it once and cache the result.

 

I ended up doing just that, but with the object's position as key rather than the object itself.

Position p = o.getPosition();

if (!validityMap.containsKey(p)) validityMap.put(p,script.getMap().canReach(o));

return validityMap.get(p);

I'm not sure how efficient the Position hash is, but it seems... better tongue.png

 

Anyhow I'm getting of track here tongue.png

The collision resistance of the Position class is 100% as it contains a custom hashCode() method, unlike many other classes which use the default java Object#hashCode(). But I'll implement custom hash methods for the other classes. Any classes you are particularly interested in?

  • Author

The collision resistance of the Position class is 100% as it contains a custom hashCode() method, unlike many other classes which use the default java Object#hashCode(). But I'll implement custom hash methods for the other classes. Any classes you are particularly interested in?

 

Yeah that's what I thought, neaterino.

 

Anything that implements Entity / RS2Object could probably deffo benefit from this :D

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.