Code-Only: Client-Side OO Javascript Vector Chance Tree for probability selection.

/*
    Copyright (c) 2004 DigiTec Web Consultants, LLC.  All rights reserved.

    The use of this software is for test and performance purposes only.
    You may not use this software in any commercial applications without
    the express permission of the copyright holder.  You may add to or
    modify the code contained here-in to cause it to run slower without
    contacting the copyright holder, however, any attempts to make this
    code run faster should be documented on:
   
    http://weblogs.asp.net/justin_rogers/articles/248367.aspx
   
    I reserve the right to change or modify the publicly available version
    of this code at any time.  I will not provide version protection, so
    if you have reliance on a particular build of this software, then make
    your own back-ups.
   
    You must laugh, at least a little, when reading this licensing agreement,
    unless of course you don't have a sense of humor.  In all seriousness,
    excluding the laughter, laughter in itself does not void this license
    agreement, nor compromise it's ability to legally bind you.
   
    You must not remove this notice, or any other, from this software.
*/
function Chance(growthWeight, currentWeight, item) {
    this.GrowthWeight = growthWeight;
    this.CurrentWeight = currentWeight;
    this.Item = item;
}

function VectorChanceTree() {
    this.chances = new Array();
   
    this.AddChance = addChance;
    this.Get = get;
    this.Take = take;
    this.FindNode = findNode;
    this.ModifyChances = modifyChances;
}

function addChance(chance, item) {
    var index = this.chances.length;
    this.chances.push(new Chance(chance, chance, item));

    while(index > 0) {
        index = (index - 1) >> 1;
        this.chances[index].GrowthWeight += chance;
    }
}

function get() {
    if ( this.chances.length == 0 ) { return null; }
   
    return this.chances[this.FindNode(Math.floor(Math.random()*this.chances[0].GrowthWeight))].Item;
}

function take() {
    if ( this.chances.length == 0 ) { return null; }
   
    var prob = Math.floor(Math.random()*this.chances[0].GrowthWeight);
    var index = this.FindNode(prob);
    var chance = this.chances[index];
    this.ModifyChances(index, -chance.CurrentWeight);
    return chance.Item;
}

function findNode(chance) {
    var index = 0; var prior = 0;

    while(true) {
        prior += this.chances[index].CurrentWeight;
        if ( chance < prior ) { return index; }

        index = (index << 1) + 1;
        if ( chance >= (prior + this.chances[index].GrowthWeight) ) {
            prior += this.chances[index].GrowthWeight; index++;
        }
    }
}

function modifyChances(index, modifyBy) {
    var priorGrowth = this.chances[index].GrowthWeight;

    if ( (this.chances[index].CurrentWeight + modifyBy) <= 0 ) {
        var last = this.chances.length - 1;
        var swapIndex = last;

        while(swapIndex > 0) {
            swapIndex = (swapIndex - 1) >> 1;
            this.chances[swapIndex].GrowthWeight -= this.chances[last].CurrentWeight;
        }
        priorGrowth = this.chances[index].GrowthWeight;

        this.chances[index] = this.chances[last];
        this.chances = this.chances.slice(0, last);
        if ( last != index ) {
            this.chances[index].GrowthWeight = this.chances[index].CurrentWeight;

            var son = (index << 1) + 1;
            if ( son < last ) { this.chances[index].GrowthWeight += this.chances[son++].GrowthWeight; }
            if ( son < last ) { this.chances[index].GrowthWeight += this.chances[son].GrowthWeight; }
        } else {
            return;
        }
    } else {
        this.chances[index].CurrentWeight += modifyBy;
        this.chances[index].GrowthWeight += modifyBy;
    }

    var feedWeight = this.chances[index].GrowthWeight - priorGrowth;
    if ( feedWeight != 0 ) {
        while(index > 0) {
            index = (index - 1) >> 1;
            this.chances[index].GrowthWeight += feedWeight;
        }
    }
}

Published Tuesday, October 26, 2004 10:34 PM by Justin Rogers
Filed under:

Comments

Monday, September 24, 2012 12:11 PM by icon library

# re: Code-Only: Client-Side OO Javascript Vector Chance Tree for probability selection.

 I am assured, what is it was already discussed.

<a href="www.hpixel.com/.../a>

Tuesday, October 09, 2012 2:13 PM by icons designs

# re: Code-Only: Client-Side OO Javascript Vector Chance Tree for probability selection.

<a href="www.777icons.com/.../economics.htm"> It is remarkable, very amusing message</a>

Wednesday, October 31, 2012 11:07 AM by icons design

# re: Code-Only: Client-Side OO Javascript Vector Chance Tree for probability selection.

 Quite right! I like this idea, I completely with you agree.

<a href="windows2012icons.com/.../cur-editor-7f">cur editor</a>

Sunday, November 04, 2012 12:10 PM by icons design

# re: Code-Only: Client-Side OO Javascript Vector Chance Tree for probability selection.

<a href=unist.de/viewtopic.php I am ready to help you, set questions.</a>

Monday, November 05, 2012 10:26 AM by icons downloads

# re: Code-Only: Client-Side OO Javascript Vector Chance Tree for probability selection.

[url=obt-forum.ru/member.php] You, maybe, were mistaken?[/url]

Sunday, December 09, 2012 2:11 AM by midesoft.com

# re: Code-Only: Client-Side OO Javascript Vector Chance Tree for probability selection.

By WebOsPublisher

Looking for Under Construction icons - then check here!No matter how much time you spend,your pages are never finished.

v\:* behavior:url(#default#VML);

o\:* behavior:url(#default#VML);

w\:* behavior:url(#default#VML);

.shape behavior:url(#default#VML);

ICONS -- Under Construction -- ICONS

 User

 User

 7

 21

 2008-01-28T18:24:00Z

 2008-02-27T14:10:00Z

 2

 127

 727

 Grizli777

 6

 1

 853

 11.5606

 Clean

 Clean

 false

 false

 false

 MicrosoftInternetExplorer4

 false

 EN-US

 X-NONE

 X-NONE

st1\:*behavior:url(#ieooui)

/* Style Definitions */

table.MsoNormalTable

mso-style-name:"Table Normal";

mso-tstyle-rowband-size:0;

mso-tstyle-colband-size:0;

mso-style-noshow:yes;

mso-style-parent:"";

mso-padding-alt:0in 5.4pt 0in 5.4pt;

mso-para-margin:0in;

mso-para-margin-bottom:.0001pt;

mso-pagination:widow-orphan;

font-size:10.0pt;

font-family:"Times New Roman";

mso-ansi-language:#0400;

mso-fareast-language:#0400;

mso-bidi-language:#0400;

This

page is

UNDER CONSTRUCTION

 Arrow Asphalt & Engineering.

 3051 NW 129th St

 Opa Locka, FL 33054

 Tel (305)

 688-8686

 Fax (305) 688-8484

Send

Us Your e-mail!

ARROWASPH@AOL.COM

This

page was created by CamaWeb.com

Send Us Your e-mail or Visit our Web Site info@Camaweb.com

!

Thursday, December 13, 2012 11:21 PM by web icons

# re: Code-Only: Client-Side OO Javascript Vector Chance Tree for probability selection.

P.S. Please review our <a href="http://timbillmarklove.us">design portfolio</a> for Doors2012.

Five Easily Avoidable Mobile Web Design Mistakes

When was the last time you viewed a webpaeg on your mobile phone or tablet computer? If you said "today", you wouldn't be alone. Increasing numbers of people are using mobile devices to surf the Internet, but is your website ready? While mobile, or adaptive, web design is big news; some companies are making the same mistakes with their designs:Ignoring Device WidthLike laptop and desktop monitors, the screen shape and size of mobile devices varies considerably. Depending on the size of the screen being used, many users will be unable to see your content displayed correctly, resulting in them leaving the website. It is important your designs are able to adapt to fit whatever size screen they are being displayed on.Long Load TimesFilling your website with images may look great on a computer screen, but have you considered them loading on a mobile? If your page takes too long to display fully on a mobile device, visitors will simply hit the "back" button, and move on to your competitors. You can maintain your brand identity and the "look" of your original website, without the long load times with a mobile specific site. A graphic design company will be able to design a minimalist design, specific for mobile devices.Endless Form FillingGenerating leads through a contact form on a mobile site is not as easy as it is when using a desktop. Filling in long forms on a small screen can be a very tedious process, and visitors may be unsure of just how safe their details are. Make sure your forms are simple and easy to navigate on both mobile and computer.Functionality FailsDon't forget that a mouse pointer, and a users' finger vary greatly in size. When designing for mobiles, consider placing icons further apart so users don't hit the wrong button by mistake. Icons should also be large enough to be clicked without the need for zooming in - or out.Not Going Mobile At AllBy implementing a mobile web design you can eradicate most of these issues. If your website hasn't been optimised for use on smart phones and tablets, or you don't have a separate mobile site, your business could be losing out.Internet browsers are increasingly impatient and want all the information they are searching for in an instant. That's why mobile browsing has become so popular. Make sure your company is ready, with mobile web design.

Leave a Comment

(required) 
(required) 
(optional)
(required)